Example #1
0
 def get_question_message(self):
     self._get_person_information()
     if not self.is_blocked:
         question = _("Do you really want to withdraw %s from the election?") % html_strong(self.person)
     else:
         question = _("Do you really want to unblock %s for the election?") % html_strong(self.person)
     return question
Example #2
0
 def get_question_message(self):
     self._get_person_information()
     if not self.is_blocked:
         question = _("Do you really want to withdraw %s from the election?") % html_strong(self.person)
     else:
         question = _("Do you really want to unblock %s for the election?") % html_strong(self.person)
     return question
Example #3
0
 def get_final_message(self):
     message = _("Candidate %s was withdrawn successfully.") % html_strong(
         self.person)
     if self.is_blocked:
         message = _("%s was unblocked successfully.") % html_strong(
             self.person)
     return message
Example #4
0
 def set_status(self, status):
     status_dict = dict(self.STATUS)
     if status not in status_dict:
         raise ValueError(_("%s is not a valid status.") % html_strong(status))
     if self.status == status:
         raise ValueError(_("The election status is already %s.") % html_strong(status_dict[status]))
     self.status = status
     self.save()
Example #5
0
 def set_status(self, status):
     status_dict = dict(self.STATUS)
     if status not in status_dict:
         raise ValueError(_('%s is not a valid status.') % html_strong(status))
     if self.status == status:
         raise ValueError(
             _('The assignment status is already %s.') % html_strong(status_dict[status]))
     self.status = status
     self.save()
Example #6
0
 def set_status(self, status):
     status_dict = dict(self.STATUS)
     if status not in status_dict:
         raise ValueError(_('%s is not a valid status.') % html_strong(status))
     if self.status == status:
         raise ValueError(
             _('The election status is already %s.') % html_strong(status_dict[status]))
     self.status = status
     self.save()
Example #7
0
 def get_final_message(self):
     """
     Prints the success message to the user.
     """
     # OpenSlidesError (invalid answer) should never be raised here because
     # this method should only be called if the answer is 'yes' or 'all'.
     if self.get_answer() == 'yes':
         message = _('Item %s was successfully deleted.') % html_strong(self.object)
     else:
         message = _('Item %s and its children were successfully deleted.') % html_strong(self.object)
     return message
Example #8
0
 def pre_post_redirect(self, request, *args, **kwargs):
     if self.get_answer() == 'all':
         self.object.delete(with_children=True)
         messages.success(request,
             _("Item %s and his children were successfully deleted.")
             % html_strong(self.object))
     elif self.get_answer() == 'yes':
         self.object.delete(with_children=False)
         messages.success(request,
             _("Item %s was successfully deleted.")
             % html_strong(self.object))
Example #9
0
 def get_final_message(self):
     """
     Prints the success message to the user.
     """
     # OpenSlidesError (invalid answer) should never be raised here because
     # this method should only be called if the answer is 'yes' or 'all'.
     if self.get_answer() == 'yes':
         message = _('Item %s was successfully deleted.') % html_strong(self.object)
     else:
         message = _('Item %s and its children were successfully deleted.') % html_strong(self.object)
     return message
Example #10
0
 def post(self, *args, **kwargs):
     self.object = self.get_object()
     if 'manual_sort' in self.request.POST:
         if self.request.user.has_perm('assignment.can_manage_assignment'):
             data = self.request.POST
             model = AssignmentCandidate
             for item in data:
                 if item.startswith('participant'):
                     model.save_sortorder(data['assignment'],
                         item[11:], data[item])
             messages.success(self.request, _(
                 "Sorting of candidates successfully saved."))
     else:
         if self.request.user.has_perm('assignment.can_nominate_other'):
             form = self.form_class(self.request.POST)
             if form.is_valid():
                 user = form.cleaned_data['candidate']
                 try:
                     self.object.run(user, self.request.user)
                 except NameError, e:
                     messages.error(self.request, e)
                 else:
                     messages.success(self.request, _(
                         "Candidate %s was nominated successfully.")
                         % html_strong(user))
