コード例 #1
0
ファイル: test_models.py プロジェクト: HengeSense/OpenSlides
 def test_person_api(self):
     self.assertTrue(hasattr(self.group1, 'person_id'))
     person_id = "group:%d" % self.group1.id
     self.assertEqual(self.group1.person_id, person_id)
     self.assertRaises(Group.DoesNotExist)
     self.group1.group_as_person = True
     self.group1.save()
     self.assertEqual(get_person(person_id), self.group1)
コード例 #2
0
 def test_person_api(self):
     self.assertTrue(hasattr(self.group1, 'person_id'))
     person_id = "group:%d" % self.group1.id
     self.assertEqual(self.group1.person_id, person_id)
     self.assertRaises(Group.DoesNotExist)
     self.group1.group_as_person = True
     self.group1.save()
     self.assertEqual(get_person(person_id), self.group1)
コード例 #3
0
ファイル: views.py プロジェクト: kuenzaa/OpenSlides
def set_elected(request, assignment_id, user_id, elected=True):
    assignment = Assignment.objects.get(pk=assignment_id)
    person = get_person(user_id)
    assignment.set_elected(person, elected)

    if request.is_ajax():
        if elected:
            link = reverse('assignment_user_not_elected', args=[assignment.id, person.person_id])
            text = _('not elected')
        else:
            link = reverse('assignment_user_elected', args=[assignment.id, person.person_id])
            text = _('elected')
        return ajax_request({'elected': elected, 'link': link, 'text': text})

    return redirect(reverse('assignment_view', args=[assignment_id]))
コード例 #4
0
ファイル: views.py プロジェクト: Shirk/OpenSlides
def delother(request, assignment_id, user_id):
    assignment = Assignment.objects.get(pk=assignment_id)
    person = get_person(user_id)
    is_blocked = assignment.is_blocked(person)

    if request.method == 'POST':
        try:
            assignment.delrun(person, blocked=False)
        except Exception, e:
            messages.error(request, e)
        else:
            if not is_blocked:
                message = _("Candidate <b>%s</b> was withdrawn successfully.") % person
            else:
                message = _("<b>%s</b> was unblocked successfully.") % person
            messages.success(request, message)
コード例 #5
0
ファイル: test_models.py プロジェクト: HengeSense/OpenSlides
 def test_person_api(self):
     self.assertTrue(hasattr(self.user1, 'person_id'))
     self.assertEqual(self.user1.person_id, 'user:2')
     self.assertEqual(get_person('user:2'), self.user1)
     self.assertEqual(len(Persons(person_prefix_filter='user')), 2)
コード例 #6
0
 def test_person_api(self):
     self.assertTrue(hasattr(self.user1, 'person_id'))
     self.assertEqual(self.user1.person_id, 'user:1')
     self.assertEqual(get_person('user:1'), self.user1)
     self.assertEqual(len(Persons(person_prefix_filter='user')), 1)
