Changeset 0bd161f


Ignore:
Timestamp:
Aug 14, 2011, 8:28:33 PM (14 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage, test-hooks
Children:
33b19c3
Parents:
aa6a940
git-author:
Alex Dehnert <adehnert@…> (08/14/11 19:42:20)
git-committer:
Alex Dehnert <adehnert@…> (08/14/11 20:28:33)
Message:

Add notes

There's currently no particularly good UI for adding new notes.
But it is possible, and viewing works fine

Location:
asadb
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • asadb/groups/admin.py

    rb713ac7 r0bd161f  
    2525    date_hierarchy = 'update_date'
    2626    search_fields = [ 'id', 'name', 'abbreviation', 'officer_email', 'athena_locker', ]
     27
     28class Admin_GroupNote(VersionAdmin):
     29    list_display = (
     30        'pk',
     31        'author',
     32        'timestamp',
     33        'acl_read_group',
     34        'acl_read_offices',
     35        'group',
     36    )
     37    list_display_links = ('pk', 'timestamp', )
     38    list_filter = [
     39        'acl_read_group',
     40        'acl_read_offices',
     41    ]
     42    date_hierarchy = 'timestamp'
     43    search_fields = [
     44        'author',
     45        'group__name',
     46        'group__abbreviation',
     47        'group__officer_email',
     48        'group__athena_locker',
     49    ]
    2750
    2851class OfficerRoleAdmin(VersionAdmin):
     
    129152
    130153admin.site.register(groups.models.Group, GroupAdmin)
     154admin.site.register(groups.models.GroupNote, Admin_GroupNote)
    131155admin.site.register(groups.models.OfficerRole, OfficerRoleAdmin)
    132156admin.site.register(groups.models.OfficeHolder, OfficeHolderAdmin)
  • asadb/groups/models.py

    raa6a940 r0bd161f  
    5050        super(Group, self).save()
    5151
     52    def viewable_notes(self, user):
     53        return GroupNote.viewable_notes(self, user)
     54
    5255    def officers(self, role=None, person=None, as_of="now",):
    5356        """Get the set of people holding some office.
     
    8386            ('admin_group', 'Administer basic group information'),
    8487            ('view_signatories', 'View signatory information for all groups'),
     88        )
     89
     90
     91class GroupNote(models.Model):
     92    author = models.CharField(max_length=30, ) # match Django username field
     93    timestamp = models.DateTimeField(default=datetime.datetime.now, editable=False, )
     94    body = models.TextField()
     95    acl_read_group = models.BooleanField(default=True, help_text='Can the group read this note')
     96    acl_read_offices = models.BooleanField(default=True, help_text='Can "offices" that interact with groups (SAO, CAC, and funding boards) read this note')
     97    group = models.ForeignKey(Group)
     98
     99    def __str__(self, ):
     100        return "Note by %s on %s" % (self.author, self.timestamp, )
     101
     102    @classmethod
     103    def viewable_notes(cls, group, user):
     104        notes = cls.objects.filter(group=group)
     105        if not user.has_perm('groups.view_note_all'):
     106            q = models.Q(pk=0)
     107            if user.has_perm('groups.view_note_group', group):
     108                q |= models.Q(acl_read_group=True)
     109            if user.has_perm('groups.view_note_office'):
     110                q |= models.Q(acl_read_offices=True)
     111            notes = notes.filter(q)
     112        return notes
     113
     114    class Meta:
     115        permissions = (
     116            ('view_note_group',     'View notes intended for the group to see', ),
     117            ('view_note_office',    'View notes intended for "offices" to see', ),
     118            ('view_note_all',       'View all notes', ),
    85119        )
    86120
  • asadb/groups/views.py

    raa6a940 r0bd161f  
    184184        context['viewpriv'] = self.request.user.has_perm('groups.view_group_private_info', group)
    185185        context['adminpriv'] = self.request.user.has_perm('groups.admin_group', group)
     186        context['notes'] = group.viewable_notes(self.request.user)
     187
    186188        return context
    187189
  • asadb/template/groups/group_detail.html

    raa6a940 r0bd161f  
    7171</table>
    7272
     73<h2>Notes</h2>
     74
     75{% if notes %}
     76<table class='pretty-table'>
     77<thead>
     78{% include "groups/note/detail.head.html" %}
     79</thead>
     80<tbody>
     81{% for note in notes %}
     82{% include "groups/note/detail.row.html" %}
     83{% endfor %}
     84</tbody>
     85</table>
     86{% else %}
     87<p>No notes are visible to you at this time.</p>
     88{% endif %}
     89
     90{% if perms.groups.add_groupnote %}
     91<p><a href='{% url admin:groups_groupnote_add %}'>Add note</a></p>
     92{% endif %}
     93
    7394{% endblock %}
    7495
Note: See TracChangeset for help on using the changeset viewer.