Example #11
0
 def get_success_url(self):
     messages.success(self.request,
         _("Item %s was successfully modified.") \
         % html_strong(self.request.POST['title']))
     if 'apply' in self.request.POST:
         return ''
     return reverse(super(UpdateView, self).get_success_url())
Example #12
0
 def get_success_url(self):
     messages.success(self.request,
         _("Item %s was successfully created.") \
         % html_strong(self.request.POST['title']))
     if 'apply' in self.request.POST:
         return reverse(self.get_apply_url(), args=[self.object.id])
     return reverse(super(CreateView, self).get_success_url())
Example #13
0
def login(request):
    extra_content = {}
    try:
        admin = User.objects.get(pk=1)
        if  admin.check_password(admin.default_password):
            extra_content['first_time_message'] = _(
                "Installation was successfully! Use %(user)s "
                "(password: %(password)s) for first login.<br>"
                "<strong>Important:</strong> Please change the password after "
                "first login! Otherwise this message still appears for "
                "everyone  and could be a security risk.") % {
                    'user': html_strong(admin.username),
                    'password': html_strong(admin.default_password)}
            extra_content['next'] = reverse('password_change')
    except User.DoesNotExist:
        pass
    return django_login(request, template_name='participant/login.html', extra_context=extra_content)
Example #14
0
def login(request):
    extra_content = {}
    try:
        admin = User.objects.get(pk=1)
        if admin.check_password(admin.default_password):
            extra_content['first_time_message'] = _(
                "Installation was successfully! Use %(user)s "
                "(password: %(password)s) for first login.<br>"
                "<strong>Important:</strong> Please change the password after "
                "first login! Otherwise this message still appears for "
                "everyone  and could be a security risk.") % {
                    'user': html_strong(admin.username),
                    'password': html_strong(admin.default_password)}
            extra_content['next'] = reverse('password_change')
    except User.DoesNotExist:
        pass
    return django_login(request, template_name='participant/login.html', extra_context=extra_content)
Example #15
0
 def pre_redirect(self, *args, **kwargs):
     self.object = self.get_object()
     status = kwargs.get('status')
     if status is not None:
         try:
             self.object.set_status(status)
         except ValueError, e:
             messages.error(self.request, e)
         else:
             messages.success(
                 self.request,
                 _('Election status was set to: %s.') %
                 html_strong(self.object.get_status_display()))
Example #16
0
 def post(self, *args, **kwargs):
     if self.request.user.has_perm('assignment.can_nominate_other'):
         form = self.form_class(self.request.POST)
         if form.is_valid():
             user = form.cleaned_data['candidate']
             try:
                 self.get_object().run(user, self.request.user)
             except NameError as e:
                 messages.error(self.request, e)
             else:
                 messages.success(self.request, _(
                     "Candidate %s was nominated successfully.")
                     % html_strong(user))
     return super(AssignmentDetail, self).get(*args, **kwargs)
Example #17
0
 def post(self, *args, **kwargs):
     self.object = self.get_object()
     if self.request.user.has_perm('assignment.can_nominate_other'):
         form = self.form_class(self.request.POST)
         if form.is_valid():
             user = form.cleaned_data['candidate']
             try:
                 self.object.run(user, self.request.user)
             except NameError, e:
                 messages.error(self.request, e)
             else:
                 messages.success(self.request, _(
                     "Candidate %s was nominated successfully.")
                     % html_strong(user))
Example #18
0
 def pre_redirect(self, *args, **kwargs):
     self.object = self.get_object()
     status = kwargs.get('status')
     if status is not None:
         try:
             self.object.set_status(status)
         except ValueError, e:
             messages.error(self.request, e)
         else:
             messages.success(
                 self.request,
                 _('Election status was set to: %s.') %
                 html_strong(self.object.get_status_display())
             )
