Move personal info widget to a new app: account.

This commit is contained in:
Norman Jäckel 2013-04-02 17:40:57 +02:00
parent 07535bd639
commit b310d6077e
7 changed files with 159 additions and 42 deletions

View File

View File

@ -2,48 +2,48 @@
{% load tags %}
<ul style="line-height: 180%">
{% trans "I submitted the following motions:" %}
{% trans 'I submitted the following motions:' %}
{% for motion in submitted_motions %}
<li>
<a href="{% model_url motion 'view' %}">{{ motion.public_version.title }}</a>
({% trans "motion" %}
<a href="{% model_url motion %}">{{ motion }}</a>
({% trans 'motion' %}
{% if motion.identifier %}
{{ motion.identifier }})
{% else %}
<i>[{% trans "no number" %}]</i>)
<i>[{% trans 'no number' %}]</i>)
{% endif %}
</li>
{% empty %}
<li><i>{% trans "None" %}</i></li>
<li><i>{% trans 'None' %}</i></li>
{% endfor %}
</ul>
{% if config_motion_min_supporters %}
<hr />
<ul style="line-height: 180%">
{% trans "I support the following motions:" %}
{% trans 'I support the following motions:' %}
{% for motion in supported_motions %}
<li>
<a href="{% model_url motion 'view' %}">{{ motion.public_version.title }}</a>
({% trans "motion" %}
<a href="{% model_url motion %}">{{ motion }}</a>
({% trans 'motion' %}
{% if motion.identifier %}
{{ motion.identifier }})
{% else %}
<i>[{% trans "no number" %}]</i>)
<i>[{% trans 'no number' %}]</i>)
{% endif %}
</li>
{% empty %}
<li><i>{% trans "None" %}</i></li>
<li><i>{% trans 'None' %}</i></li>
{% endfor %}
</ul>
{% endif %}
<hr />
<ul style="line-height: 180%">
{% trans "I am candidate for the following elections:" %}
{% trans 'I am candidate for the following elections:' %}
{% for assignment in assignments %}
<li><a href="{% model_url assignment 'view' %}">{{ assignment }}</a></li>
<li><a href="{% model_url assignment %}">{{ assignment }}</a></li>
{% empty %}
<li><i>{% trans "None" %}</i></li>
<li><i>{% trans 'None' %}</i></li>
{% endfor %}
</ul>

View File

@ -0,0 +1,62 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
openslides.account.views
~~~~~~~~~~~~~~~~~~~~~~~~
Views for the account app.
:copyright: 20112013 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)

View File

@ -112,6 +112,7 @@ INSTALLED_APPS = (
'openslides.utils',
'openslides.poll',
'openslides.core',
'openslides.account',
'openslides.projector',
'openslides.agenda',
'openslides.motion',

View File

@ -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):

View File

View File

@ -0,0 +1,80 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Tests for the widgets of openslides.account
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:copyright: 20112013 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, '<h3>My motions and elections</h3>', 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)