Added motion log entry for creating polls.

Use timezone support for motion log time.
This commit is contained in:
Emanuel Schütze 2017-02-20 20:13:58 +01:00
parent cac15db50a
commit 4ebc238ea2
2 changed files with 22 additions and 2 deletions

View File

@ -3,7 +3,7 @@ from django.contrib.contenttypes.fields import GenericRelation
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
from django.db import models from django.db import models
from django.db.models import Max from django.db.models import Max
from django.utils import formats from django.utils import formats, timezone
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy, ugettext_noop from django.utils.translation import ugettext_lazy, ugettext_noop
from jsonfield import JSONField from jsonfield import JSONField
@ -866,7 +866,8 @@ class MotionLog(RESTModelMixin, models.Model):
""" """
Return a string, representing the log message. Return a string, representing the log message.
""" """
time = formats.date_format(self.time, 'DATETIME_FORMAT') localtime = timezone.localtime(self.time)
time = formats.date_format(localtime, 'DATETIME_FORMAT')
time_and_messages = '%s ' % time + ''.join(map(_, self.message_list)) time_and_messages = '%s ' % time + ''.join(map(_, self.message_list))
if self.person is not None: if self.person is not None:
return _('%(time_and_messages)s by %(person)s') % {'time_and_messages': time_and_messages, return _('%(time_and_messages)s by %(person)s') % {'time_and_messages': time_and_messages,

View File

@ -338,6 +338,7 @@ class MotionViewSet(ModelViewSet):
motion.create_poll() motion.create_poll()
except WorkflowError as e: except WorkflowError as e:
raise ValidationError({'detail': e}) raise ValidationError({'detail': e})
motion.write_log([ugettext_noop('Vote created')], request.user)
return Response({'detail': _('Vote created successfully.')}) return Response({'detail': _('Vote created successfully.')})
@ -357,6 +358,24 @@ class MotionPollViewSet(UpdateModelMixin, DestroyModelMixin, GenericViewSet):
return (has_perm(self.request.user, 'motions.can_see') and return (has_perm(self.request.user, 'motions.can_see') and
has_perm(self.request.user, 'motions.can_manage')) has_perm(self.request.user, 'motions.can_manage'))
def update(self, *args, **kwargs):
"""
Customized view endpoint to update a motion poll.
"""
result = super().update(*args, **kwargs)
poll = self.get_object()
poll.motion.write_log([ugettext_noop('Vote updated')], self.request.user)
return result
def destroy(self, *args, **kwargs):
"""
Customized view endpoint to delete a motion poll.
"""
result = super().destroy(*args, **kwargs)
poll = self.get_object()
poll.motion.write_log([ugettext_noop('Vote deleted')], self.request.user)
return result
class MotionChangeRecommendationViewSet(ModelViewSet): class MotionChangeRecommendationViewSet(ModelViewSet):
""" """