Example #19
0
 def pre_redirect(self, request, *args, **kwargs):
     """
     Save the new state and write a log message.
     """
     success = False
     if self.reset:
         self.get_object().reset_state()
         success = True
     elif self.get_object().state.id == int(kwargs['state']):
         messages.error(request, _('You can not set the state of the motion. It is already done.'))
     elif int(kwargs['state']) not in [state.id for state in self.get_object().state.next_states.all()]:
         messages.error(request, _('You can not set the state of the motion to %s.') % _(State.objects.get(pk=int(kwargs['state'])).name))
     else:
         self.get_object().set_state(int(kwargs['state']))
         success = True
     if success:
         self.get_object().save(update_fields=['state', 'identifier'])
         self.get_object().write_log(
             message_list=[ugettext_noop('State changed to'), ' ', self.get_object().state.name],  # TODO: Change string to 'State set to ...'
             person=self.request.user)
         messages.success(request,
                          _('The state of the motion was set to %s.')
                          % html_strong(_(self.get_object().state.name)))
Example #20
0
 def pre_redirect(self, request, *args, **kwargs):
     """
     Save the new state and write a log message.
     """
     self.object = self.get_object()
     success = False
     if self.reset:
         self.object.reset_state()
         success = True
     elif self.object.state.id == int(kwargs['state']):
         messages.error(request, _('You can not set the state of the motion. It is already done.'))
     elif int(kwargs['state']) not in [state.id for state in self.object.state.next_states.all()]:
         messages.error(request, _('You can not set the state of the motion to %s.') % _(State.objects.get(pk=int(kwargs['state'])).name))
     else:
         self.object.set_state(int(kwargs['state']))
         success = True
     if success:
         self.object.save(update_fields=['state', 'identifier'])
         self.object.write_log(
             message_list=[ugettext_noop('State changed to'), ' ', self.object.state.name],  # TODO: Change string to 'State set to ...'
             person=self.request.user)
         messages.success(request,
                          _('The state of the motion was set to %s.')
                          % html_strong(_(self.object.state.name)))
Example #21
0
 def get_final_message(self):
     message = _("Candidate %s was withdrawn successfully.") % html_strong(self.person)
     if self.is_blocked:
         message = _("%s was unblocked successfully.") % html_strong(self.person)
     return message
Example #22
0
def import_users(csvfile):
    error_messages = []
    count_success = 0
    try:
        # check for valid encoding (will raise UnicodeDecodeError if not)
        csvfile.read().decode('utf-8')
        csvfile.seek(0)

        with transaction.commit_on_success():
            dialect = csv.Sniffer().sniff(csvfile.readline().decode('utf-8'))
            dialect = csv_ext.patchup(dialect)
            csvfile.seek(0)

            for (line_no, line) in enumerate(
                    csv.reader(
                        (line.decode('utf8') for line in csvfile.readlines()),
                        dialect=dialect)):
                if line_no:
                    try:
                        (title, first_name, last_name, gender, email, groups,
                         structure_level, committee, about_me, comment,
                         is_active) = line[:11]
                    except ValueError:
                        error_messages.append(
                            _('Ignoring malformed line %d in import file.') %
                            (line_no + 1))
                        continue
                    if not first_name and not last_name:
                        error_messages.append(
                            _("In line %d you have to provide either 'first_name' or 'last_name'."
                              ) % (line_no + 1))
                        continue
                    user = User()
                    user.title = title
                    user.last_name = last_name
                    user.first_name = first_name
                    user.username = gen_username(first_name, last_name)
                    user.gender = gender
                    user.email = email
                    user.structure_level = structure_level
                    user.committee = committee
                    user.about_me = about_me
                    user.comment = comment
                    if is_active == '1':
                        user.is_active = True
                    else:
                        user.is_active = False
                    user.default_password = gen_password()
                    user.save()
                    for groupid in groups.split(','):
                        try:
                            if groupid and int(groupid):
                                Group.objects.get(
                                    pk=groupid).user_set.add(user)
                        except (Group.DoesNotExist, ValueError):
                            error_messages.append(
                                _('Ignoring group id "%(id)s" in line %(line)d which does not exist.'
                                  ) % {
                                      'id': groupid,
                                      'line': line_no + 1
                                  })
                            continue
                    user.reset_password()
                    user.save()
                    count_success += 1
    except csv.Error:
        error_messages.append(
            _('Import aborted because of severe errors in the input file.'))
    except UnicodeDecodeError:
        error_messages.append(
            _('Import file has wrong character encoding, only UTF-8 is supported!'
              ))

    # Build final success message
    if count_success:
        success_message = _(
            '%d new users were successfully imported.') % count_success
    else:
        success_message = ''

    # Build final error message with all error items (one bullet point for each csv line)
    full_error_message = ''
    if error_messages:
        full_error_message = "%s <ul>" % html_strong(_("Errors"))
        for error in error_messages:
            full_error_message += "<li>%s</li>" % error
        full_error_message += "</ul>"

    return success_message, '', full_error_message
