Added translatable log to the new motion system
This commit is contained in:
parent
15b13c2bcd
commit
65a18953bd
@ -251,8 +251,7 @@ class Motion(SlideMixin, models.Model):
|
|||||||
if self.state.support:
|
if self.state.support:
|
||||||
if not self.is_supporter(person):
|
if not self.is_supporter(person):
|
||||||
MotionSupporter(motion=self, person=person).save()
|
MotionSupporter(motion=self, person=person).save()
|
||||||
#self.writelog(_("Supporter: +%s") % (person))
|
self.write_log(ugettext_noop("Supporter: +%s") % person)
|
||||||
# TODO: Raise a precise exception for the view in else-clause
|
|
||||||
else:
|
else:
|
||||||
raise WorkflowError("You can not support a motion in state %s" % self.state.name)
|
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:
|
if self.state.support:
|
||||||
self.supporter.filter(person=person).delete()
|
self.supporter.filter(person=person).delete()
|
||||||
|
self.write_log(ugettext_noop("Supporter: -%s") % person)
|
||||||
else:
|
else:
|
||||||
raise WorkflowError("You can not unsupport a motion in state %s" % self.state.name)
|
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
|
Create a new poll for this motion
|
||||||
"""
|
"""
|
||||||
# TODO: auto increment the poll_number in the Database
|
|
||||||
if self.state.create_poll:
|
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_number = self.polls.aggregate(Max('poll_number'))['poll_number__max'] or 0
|
||||||
poll = MotionPoll.objects.create(motion=self, poll_number=poll_number + 1)
|
poll = MotionPoll.objects.create(motion=self, poll_number=poll_number + 1)
|
||||||
poll.set_options()
|
poll.set_options()
|
||||||
@ -293,7 +293,7 @@ class Motion(SlideMixin, models.Model):
|
|||||||
|
|
||||||
next_state has to be a valid state id or State object.
|
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)
|
next_state = get_state(next_state)
|
||||||
if next_state in self.state.next_states:
|
if next_state in self.state.next_states:
|
||||||
self.state_id = next_state.id
|
self.state_id = next_state.id
|
||||||
@ -359,6 +359,9 @@ class Motion(SlideMixin, models.Model):
|
|||||||
actions['reset_state'] = 'change_state'
|
actions['reset_state'] = 'change_state'
|
||||||
return actions
|
return actions
|
||||||
|
|
||||||
|
def write_log(self, message, person=None):
|
||||||
|
MotionLog.objects.create(motion=self, message=message, person=person)
|
||||||
|
|
||||||
|
|
||||||
class MotionVersion(models.Model):
|
class MotionVersion(models.Model):
|
||||||
title = models.CharField(max_length=255, verbose_name=ugettext_lazy("Title"))
|
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)
|
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):
|
class MotionVote(BaseVote):
|
||||||
option = models.ForeignKey('MotionOption')
|
option = models.ForeignKey('MotionOption')
|
||||||
|
|
||||||
|
@ -79,4 +79,13 @@
|
|||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endwith %}
|
{% endwith %}
|
||||||
|
|
||||||
|
|
||||||
|
<h4>log</h4>
|
||||||
|
<ul>
|
||||||
|
{% for message in motion.log_messages.all %}
|
||||||
|
<li>{{ message }}</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -15,7 +15,7 @@ from django.core.urlresolvers import reverse
|
|||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.db.models import Model
|
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.views.generic.detail import SingleObjectMixin
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
|
|
||||||
@ -119,6 +119,11 @@ class MotionCreateView(MotionMixin, CreateView):
|
|||||||
permission_required = 'motion.can_create_motion'
|
permission_required = 'motion.can_create_motion'
|
||||||
model = 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()
|
motion_create = MotionCreateView.as_view()
|
||||||
|
|
||||||
|
|
||||||
@ -131,6 +136,11 @@ class MotionUpdateView(MotionMixin, UpdateView):
|
|||||||
def has_permission(self, request, *args, **kwargs):
|
def has_permission(self, request, *args, **kwargs):
|
||||||
return self.get_object().get_allowed_actions(request.user)['edit']
|
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()
|
motion_edit = MotionUpdateView.as_view()
|
||||||
|
|
||||||
|
|
||||||
@ -268,9 +278,8 @@ class MotionSetStateView(SingleObjectMixin, RedirectView):
|
|||||||
self.object.reset_state()
|
self.object.reset_state()
|
||||||
else:
|
else:
|
||||||
self.object.state = kwargs['state']
|
self.object.state = kwargs['state']
|
||||||
except WorkflowError:
|
except WorkflowError, e:
|
||||||
messages.error(request, _('Can not set the state to: %s.')
|
messages.error(request, e)
|
||||||
% html_strong(kwargs['state']))
|
|
||||||
else:
|
else:
|
||||||
self.object.save()
|
self.object.save()
|
||||||
messages.success(request, _('Motion status was set to: %s.'
|
messages.success(request, _('Motion status was set to: %s.'
|
||||||
|
Loading…
Reference in New Issue
Block a user