Re: Button action to delete files from server

2012-09-18 Thread xactive
Sebastian

I'm not sure if I've done something wrong, but this does not seem to work.

What happens now is that the content of the page redirects immediately when 
it renders, before anything is clicked.

Hope you have a solution?

Thanks

Adam

On Monday, September 17, 2012 1:57:48 PM UTC+1, Sebastian Henschel wrote:
>
> hey xactive... 
>
> a simple solution, without bells & whistles could be this (assuming 
> File.file_obj is defined as a Django FileField): 
>
> On 09/17/2012 01:15 PM, xactive wrote: 
> > I have little experience with Django/Python but have a problem that I 
> > need to solve. 
> > 
> > Currently I have a button action that allows users of a website to 
> > download files from a displayed list. I want to add a button to allow 
> > users to delete the files if required. 
> > 
> > The current download button is set up as follows on the page itself: 
> > Download 
>
> add to your template: 
>
> Delete 
>
> > And as far as I can see there is a file called views.py which contains 
> > code as follows: 
> > @login_required(login_url='/portal/login/', redirect_field_name=None) 
> > def file_view(request, id, template_name='portal/file_view.html'): 
> > try: 
> > f = File.objects.get(pk=id) 
> > except File.DoesNotExist: 
> > raise Http404 
> > if request.user not in f.recipients.all() and request.user != 
> f.owner: 
> > return HttpResponseForbidden() 
>
> if request.GET.has_key('action'): 
>action = request.GET['action'] 
>if action == 'download': 
>  filename = f.file_obj.name.rsplit('/', 1)[1] 
>  response = HttpResponse() 
>  response['Content-Disposition'] = 'attachment; filename=%s' % 
> filename 
>  response['Content-Length']  = '' 
>  response['X-Accel-Redirect']= '/%s' % f.file_obj.name 
>  return response 
>elif action == 'delete': 
>  f.file_obj.delete() 
>  # read https://docs.djangoproject.com/en/dev/ref/models/fields/ 
>
>  return render_to_response('portal/file_deleted.html', {}, 
>context_instance=RequestContext(request)) 
>
>return render_to_response(template_name, { 
>  'file': f 
>}, context_instance=RequestContext(request)) 
>
>
>
> you still have to create the template file 'portal/file_deleted.html'. 
> or you do a redirect to another URL instead... 
>
> > 
> > Can somebody please help me to create an action to delete files? 
> > 
>
>
> hth, 
>   Sebastian 
>
> -- 
> Sebastian Henschel, Python Developer Web 
> txtr GmbH | Rosenthaler Str. 13 | 10119 Berlin | Germany 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/rmt9k1bLvHAJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Button action to delete files from server

2012-09-17 Thread xactive
Many thanks, I'll give that a try.

On Monday, September 17, 2012 1:57:48 PM UTC+1, Sebastian Henschel wrote:
>
> hey xactive... 
>
> a simple solution, without bells & whistles could be this (assuming 
> File.file_obj is defined as a Django FileField): 
>
> On 09/17/2012 01:15 PM, xactive wrote: 
> > I have little experience with Django/Python but have a problem that I 
> > need to solve. 
> > 
> > Currently I have a button action that allows users of a website to 
> > download files from a displayed list. I want to add a button to allow 
> > users to delete the files if required. 
> > 
> > The current download button is set up as follows on the page itself: 
> > Download 
>
> add to your template: 
>
> Delete 
>
> > And as far as I can see there is a file called views.py which contains 
> > code as follows: 
> > @login_required(login_url='/portal/login/', redirect_field_name=None) 
> > def file_view(request, id, template_name='portal/file_view.html'): 
> > try: 
> > f = File.objects.get(pk=id) 
> > except File.DoesNotExist: 
> > raise Http404 
> > if request.user not in f.recipients.all() and request.user != 
> f.owner: 
> > return HttpResponseForbidden() 
>
> if request.GET.has_key('action'): 
>action = request.GET['action'] 
>if action == 'download': 
>  filename = f.file_obj.name.rsplit('/', 1)[1] 
>  response = HttpResponse() 
>  response['Content-Disposition'] = 'attachment; filename=%s' % 
> filename 
>  response['Content-Length']  = '' 
>  response['X-Accel-Redirect']= '/%s' % f.file_obj.name 
>  return response 
>elif action == 'delete': 
>  f.file_obj.delete() 
>  # read https://docs.djangoproject.com/en/dev/ref/models/fields/ 
>
>  return render_to_response('portal/file_deleted.html', {}, 
>context_instance=RequestContext(request)) 
>
>return render_to_response(template_name, { 
>  'file': f 
>}, context_instance=RequestContext(request)) 
>
>
>
> you still have to create the template file 'portal/file_deleted.html'. 
> or you do a redirect to another URL instead... 
>
> > 
> > Can somebody please help me to create an action to delete files? 
> > 
>
>
> hth, 
>   Sebastian 
>
> -- 
> Sebastian Henschel, Python Developer Web 
> txtr GmbH | Rosenthaler Str. 13 | 10119 Berlin | Germany 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/nVZ_4aJQVKYJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Button action to delete files from server

2012-09-17 Thread xactive
I have little experience with Django/Python but have a problem that I need 
to solve.

Currently I have a button action that allows users of a website to download 
files from a displayed list. I want to add a button to allow users to 
delete the files if required.

The current download button is set up as follows on the page itself:
Download

And as far as I can see there is a file called views.py which contains code 
as follows:
@login_required(login_url='/portal/login/', redirect_field_name=None)
def file_view(request, id, template_name='portal/file_view.html'):
try:
f = File.objects.get(pk=id)
except File.DoesNotExist:
raise Http404

if request.user not in f.recipients.all() and request.user != f.owner:
return HttpResponseForbidden()

if request.GET.has_key('action') and request.GET['action'] == 
'download':

filename = f.file_obj.name.rsplit('/', 1)[1]

response = HttpResponse()
response['Content-Disposition'] = 'attachment; filename=%s' % 
filename
response['Content-Length']  = ''
response['X-Accel-Redirect']= '/%s' % f.file_obj.name

return response

return render_to_response(template_name, {
'file': f
}, context_instance=RequestContext(request))


Can somebody please help me to create an action to delete files?

Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/kckZZ137xigJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.