Example #23
0
 def get_final_message(self):
     return _('The Password for %s was successfully reset.') % html_strong(self.object)
Example #24
0
def import_users(csvfile):
    error_messages = []
    count_success = 0
    try:
        # check for valid encoding (will raise UnicodeDecodeError if not)
        csvfile.read().decode('utf-8')
        csvfile.seek(0)

        with transaction.commit_on_success():
            dialect = csv.Sniffer().sniff(csvfile.readline().decode('utf-8'))
            dialect = csv_ext.patchup(dialect)
            csvfile.seek(0)

            for (line_no, line) in enumerate(csv.reader(
                    (line.decode('utf8') for line in csvfile.readlines()),                                                        dialect=dialect)):
                if line_no:
                    try:
                        (title, first_name, last_name, gender, email, groups,
                         structure_level, committee, about_me, comment, is_active) = line[:11]
                    except ValueError:
                        error_messages.append(_('Ignoring malformed line %d in import file.') % (line_no + 1))
                        continue
                    if not first_name and not last_name:
                        error_messages.append(_("In line %d you have to provide either 'first_name' or 'last_name'.") % (line_no + 1))
                        continue
                    user = User()
                    user.title = title
                    user.last_name = last_name
                    user.first_name = first_name
                    user.username = gen_username(first_name, last_name)
                    user.gender = gender
                    user.email = email
                    user.structure_level = structure_level
                    user.committee = committee
                    user.about_me = about_me
                    user.comment = comment
                    if is_active == '1':
                        user.is_active = True
                    else:
                        user.is_active = False
                    user.default_password = gen_password()
                    user.save()
                    for groupid in groups:
                        try:
                            if groupid != ",":
                                Group.objects.get(pk=groupid).user_set.add(user)
                        except ValueError:
                            error_messages.append(_('Ignoring malformed group id in line %d.') % (line_no + 1))
                            continue
                        except Group.DoesNotExist:
                            error_messages.append(_('Group id %(id)s does not exists (line %(line)d).') % {'id': groupid, 'line': line_no + 1})
                            continue
                    user.reset_password()
                    count_success += 1
    except csv.Error:
        error_messages.append(_('Import aborted because of severe errors in the input file.'))
    except UnicodeDecodeError:
        error_messages.append(_('Import file has wrong character encoding, only UTF-8 is supported!'))

    # Build final success message
    if count_success:
        success_message = _('%d new participants were successfully imported.') % count_success
    else:
        success_message = ''

    # Build final error message with all error items (one bullet point for each csv line)
    full_error_message = ''
    if error_messages:
        full_error_message = "%s <ul>" % html_strong(_("Errors"))
        for error in error_messages:
            full_error_message += "<li>%s</li>" % error
        full_error_message += "</ul>"

    return success_message, '', full_error_message
