Changeset aa6a940


Ignore:
Timestamp:
Aug 13, 2011, 9:53:10 PM (14 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage, test-hooks
Children:
0bd161f
Parents:
9bf5237
git-author:
Alex Dehnert <adehnert@…> (08/13/11 21:53:10)
git-committer:
Alex Dehnert <adehnert@…> (08/13/11 21:53:10)
Message:

Fix updater information

Systems updating entries should call set_updater with the updater (as a string
or request.user object) in order to ensure that the updater is correct.
Otherwise, it will be unset on instance.save(). Regardless, the update_time
will be updated.

This mechanism is independent of django-reversion's history functionality,
which also stores the updater.

Note, in particular, that the admin does not currently use this interface
to store the updater, but does store it in django-reversion's system (along
with the rest of the history). Porting the "view group" page over may be
desirable.

Location:
asadb
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • asadb/groups/models.py

    r9bf5237 raa6a940  
    33
    44import datetime
     5
     6import settings
    57
    68# Create your models here.
     
    2729    athena_locker = models.CharField(max_length=20, blank=True)
    2830    recognition_date = models.DateField()
    29     update_date = models.DateTimeField()
    30     updater = models.CharField(max_length=30) # match Django username field
     31    update_date = models.DateTimeField(editable=False, )
     32    updater = models.CharField(max_length=30, editable=False, ) # match Django username field
     33    _updater_set = False
     34
     35    def update_string(self, ):
     36        updater = self.updater or "unknown"
     37        return "%s by %s" % (self.update_date.strftime(settings.DATETIME_FORMAT_PYTHON), updater, )
     38
     39    def set_updater(self, who):
     40        if hasattr(who, 'username'):
     41            self.updater = who.username
     42        else:
     43            self.updater = who
     44        self._updater_set = True
     45
     46    def save(self, ):
     47        if not self._updater_set:
     48            self.updater = None
     49        self.update_date = datetime.datetime.now()
     50        super(Group, self).save()
    3151
    3252    def officers(self, role=None, person=None, as_of="now",):
  • asadb/groups/views.py

    r70f2dd3 raa6a940  
    7878    ]
    7979    nobody_fields = [
    80         'recognition_date', 'updater', 'update_date',
     80        'recognition_date',
    8181    ]
    8282
     
    105105            ('more-info', {
    106106                'legend': 'Additional Information',
    107                 'fields': ['constitution_url', 'advisor_name', 'athena_locker', 'updater', 'update_date', ],
     107                'fields': ['constitution_url', 'advisor_name', 'athena_locker', ],
    108108            }),
    109109        ]
     
    131131
    132132        if form.is_valid(): # All validation rules pass
    133             request_obj = form.save()
     133            request_obj = form.save(commit=False)
     134            request_obj.set_updater(request.user)
     135            request_obj.save()
     136            form.save_m2m()
    134137
    135138            # Send email
  • asadb/settings.py

    r16b7515 raa6a940  
    3939# to load the internationalization machinery.
    4040USE_I18N = True
     41
     42DATETIME_FORMAT_PYTHON = "%c"
    4143
    4244from local_settings import *
  • asadb/template/groups/group_detail.html

    rb6d89f2 raa6a940  
    4747</tr>
    4848<tr><th>Athena locker</th><td>{{group.athena_locker}}</td></tr>
    49 <tr><th>Last updated</th><td>{{group.update_date}} by {{group.updater}}</td></tr>
     49<tr><th>Last updated</th><td>{{group.update_string}}</td></tr>
    5050
    5151{% if viewpriv %}
Note: See TracChangeset for help on using the changeset viewer.