Added translatable log to the new motion system

This commit is contained in:
Oskar Hahn 2013-02-02 21:40:23 +01:00
parent 15b13c2bcd
commit 65a18953bd
3 changed files with 46 additions and 8 deletions

View File

@ -251,8 +251,7 @@ class Motion(SlideMixin, models.Model):
if self.state.support:
if not self.is_supporter(person):
MotionSupporter(motion=self, person=person).save()
#self.writelog(_("Supporter: +%s") % (person))
# TODO: Raise a precise exception for the view in else-clause
self.write_log(ugettext_noop("Supporter: +%s") % person)
else:
raise WorkflowError("You can not support a motion in state %s" % self.state.name)
@ -262,6 +261,7 @@ class Motion(SlideMixin, models.Model):
"""
if self.state.support:
self.supporter.filter(person=person).delete()
self.write_log(ugettext_noop("Supporter: -%s") % person)
else:
raise WorkflowError("You can not unsupport a motion in state %s" % self.state.name)
@ -269,8 +269,8 @@ class Motion(SlideMixin, models.Model):
"""
Create a new poll for this motion
"""
# TODO: auto increment the poll_number in the Database
if self.state.create_poll:
# TODO: auto increment the poll_number in the Database
poll_number = self.polls.aggregate(Max('poll_number'))['poll_number__max'] or 0
poll = MotionPoll.objects.create(motion=self, poll_number=poll_number + 1)
poll.set_options()
@ -293,7 +293,7 @@ class Motion(SlideMixin, models.Model):
next_state has to be a valid state id or State object.
"""
if type(next_state) is not State:
if not isinstance(next_state, State):
next_state = get_state(next_state)
if next_state in self.state.next_states:
self.state_id = next_state.id
@ -359,6 +359,9 @@ class Motion(SlideMixin, models.Model):
actions['reset_state'] = 'change_state'
return actions
def write_log(self, message, person=None):
MotionLog.objects.create(motion=self, message=message, person=person)
class MotionVersion(models.Model):
title = models.CharField(max_length=255, verbose_name=ugettext_lazy("Title"))
@ -401,6 +404,23 @@ class Comment(models.Model):
creation_time = models.DateTimeField(auto_now=True)
class MotionLog(models.Model):
motion = models.ForeignKey(Motion, related_name='log_messages')
message = models.CharField(max_length=255)
person = PersonField(null=True)
time = models.DateTimeField(auto_now=True)
class Meta:
ordering = ['-time']
def __unicode__(self):
# TODO: write time in the local time format.
if self.person is None:
return "%s %s" % (self.time, _(self.message))
else:
return "%s %s by %s" % (self.time, _(self.message), self.person)
class MotionVote(BaseVote):
option = models.ForeignKey('MotionOption')

View File

@ -79,4 +79,13 @@
</a>
{% endif %}
{% endwith %}
<h4>log</h4>
<ul>
{% for message in motion.log_messages.all %}
<li>{{ message }}</li>
{% endfor %}
</ul>
{% endblock %}

View File

@ -15,7 +15,7 @@ from django.core.urlresolvers import reverse
from django.contrib import messages
from django.db import transaction
from django.db.models import Model
from django.utils.translation import ugettext as _, ugettext_lazy
from django.utils.translation import ugettext as _, ugettext_lazy, ugettext_noop
from django.views.generic.detail import SingleObjectMixin
from django.http import Http404
@ -119,6 +119,11 @@ class MotionCreateView(MotionMixin, CreateView):
permission_required = 'motion.can_create_motion'
model = Motion
def form_valid(self, form):
value = super(MotionCreateView, self).form_valid(form)
self.object.write_log(ugettext_noop('Motion created'), self.request.user)
return value
motion_create = MotionCreateView.as_view()
@ -131,6 +136,11 @@ class MotionUpdateView(MotionMixin, UpdateView):
def has_permission(self, request, *args, **kwargs):
return self.get_object().get_allowed_actions(request.user)['edit']
def form_valid(self, form):
value = super(MotionUpdateView, self).form_valid(form)
self.object.write_log(ugettext_noop('Motion updated'), self.request.user)
return value
motion_edit = MotionUpdateView.as_view()
@ -268,9 +278,8 @@ class MotionSetStateView(SingleObjectMixin, RedirectView):
self.object.reset_state()
else:
self.object.state = kwargs['state']
except WorkflowError:
messages.error(request, _('Can not set the state to: %s.')
% html_strong(kwargs['state']))
except WorkflowError, e:
messages.error(request, e)
else:
self.object.save()
messages.success(request, _('Motion status was set to: %s.'