Example #25
0
def import_motions(csvfile, default_submitter, override, importing_person=None):
    """
    Imports motions from a csv file.

    The file must be encoded in utf8. The first line (header) is ignored.
    If no or multiple submitters found, the default submitter is used. If
    a motion with a given identifier already exists, the motion is overridden,
    when the flag 'override' is True. If no or multiple categories found,
    the category is set to None.
    """
    count_success = 0
    count_lines = 0

    # Check encoding
    try:
        csvfile.read().decode('utf8')
    except UnicodeDecodeError:
        return '', '', _('Import file has wrong character encoding, only UTF-8 is supported!')
    csvfile.seek(0)

    with transaction.commit_on_success():
        dialect = csv.Sniffer().sniff(csvfile.readline())
        dialect = csv_ext.patchup(dialect)
        csvfile.seek(0)
        all_error_messages = []
        all_warning_messages = []
        for (line_no, line) in enumerate(csv.reader(csvfile, dialect=dialect)):
            warning = []
            if line_no < 1:
                # Do not read the header line
                continue
            importline = html_strong(_('Line %d:') % (line_no + 1))
            count_lines += 1
            # Check format
            try:
                (identifier, title, text, reason, submitter, category) = line[:6]
            except ValueError:
                msg = _('Line is malformed. Motion not imported. Please check the required values.')
                all_error_messages.append("%s %s" % (importline, msg))
                continue

            # Check existing motions according to the identifier
            if identifier:
                try:
                    motion = Motion.objects.get(identifier=identifier)
                except Motion.DoesNotExist:
                    motion = Motion(identifier=identifier)
                else:
                    if not override:
                        msg = _('Identifier already exists. Motion not imported.')
                        all_error_messages.append("%s %s" % (importline, msg))
                        continue
            else:
                motion = Motion()

            # Insert data
            motion.title = title
            motion.text = text
            motion.reason = reason
            if category:
                try:
                    motion.category = Category.objects.get(name=category)
                except Category.DoesNotExist:
                    warning.append(_('Category unknown. No category is used.'))
                except Category.MultipleObjectsReturned:
                    warning.append(_('Several suitable categories found. No category is used.'))
            motion.save()

            # Add submitter
            person_found = False
            if submitter:
                for person in Persons():
                    if person.clean_name == submitter.decode('utf8'):
                        if person_found:
                            warning.append(_('Several suitable submitters found.'))
                            person_found = False
                            break
                        else:
                            new_submitter = person
                            person_found = True
            if not person_found:
                warning.append(_('Submitter unknown. Default submitter is used.'))
                new_submitter = default_submitter

            # add all warnings of each csv line to one warning message
            if warning:
                warning_message_string = "%s " % importline
                warning_message_string += " ".join(warning)
                all_warning_messages.append(warning_message_string)

            motion.clear_submitters()
            motion.add_submitter(new_submitter)

            motion.write_log(message_list=[ugettext_noop('Motion imported')],
                             person=importing_person)
            count_success += 1

        # Build final error message with all error items (one bullet point for each csv line)
        full_error_message = ''
        if all_error_messages:
            full_error_message = "%s <ul>" % html_strong(_("Errors"))
            for error in all_error_messages:
                full_error_message += "<li>%s</li>" % error
            full_error_message += "</ul>"

        # Build final warning message with all warning items (one bullet point for each csv line)
        full_warning_message = ''
        if all_warning_messages:
            full_warning_message = "%s <ul>" % html_strong(_("Warnings"))
            for warning in all_warning_messages:
                full_warning_message += "<li>%s</li>" % warning
            full_warning_message += "</ul>"

        # Build final success message
        if count_success:
            success_message = '<strong>%s</strong><br>%s' % (
                _('Summary'),
                _('%(counts)d of %(total)d motions successfully imported.')
                % {'counts': count_success, 'total': count_lines})
        else:
            success_message = ''

    return success_message, full_warning_message, full_error_message
Example #26
0
 def get_question(self):
     return _('Do you really want to delete %s?') % html_strong(self.object)
Example #27
0
 def get_success_message(self):
     return _('The Password for %s was successfully reset.') % html_strong(
         self.object)
Example #28
0
        self.object = self.get_object()
        try:
            if self.reset:
                self.object.reset_state()
            else:
                self.object.set_state(int(kwargs['state']))
        except WorkflowError, e:  # TODO: Is a WorkflowError still possible here?
            messages.error(request, e)
        else:
            self.object.save(update_fields=['state', 'identifier'])
            self.object.write_log(
                message_list=[ugettext_noop('State changed to'), ' %s' % 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.name)))

set_state = MotionSetStateView.as_view()
reset_state = MotionSetStateView.as_view(reset=True)


class CreateAgendaItemView(SingleObjectMixin, RedirectView):
    """
    View to create and agenda item for a motion.
    """
    permission_required = 'agenda.can_manage_agenda'
    model = Motion
    url_name = 'item_overview'
    url_name_args = []

    def get(self, request, *args, **kwargs):
