2013-04-02 17:40:57 +02:00
|
|
|
|
#!/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.
|
|
|
|
|
"""
|
|
|
|
|
|
2013-04-24 09:28:58 +02:00
|
|
|
|
from django.contrib.auth.models import AnonymousUser
|
2013-09-25 10:01:01 +02:00
|
|
|
|
from django.utils.translation import ugettext as _
|
2013-04-02 17:40:57 +02:00
|
|
|
|
|
|
|
|
|
from openslides.config.api import config
|
|
|
|
|
from openslides.projector.projector import Widget
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_widgets(request):
|
|
|
|
|
"""
|
2013-05-12 01:46:40 +02:00
|
|
|
|
Returns the widgets of the account app. It is only the personal_info_widget.
|
2013-04-02 17:40:57 +02:00
|
|
|
|
"""
|
2013-04-24 09:28:58 +02:00
|
|
|
|
if not isinstance(request.user, AnonymousUser):
|
|
|
|
|
return [get_personal_info_widget(request)]
|
|
|
|
|
else:
|
|
|
|
|
return []
|
2013-04-02 17:40:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_personal_info_widget(request):
|
|
|
|
|
"""
|
|
|
|
|
Provides a widget for personal info. It shows your submitted and supported
|
2013-05-12 01:46:40 +02:00
|
|
|
|
motions, where you are on the list of speakers and where you are supporter
|
|
|
|
|
or candidate. If one of the modules agenda, motion or assignment does
|
|
|
|
|
not exist, it is not loaded. If all does not exist, the widget disapears.
|
2013-04-02 17:40:57 +02:00
|
|
|
|
"""
|
|
|
|
|
personal_info_context = {}
|
|
|
|
|
|
2013-05-12 01:46:40 +02:00
|
|
|
|
try:
|
|
|
|
|
from openslides.agenda.models import Item
|
|
|
|
|
except ImportError:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
personal_info_context.update({
|
|
|
|
|
'items': Item.objects.filter(
|
|
|
|
|
speaker__person=request.user,
|
|
|
|
|
speaker__begin_time=None)})
|
2013-04-02 17:40:57 +02:00
|
|
|
|
try:
|
|
|
|
|
from openslides.motion.models import Motion
|
|
|
|
|
except ImportError:
|
|
|
|
|
pass
|
|
|
|
|
else:
|
|
|
|
|
personal_info_context.update({
|
2013-05-31 14:00:24 +02:00
|
|
|
|
'submitted_motions': Motion.objects.filter(submitter__person=request.user),
|
2013-04-02 17:40:57 +02:00
|
|
|
|
'config_motion_min_supporters': config['motion_min_supporters'],
|
2013-05-31 14:00:24 +02:00
|
|
|
|
'supported_motions': Motion.objects.filter(supporter__person=request.user)})
|
2013-04-02 17:40:57 +02:00
|
|
|
|
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(
|
2013-06-13 23:38:58 +02:00
|
|
|
|
request,
|
2013-04-02 17:40:57 +02:00
|
|
|
|
name='personal_info',
|
2013-05-12 01:46:40 +02:00
|
|
|
|
display_name=_('My items, motions and elections'),
|
2013-04-02 17:40:57 +02:00
|
|
|
|
template='account/personal_info_widget.html',
|
|
|
|
|
context=personal_info_context,
|
|
|
|
|
permission_required=None,
|
2013-09-07 15:09:37 +02:00
|
|
|
|
default_column=1,
|
|
|
|
|
default_weight=80)
|