コード例 #7
0
ファイル: views.py プロジェクト: MechanisM/OpenSlides
def motion_import(request):
    if request.method == 'POST':
        form = MotionImportForm(request.POST, request.FILES)
        if form.is_valid():
            import_permitted = form.cleaned_data['import_permitted']
            try:
                # check for valid encoding (will raise UnicodeDecodeError if not)
                request.FILES['csvfile'].read().decode('utf-8')
                request.FILES['csvfile'].seek(0)

                users_generated = 0
                motions_generated = 0
                motions_modified = 0
                groups_assigned = 0
                groups_generated = 0
                with transaction.commit_on_success():
                    dialect = csv.Sniffer().sniff(request.FILES['csvfile'].readline())
                    dialect = csv_ext.patchup(dialect)
                    request.FILES['csvfile'].seek(0)
                    for (lno, line) in enumerate(csv.reader(request.FILES['csvfile'], dialect=dialect)):
                        # basic input verification
                        if lno < 1:
                            continue
                        try:
                            (number, title, text, reason, first_name, last_name, is_group) = line[:7]
                            if is_group.strip().lower() in ['y', 'j', 't', 'yes', 'ja', 'true', '1', 1]:
                                is_group = True
                            else:
                                is_group = False
                        except ValueError:
                            messages.error(request, _('Ignoring malformed line %d in import file.') % (lno + 1))
                            continue
                        form = MotionForm({'title': title, 'text': text, 'reason': reason})
                        if not form.is_valid():
                            messages.error(request, _('Ignoring malformed line %d in import file.') % (lno + 1))
                            continue
                        if number:
                            try:
                                number = abs(long(number))
                                if number < 1:
                                    messages.error(request, _('Ignoring malformed line %d in import file.') % (lno + 1))
                                    continue
                            except ValueError:
                                messages.error(request, _('Ignoring malformed line %d in import file.') % (lno + 1))
                                continue

                        if is_group:
                            # fetch existing groups or issue an error message
                            try:
                                user = Group.objects.get(name=last_name)
                                if user.group_as_person == False:
                                    messages.error(request, _('Ignoring line %d because the assigned group may not act as a person.') % (lno + 1))
                                    continue
                                else:
                                    user = get_person(user.person_id)

                                groups_assigned += 1
                            except Group.DoesNotExist:
                                group = Group()
                                group.group_as_person = True
                                group.description = _('Created by motion import.')
                                group.name = last_name
                                group.save()
                                groups_generated += 1

                                user = get_person(group.person_id)
                        else:
                            # fetch existing users or create new users as needed
                            try:
                                user = User.objects.get(first_name=first_name, last_name=last_name)
                            except User.DoesNotExist:
                                user = None
                            if user is None:
                                if not first_name or not last_name:
                                    messages.error(request, _('Ignoring line %d because it contains an incomplete first / last name pair.') % (lno + 1))
                                    continue

                                user = User()
                                user.last_name = last_name
                                user.first_name = first_name
                                user.username = gen_username(first_name, last_name)
                                user.structure_level = ''
                                user.committee = ''
                                user.gender = ''
                                user.type = ''
                                user.default_password = gen_password()
                                user.save()
                                user.reset_password()
                                users_generated += 1
                        # create / modify the motion
                        motion = None
                        if number:
                            try:
                                motion = Motion.objects.get(number=number)
                                motions_modified += 1
                            except Motion.DoesNotExist:
                                motion = None
                        if motion is None:
                            motion = Motion(submitter=user)
                            if number:
                                motion.number = number
                            motions_generated += 1

                        motion.title = form.cleaned_data['title']
                        motion.text = form.cleaned_data['text']
                        motion.reason = form.cleaned_data['reason']
                        if import_permitted:
                            motion.status = 'per'

                        motion.save(user, trivial_change=True)

                if motions_generated:
                    messages.success(request, ungettext('%d motion was successfully imported.',
                                                '%d motions were successfully imported.', motions_generated) % motions_generated)
                if motions_modified:
                    messages.success(request, ungettext('%d motion was successfully modified.',
                                                '%d motions were successfully modified.', motions_modified) % motions_modified)
                if users_generated:
                    messages.success(request, ungettext('%d new user was added.', '%d new users were added.', users_generated) % users_generated)

                if groups_generated:
                    messages.success(request, ungettext('%d new group was added.', '%d new groups were added.', groups_generated) % groups_generated)

                if groups_assigned:
                    messages.success(request, ungettext('%d group assigned to motions.', '%d groups assigned to motions.', groups_assigned) % groups_assigned)
                return redirect(reverse('motion_overview'))

            except csv.Error:
                messages.error(request, _('Import aborted because of severe errors in the input file.'))
            except UnicodeDecodeError:
                messages.error(request, _('Import file has wrong character encoding, only UTF-8 is supported!'))
        else:
            messages.error(request, _('Please check the form for errors.'))
    else:
        messages.warning(request, _("Attention: Existing motions will be modified if you import new motions with the same number."))
        messages.warning(request, _("Attention: Importing an motions without a number multiple times will create duplicates."))
        form = MotionImportForm()
    return {
        'form': form,
    }
コード例 #8
0
ファイル: views.py プロジェクト: DerPate/OpenSlides
 def pre_redirect(self, *args, **kwargs):
     self.object = self.get_object()
     self.person = get_person(kwargs['user_id'])
     self.elected = kwargs['elected']
     self.object.set_elected(self.person, self.elected)
コード例 #9
0
ファイル: views.py プロジェクト: DerPate/OpenSlides
 def _get_person_information(self):
     self.object = self.get_object()
     self.person = get_person(self.kwargs.get('user_id'))
     self.is_blocked = self.object.is_blocked(self.person)
コード例 #10
0
ファイル: views.py プロジェクト: DerPate/OpenSlides
 def pre_redirect(self, *args, **kwargs):
     self.object = self.get_object()
     self.person = get_person(kwargs['user_id'])
     self.elected = kwargs['elected']
     self.object.set_elected(self.person, self.elected)
コード例 #11
0
ファイル: views.py プロジェクト: DerPate/OpenSlides
 def _get_person_information(self):
     self.object = self.get_object()
     self.person = get_person(self.kwargs.get('user_id'))
     self.is_blocked = self.object.is_blocked(self.person)