Example #29
0
 def get_success_message(self):
     return _('%s was successfully deleted.') % html_strong(self.object)
Example #30
0
 def get_success_message(self):
     return _('%s was successfully deleted.') % html_strong(self.object)
Example #31
0
 def test_string(self):
     self.assertEqual(html_strong('some text'), '<strong>some text</strong>')
Example #32
0
def import_motions(csv_file,
                   default_submitter,
                   override=False,
                   importing_person=None):
    """
    Imports motions from a csv file.

    The file must be encoded in utf8. The first line (header) is ignored.
    If no or multiple submitters found, the default submitter is used. If
    a motion with a given identifier already exists, the motion is overridden,
    when the flag 'override' is true. If no or multiple categories found,
    the category is set to None.
    """
    error_messages = []
    warning_messages = []
    count_success = 0
    count_lines = 0

    # Check encoding
    try:
        csv_file.read().decode('utf8')
    except UnicodeDecodeError:
        return (0, [
            _('Import file has wrong character encoding, only UTF-8 is supported!'
              )
        ], [])
    csv_file.seek(0)

    with transaction.commit_on_success():
        dialect = csv.Sniffer().sniff(csv_file.readline())
        dialect = csv_ext.patchup(dialect)
        csv_file.seek(0)
        for (line_no, line) in enumerate(csv.reader(csv_file,
                                                    dialect=dialect)):
            warnings = []
            if line_no < 1:
                # Do not read the header line
                continue

            count_lines += 1
            # Check format
            try:
                (identifier, title, text, reason, submitter,
                 category) = line[:6]
            except ValueError:
                error_line = html_strong(
                    _('Line %d of import file:') % (line_no + 1))
                msg = _(
                    'Line is malformed. Motion not imported. Please check the required values.'
                )
                error_messages.append("%s<br>%s" % (error_line, msg))
                continue

            # Check existing motions according to the identifier
            if identifier:
                try:
                    motion = Motion.objects.get(identifier=identifier)
                except Motion.DoesNotExist:
                    motion = Motion(identifier=identifier)
                else:
                    if not override:
                        error_line = html_strong(
                            _('Line %d of import file:') % (line_no + 1))
                        msg = _(
                            'Identifier already exists. Motion not imported.')
                        error_messages.append("%s<br>%s" % (error_line, msg))
                        continue
            else:
                motion = Motion()

            # Insert data
            motion.title = title
            motion.text = text
            motion.reason = reason
            if category:
                try:
                    motion.category = Category.objects.get(name=category)
                except Category.DoesNotExist:
                    warnings.append(
                        _('Category unknown. No category is used.'))
                except Category.MultipleObjectsReturned:
                    warnings.append(
                        _('Several suitable categories found. No category is used.'
                          ))
            motion.save()

            # Add submitter
            person_found = False
            if submitter:
                for person in Persons():
                    if person.clean_name == submitter.decode('utf8'):
                        if person_found:
                            warnings.append(
                                _('Several suitable submitters found.'))
                            person_found = False
                            break
                        else:
                            new_submitter = person
                            person_found = True
            if not person_found:
                warnings.append(
                    _('Submitter unknown. Default submitter is used.'))
                new_submitter = default_submitter

            # show summarized warning message for each import line
            if warnings:
                warning_line = _('Line %d of import file:') % (line_no + 1)
                warning_message_string = "%s<ul>" % html_strong(warning_line)
                for w in warnings:
                    warning_message_string += "<li>%s</li>" % w
                warning_message_string += "</ul>"
                warning_messages.append(warning_message_string)
            motion.clear_submitters()
            motion.add_submitter(new_submitter)

            motion.write_log(message_list=[ugettext_noop('Motion imported')],
                             person=importing_person)
            count_success += 1

    return (count_success, count_lines, error_messages, warning_messages)
