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:
<a id="download" href="/portal/files/{{ file.id }}/?action=download">Download</a>

add to your template:

<a id="delete" href="/portal/files/{{ file.id }}/?action=delete">Delete</a>

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 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.

Reply via email to