Merge pull request #660 from normanjaeckel/TranslatedStateChanged

Translate changed state in motion log (Fixed #656)
This commit is contained in:
Emanuel Schütze 2013-05-16 13:37:09 -07:00
commit 6dbd606232
3 changed files with 31 additions and 27 deletions

View File

@ -102,7 +102,7 @@ def import_motions(csv_file, default_submitter, override=False, importing_person
motion.clear_submitters()
motion.add_submitter(new_submitter)
motion.write_log(message=ugettext_noop('Motion imported'),
motion.write_log(message_list=[ugettext_noop('Motion imported')],
person=importing_person)
count_success += 1

View File

@ -23,6 +23,7 @@ from django.utils import formats
from django.utils.translation import pgettext
from django.utils.translation import ugettext as _, ugettext_lazy, ugettext_noop
from openslides.utils.jsonfield import JSONField
from openslides.utils.person import PersonField
from openslides.config.api import config
from openslides.poll.models import (
@ -495,14 +496,14 @@ class Motion(SlideMixin, models.Model):
actions['reset_state'] = actions['change_state']
return actions
def write_log(self, message, person=None):
def write_log(self, message_list, person=None):
"""
Write a log message.
The message should be in English and translatable,
e. g. motion.write_log(message=ugettext_noop('Message Text'))
e. g. motion.write_log(message_list=[ugettext_noop('Message Text')])
"""
MotionLog.objects.create(motion=self, message=message, person=person)
MotionLog.objects.create(motion=self, message_list=message_list, person=person)
def set_active_version(self, version):
"""
@ -652,10 +653,9 @@ class MotionLog(models.Model):
motion = models.ForeignKey(Motion, related_name='log_messages')
"""The motion to witch the object belongs."""
message = models.CharField(max_length=255) # TODO: arguments in message, not translatable
"""The log message.
Should be in english.
message_list = JSONField()
"""
The log message. It should be a list of strings in english.
"""
person = PersonField(null=True)
@ -668,12 +668,16 @@ class MotionLog(models.Model):
ordering = ['-time']
def __unicode__(self):
"""Return a string, representing the log message."""
"""
Return a string, representing the log message.
"""
time = formats.date_format(self.time, 'DATETIME_FORMAT')
if self.person is None:
return "%s %s" % (time, _(self.message))
else:
return "%s %s by %s" % (time, _(self.message), self.person)
return_message = '%s ' % time
for message in self.message_list:
return_message += _(message)
if self.person is not None:
return_message += ' by %s' % self.person
return return_message
class MotionVote(BaseVote):

View File

@ -190,7 +190,7 @@ class MotionCreateView(MotionMixin, CreateView):
def form_valid(self, form):
"""Write a log message, if the form is valid."""
value = super(MotionCreateView, self).form_valid(form)
self.object.write_log(ugettext_noop('Motion created'), self.request.user)
self.object.write_log([ugettext_noop('Motion created')], self.request.user)
return value
def post_save(self, form):
@ -212,7 +212,7 @@ class MotionUpdateView(MotionMixin, UpdateView):
def form_valid(self, form):
"""Write a log message, if the form is valid."""
value = super(MotionUpdateView, self).form_valid(form)
self.object.write_log(ugettext_noop('Motion updated'), self.request.user)
self.object.write_log([ugettext_noop('Motion updated')], self.request.user)
return value
motion_edit = MotionUpdateView.as_view()
@ -266,7 +266,7 @@ class VersionPermitView(GetVersionMixin, SingleObjectMixin, QuestionMixin, Redir
self.object.set_active_version(self.object.version)
self.object.save(ignore_version_data=True)
self.object.write_log(
message=ugettext_noop('Version %d permitted') % self.object.version.version_number,
message_list=[ugettext_noop('Version %d permitted') % self.object.version.version_number],
person=self.request.user)
version_permit = VersionPermitView.as_view()
@ -304,7 +304,7 @@ class VersionRejectView(GetVersionMixin, SingleObjectMixin, QuestionMixin, Redir
self.object.reject_version(self.object.version)
self.object.save(ignore_version_data=True)
self.object.write_log(
message=ugettext_noop('Version %d rejected') % self.object.version.version_number,
message_list=[ugettext_noop('Version %d rejected') % self.object.version.version_number],
person=self.request.user)
version_reject = VersionRejectView.as_view()
@ -389,10 +389,10 @@ class SupportView(SingleObjectMixin, QuestionMixin, RedirectView):
user = self.request.user
if self.support:
self.object.support(person=user)
self.object.write_log(ugettext_noop("Supporter: +%s") % user, user)
self.object.write_log([ugettext_noop("Supporter: +%s") % user], user)
else:
self.object.unsupport(person=user)
self.object.write_log(ugettext_noop("Supporter: -%s") % user, user)
self.object.write_log([ugettext_noop("Supporter: -%s") % user], user)
def get_success_message(self):
"""Return the success message."""
@ -422,7 +422,7 @@ class PollCreateView(SingleObjectMixin, RedirectView):
def pre_redirect(self, request, *args, **kwargs):
"""Create the poll for the motion."""
self.poll = self.object.create_poll()
self.object.write_log(ugettext_noop("Poll created"), request.user)
self.object.write_log([ugettext_noop("Poll created")], request.user)
messages.success(request, _("New vote was successfully created."))
def get_redirect_url(self, **kwargs):
@ -487,7 +487,7 @@ class PollUpdateView(PollMixin, PollFormView):
Write a log message, if the form is valid.
"""
value = super(PollUpdateView, self).form_valid(form)
self.object.write_log(ugettext_noop('Poll updated'), self.request.user)
self.object.write_log([ugettext_noop('Poll updated')], self.request.user)
return value
poll_edit = PollUpdateView.as_view()
@ -505,7 +505,7 @@ class PollDeleteView(PollMixin, DeleteView):
Write a log message, if the form is valid.
"""
super(PollDeleteView, self).case_yes()
self.object.write_log(ugettext_noop('Poll deleted'), self.request.user)
self.object.write_log([ugettext_noop('Poll deleted')], self.request.user)
def get_redirect_url(self, **kwargs):
"""
@ -577,10 +577,10 @@ class MotionSetStateView(SingleObjectMixin, RedirectView):
messages.error(request, e)
else:
self.object.save(ignore_version_data=True)
# TODO: the state is not translated
self.object.write_log(ugettext_noop('State changed to %s') %
self.object.state.name, self.request.user)
messages.success(request, _('Motion status was set to: %s.'
self.object.write_log(
message_list=[ugettext_noop('State changed to '), self.object.state.name],
person=self.request.user)
messages.success(request, _('The state of the motion was set to %s.'
% html_strong(self.object.state)))
set_state = MotionSetStateView.as_view()
@ -602,7 +602,7 @@ class CreateAgendaItemView(SingleObjectMixin, RedirectView):
def pre_redirect(self, request, *args, **kwargs):
"""Create the agenda item."""
self.item = Item.objects.create(related_sid=self.object.sid)
self.object.write_log(ugettext_noop('Agenda item created'), self.request.user)
self.object.write_log([ugettext_noop('Agenda item created')], self.request.user)
create_agenda_item = CreateAgendaItemView.as_view()