Example #33
0
def import_motions(csv_file, default_submitter, override=False, importing_person=None):
    """
    Imports motions from a csv file.

    The file must be encoded in utf8. The first line (header) is ignored.
    If no or multiple submitters found, the default submitter is used. If
    a motion with a given identifier already exists, the motion is overridden,
    when the flag 'override' is true. If no or multiple categories found,
    the category is set to None.
    """
    error_messages = []
    warning_messages = []
    count_success = 0
    count_lines = 0

    # Check encoding
    try:
        csv_file.read().decode('utf8')
    except UnicodeDecodeError:
        return (0, [_('Import file has wrong character encoding, only UTF-8 is supported!')], [])
    csv_file.seek(0)

    with transaction.commit_on_success():
        dialect = csv.Sniffer().sniff(csv_file.readline())
        dialect = csv_ext.patchup(dialect)
        csv_file.seek(0)
        for (line_no, line) in enumerate(csv.reader(csv_file, dialect=dialect)):
            warnings = []
            if line_no < 1:
                # Do not read the header line
                continue

            count_lines += 1
            # Check format
            try:
                (identifier, title, text, reason, submitter, category) = line[:6]
            except ValueError:
                error_line = html_strong(_('Line %d of import file:') % (line_no + 1))
                msg = _('Line is malformed. Motion not imported. Please check the required values.')
                error_messages.append("%s<br>%s" % (error_line, msg))
                continue

            # Check existing motions according to the identifier
            if identifier:
                try:
                    motion = Motion.objects.get(identifier=identifier)
                except Motion.DoesNotExist:
                    motion = Motion(identifier=identifier)
                else:
                    if not override:
                        error_line = html_strong(_('Line %d of import file:') % (line_no + 1))
                        msg = _('Identifier already exists. Motion not imported.')
                        error_messages.append("%s<br>%s" % (error_line, msg))
                        continue
            else:
                motion = Motion()

            # Insert data
            motion.title = title
            motion.text = text
            motion.reason = reason
            if category:
                try:
                    motion.category = Category.objects.get(name=category)
                except Category.DoesNotExist:
                    warnings.append(_('Category unknown. No category is used.'))
                except Category.MultipleObjectsReturned:
                    warnings.append(_('Several suitable categories found. No category is used.'))
            motion.save()

            # Add submitter
            person_found = False
            if submitter:
                for person in Persons():
                    if person.clean_name == submitter.decode('utf8'):
                        if person_found:
                            warnings.append(_('Several suitable submitters found.'))
                            person_found = False
                            break
                        else:
                            new_submitter = person
                            person_found = True
            if not person_found:
                warnings.append(_('Submitter unknown. Default submitter is used.'))
                new_submitter = default_submitter

            # show summarized warning message for each import line
            if warnings:
                warning_line = _('Line %d of import file:') % (line_no + 1)
                warning_message_string = "%s<ul>" % html_strong(warning_line)
                for w in warnings:
                    warning_message_string += "<li>%s</li>" % w
                warning_message_string += "</ul>"
                warning_messages.append(warning_message_string)
            motion.clear_submitters()
            motion.add_submitter(new_submitter)

            motion.write_log(message_list=[ugettext_noop('Motion imported')],
                             person=importing_person)
            count_success += 1

    return (count_success, count_lines, error_messages, warning_messages)
Example #34
0
 def get_final_message(self):
     return _('The Password for %s was successfully reset.') % html_strong(self.get_object())
Example #35
0
 def get_question(self):
     return _('Do you really want to delete %s?') % html_strong(self.object)
Example #36
0
 def test_string(self):
     self.assertEqual(html_strong('some text'),
                      '<strong>some text</strong>')
Example #37
0
                self.object.reset_state()
            else:
                self.object.set_state(int(kwargs['state']))
        except WorkflowError, e:  # TODO: Is a WorkflowError still possible here?
            messages.error(request, e)
        else:
            self.object.save(update_fields=['state', 'identifier'])
            self.object.write_log(message_list=[
                ugettext_noop('State changed to'),
                ' %s' % 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.name)))


set_state = MotionSetStateView.as_view()
reset_state = MotionSetStateView.as_view(reset=True)


class CreateAgendaItemView(SingleObjectMixin, RedirectView):
    """
    View to create and agenda item for a motion.
    """
    permission_required = 'agenda.can_manage_agenda'
    model = Motion
    url_name = 'item_overview'
    url_name_args = []