~panosl/+junk/django-attachments

« back to all changes in this revision

Viewing changes to attachments/templatetags/attachments_tags.py

  • Committer: Martin Mahner
  • Date: 2009-07-22 13:31:13 UTC
  • Revision ID: git-v1:89b298e184a844ca4811373b39f4095db360ee01
Backwards incompatible: This introdues granular permissions for users who should been able to add or delete permissions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
@register.inclusion_tag('attachments/add_form.html', takes_context=True)
10
10
def attachment_form(context, obj):
11
11
    """
12
 
    Renders a "upload attachment" form
 
12
    Renders a "upload attachment" form.
 
13
    
 
14
    The user must own ``attachments.add_attachment permission`` to add
 
15
    attachments.
13
16
    """
14
 
    if context['user'].is_authenticated():
 
17
    if context['user'].has_perm('attachments.add_attachment'):
15
18
        return {
16
19
            'form': AttachmentForm(),
17
20
            'form_url': add_url_for_obj(obj),
26
29
def attachment_delete_link(context, attachment):
27
30
    """
28
31
    Renders a html link to the delete view of the given attachment. Returns
29
 
    no content if the request-user has no permission to delete foreign
 
32
    no content if the request-user has no permission to delete attachments.
 
33
    
 
34
    The user must own either the ``attachments.delete_attachment`` permission
 
35
    and is the creator of the attachment, that he can delete it or he has
 
36
    ``attachments.delete_foreign_attachments`` which allows him to delete all
30
37
    attachments.
31
38
    """
32
39
    if context['user'].has_perm('delete_foreign_attachments') \
33
 
       or context['user'] == attachment.creator:
 
40
       or (context['user'] == attachment.creator and \
 
41
           context['user'].has_perm('attachments.delete_attachment')):
34
42
        return {
35
43
            'next': context['request'].build_absolute_uri(),
36
44
            'delete_url': reverse('delete_attachment', kwargs={'attachment_pk': attachment.pk})