From b310d6077e09d763ac8947269bb81209219259b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Tue, 2 Apr 2013 17:40:57 +0200 Subject: [PATCH] Move personal info widget to a new app: account. --- openslides/account/__init__.py | 0 .../account}/personal_info_widget.html | 26 +++--- openslides/account/views.py | 62 ++++++++++++++ openslides/global_settings.py | 1 + openslides/participant/views.py | 32 +------- tests/account/__init__.py | 0 tests/account/test_widgets.py | 80 +++++++++++++++++++ 7 files changed, 159 insertions(+), 42 deletions(-) create mode 100644 openslides/account/__init__.py rename openslides/{participant/templates/participant => account/templates/account}/personal_info_widget.html (50%) create mode 100644 openslides/account/views.py create mode 100644 tests/account/__init__.py create mode 100644 tests/account/test_widgets.py diff --git a/openslides/account/__init__.py b/openslides/account/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/openslides/participant/templates/participant/personal_info_widget.html b/openslides/account/templates/account/personal_info_widget.html similarity index 50% rename from openslides/participant/templates/participant/personal_info_widget.html rename to openslides/account/templates/account/personal_info_widget.html index e5d8ffde0..542f3f8df 100644 --- a/openslides/participant/templates/participant/personal_info_widget.html +++ b/openslides/account/templates/account/personal_info_widget.html @@ -2,48 +2,48 @@ {% load tags %} {% if config_motion_min_supporters %}
{% endif %}
diff --git a/openslides/account/views.py b/openslides/account/views.py new file mode 100644 index 000000000..a3b9c47e9 --- /dev/null +++ b/openslides/account/views.py @@ -0,0 +1,62 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" + openslides.account.views + ~~~~~~~~~~~~~~~~~~~~~~~~ + + Views for the account app. + + :copyright: 2011–2013 by OpenSlides team, see AUTHORS. + :license: GNU GPL, see LICENSE for more details. +""" + +from django.utils.translation import ugettext as _ + +from openslides.config.api import config +from openslides.projector.projector import Widget + + +def get_widgets(request): + """ + Returns the widgets of the account app. It is only a personal_info_widget. + """ + return [get_personal_info_widget(request)] + + +def get_personal_info_widget(request): + """ + Provides a widget for personal info. It shows your submitted and supported + motions and where you are supporter or candidate. If one of the modules + motion or assignment does not exist, it is not loaded. If both don't + exist, the widget disapears. + """ + personal_info_context = {} + + try: + from openslides.motion.models import Motion + except ImportError: + pass + else: + personal_info_context.update({ + 'submitted_motions': Motion.objects.filter(submitter=request.user), + 'config_motion_min_supporters': config['motion_min_supporters'], + 'supported_motions': Motion.objects.filter(supporter=request.user)}) + + try: + from openslides.assignment.models import Assignment + except ImportError: + pass + else: + personal_info_context.update({ + 'assignments': Assignment.objects.filter( + assignmentcandidate__person=request.user, + assignmentcandidate__blocked=False)}) + + if personal_info_context: + return Widget( + name='personal_info', + display_name=_('My motions and elections'), + template='account/personal_info_widget.html', + context=personal_info_context, + permission_required=None, + default_column=1) diff --git a/openslides/global_settings.py b/openslides/global_settings.py index 60f6876ae..3473c6a4c 100644 --- a/openslides/global_settings.py +++ b/openslides/global_settings.py @@ -112,6 +112,7 @@ INSTALLED_APPS = ( 'openslides.utils', 'openslides.poll', 'openslides.core', + 'openslides.account', 'openslides.projector', 'openslides.agenda', 'openslides.motion', diff --git a/openslides/participant/views.py b/openslides/participant/views.py index c1988b309..91218742d 100644 --- a/openslides/participant/views.py +++ b/openslides/participant/views.py @@ -43,8 +43,6 @@ from openslides.utils.views import ( RedirectView, SingleObjectMixin, ListView, QuestionMixin, DetailView) from openslides.config.api import config from openslides.projector.projector import Widget -from openslides.motion.models import Motion -from openslides.assignment.models import Assignment from openslides.participant.api import gen_username, gen_password, import_users from openslides.participant.forms import ( UserCreateForm, UserUpdateForm, UsersettingsForm, @@ -472,34 +470,10 @@ def register_tab(request): def get_widgets(request): """ - Returns all widgets of the participant app. This is a user_widget, a - group_widget and a personal_info_widget. + Returns all widgets of the participant app. This is a user_widget + and a group_widget. """ - return [ - #get_personal_info_widget(request), - get_user_widget(request), - get_group_widget(request)] - - -## def get_personal_info_widget(request): - ## """ - ## Provides a widget for personal info. It shows your submitted motions - ## and where you are supporter or candidate. - ## """ - ## personal_info_context = { - ## 'submitted_motions': Motion.objects.filter(submitter=request.user), - ## 'config_motion_min_supporters': config['motion_min_supporters'], - ## 'supported_motions': Motion.objects.filter(motionsupporter=request.user), - ## 'assignments': Assignment.objects.filter( - ## assignmentcandidate__person=request.user, - ## assignmentcandidate__blocked=False)} - ## return Widget( - ## name='personal_info', - ## display_name=_('My motions and elections'), - ## template='participant/personal_info_widget.html', - ## context=personal_info_context, - ## permission_required=None, - ## default_column=1) + return [get_user_widget(request), get_group_widget(request)] def get_user_widget(request): diff --git a/tests/account/__init__.py b/tests/account/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/account/test_widgets.py b/tests/account/test_widgets.py new file mode 100644 index 000000000..45b888942 --- /dev/null +++ b/tests/account/test_widgets.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +""" + Tests for the widgets of openslides.account + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + :copyright: 2011–2013 by OpenSlides team, see AUTHORS. + :license: GNU GPL, see LICENSE for more details. +""" + +from django.test.client import Client + +from openslides.utils.test import TestCase +from openslides.config.api import config +from openslides.participant.models import User + + +class PersonalInfoWidget(TestCase): + """ + Tests the content of the personal info widget. + """ + def import_motion(self): + """ + Helper function to make the module motion optional. + """ + try: + from openslides import motion + except ImportError: + return False + else: + return motion + + def import_assignment(self): + """ + Helper function to make the module assignment optional. + """ + try: + from openslides import assignment + except ImportError: + return False + else: + return assignment + + def setUp(self): + self.user = User.objects.create(username='HansMeiser') + self.user.reset_password('default') + self.client = Client() + self.client.login(username='HansMeiser', password='default') + + def test_widget_appearance(self): + response = self.client.get('/projector/dashboard/') + self.assertContains(response, '

My motions and elections

', status_code=200) + + def test_submitter_list(self): + motion = self.import_motion() + if motion: + motion_1 = motion.models.Motion.objects.create(title='My Motion Title pa8aeNohYai0ahge', text='My Motion Text') + submitter_1 = motion.models.MotionSubmitter.objects.create(motion=motion_1, person=self.user) + response = self.client.get('/projector/dashboard/') + self.assertContains(response, 'I submitted the following motions:', status_code=200) + self.assertContains(response, 'My Motion Title pa8aeNohYai0ahge', status_code=200) + + def test_supporter_list(self): + motion = self.import_motion() + if motion: + motion_1 = motion.models.Motion.objects.create(title='My Motion Title pa8aeNohYai0ahge', text='My Motion Text') + supporter_1 = motion.models.MotionSupporter.objects.create(motion=motion_1, person=self.user) + config['motion_min_supporters'] = 1 + response = self.client.get('/projector/dashboard/') + self.assertContains(response, 'I support the following motions:', status_code=200) + self.assertContains(response, 'My Motion Title pa8aeNohYai0ahge', status_code=200) + + def test_candidate_list(self): + assignment = self.import_assignment() + if assignment: + assignment_1 = assignment.models.Assignment.objects.create(name='Hausmeister ooKoh7roApoo3phe', posts=1) + assignment_1.run(candidate=self.user, person=self.user) + response = self.client.get('/projector/dashboard/') + self.assertContains(response, 'I am candidate for the following elections:', status_code=200) + self.assertContains(response, 'Hausmeister ooKoh7roApoo3phe', status_code=200)