コード例 #12
0
def motion_import(request):
    if request.method == 'POST':
        form = MotionImportForm(request.POST, request.FILES)
        if form.is_valid():
            import_permitted = form.cleaned_data['import_permitted']
            try:
                # check for valid encoding (will raise UnicodeDecodeError if not)
                request.FILES['csvfile'].read().decode('utf-8')
                request.FILES['csvfile'].seek(0)

                users_generated = 0
                motions_generated = 0
                motions_modified = 0
                groups_assigned = 0
                groups_generated = 0
                with transaction.commit_on_success():
                    dialect = csv.Sniffer().sniff(
                        request.FILES['csvfile'].readline())
                    dialect = csv_ext.patchup(dialect)
                    request.FILES['csvfile'].seek(0)
                    for (lno, line) in enumerate(
                            csv.reader(request.FILES['csvfile'],
                                       dialect=dialect)):
                        # basic input verification
                        if lno < 1:
                            continue
                        try:
                            (number, title, text, reason, first_name,
                             last_name, is_group) = line[:7]
                            if is_group.strip().lower() in [
                                    'y', 'j', 't', 'yes', 'ja', 'true', '1', 1
                            ]:
                                is_group = True
                            else:
                                is_group = False
                        except ValueError:
                            messages.error(
                                request,
                                _('Ignoring malformed line %d in import file.')
                                % (lno + 1))
                            continue
                        form = MotionForm({
                            'title': title,
                            'text': text,
                            'reason': reason
                        })
                        if not form.is_valid():
                            messages.error(
                                request,
                                _('Ignoring malformed line %d in import file.')
                                % (lno + 1))
                            continue
                        if number:
                            try:
                                number = abs(long(number))
                                if number < 1:
                                    messages.error(
                                        request,
                                        _('Ignoring malformed line %d in import file.'
                                          ) % (lno + 1))
                                    continue
                            except ValueError:
                                messages.error(
                                    request,
                                    _('Ignoring malformed line %d in import file.'
                                      ) % (lno + 1))
                                continue

                        if is_group:
                            # fetch existing groups or issue an error message
                            try:
                                user = Group.objects.get(name=last_name)
                                if user.group_as_person == False:
                                    messages.error(
                                        request,
                                        _('Ignoring line %d because the assigned group may not act as a person.'
                                          ) % (lno + 1))
                                    continue
                                else:
                                    user = get_person(user.person_id)

                                groups_assigned += 1
                            except Group.DoesNotExist:
                                group = Group()
                                group.group_as_person = True
                                group.description = _(
                                    'Created by motion import.')
                                group.name = last_name
                                group.save()
                                groups_generated += 1

                                user = get_person(group.person_id)
                        else:
                            # fetch existing users or create new users as needed
                            try:
                                user = User.objects.get(first_name=first_name,
                                                        last_name=last_name)
                            except User.DoesNotExist:
                                user = None
                            if user is None:
                                if not first_name or not last_name:
                                    messages.error(
                                        request,
                                        _('Ignoring line %d because it contains an incomplete first / last name pair.'
                                          ) % (lno + 1))
                                    continue

                                user = User()
                                user.last_name = last_name
                                user.first_name = first_name
                                user.username = gen_username(
                                    first_name, last_name)
                                user.structure_level = ''
                                user.committee = ''
                                user.gender = ''
                                user.type = ''
                                user.default_password = gen_password()
                                user.save()
                                user.reset_password()
                                users_generated += 1
                        # create / modify the motion
                        motion = None
                        if number:
                            try:
                                motion = Motion.objects.get(number=number)
                                motions_modified += 1
                            except Motion.DoesNotExist:
                                motion = None
                        if motion is None:
                            motion = Motion(submitter=user)
                            if number:
                                motion.number = number
                            motions_generated += 1

                        motion.title = form.cleaned_data['title']
                        motion.text = form.cleaned_data['text']
                        motion.reason = form.cleaned_data['reason']
                        if import_permitted:
                            motion.status = 'per'

                        motion.save(user, trivial_change=True)

                if motions_generated:
                    messages.success(
                        request,
                        ungettext('%d motion was successfully imported.',
                                  '%d motions were successfully imported.',
                                  motions_generated) % motions_generated)
                if motions_modified:
                    messages.success(
                        request,
                        ungettext('%d motion was successfully modified.',
                                  '%d motions were successfully modified.',
                                  motions_modified) % motions_modified)
                if users_generated:
                    messages.success(
                        request,
                        ungettext('%d new user was added.',
                                  '%d new users were added.', users_generated)
                        % users_generated)

                if groups_generated:
                    messages.success(
                        request,
                        ungettext('%d new group was added.',
                                  '%d new groups were added.',
                                  groups_generated) % groups_generated)

                if groups_assigned:
                    messages.success(
                        request,
                        ungettext('%d group assigned to motions.',
                                  '%d groups assigned to motions.',
                                  groups_assigned) % groups_assigned)
                return redirect(reverse('motion_overview'))

            except csv.Error:
                messages.error(
                    request,
                    _('Import aborted because of severe errors in the input file.'
                      ))
            except UnicodeDecodeError:
                messages.error(
                    request,
                    _('Import file has wrong character encoding, only UTF-8 is supported!'
                      ))
        else:
            messages.error(request, _('Please check the form for errors.'))
    else:
        messages.warning(
            request,
            _("Attention: Existing motions will be modified if you import new motions with the same number."
              ))
        messages.warning(
            request,
            _("Attention: Importing an motions without a number multiple times will create duplicates."
              ))
        form = MotionImportForm()
    return {
        'form': form,
    }