Merge remote-tracking branch 'emanuel/master'

This commit is contained in:
Oskar Hahn 2012-09-20 10:05:00 +02:00
commit 3aefd252ff
11 changed files with 338 additions and 285 deletions

View File

@ -164,7 +164,10 @@ class Application(models.Model, SlideMixin):
yield object.person yield object.person
def is_supporter(self, person): def is_supporter(self, person):
try:
return self.applicationsupporter_set.filter(person=person).exists() return self.applicationsupporter_set.filter(person=person).exists()
except AttributeError:
return False
@property @property
def enough_supporters(self): def enough_supporters(self):
@ -534,6 +537,7 @@ class Application(models.Model, SlideMixin):
('can_support_application', ugettext_noop("Can support motions")), ('can_support_application', ugettext_noop("Can support motions")),
('can_manage_application', ugettext_noop("Can manage motions")), ('can_manage_application', ugettext_noop("Can manage motions")),
) )
ordering = ('number',)
class AVersion(models.Model): class AVersion(models.Model):

View File

@ -49,7 +49,7 @@
<td>{% if application.number %}{{ application.number }}{% else %}-{% endif %}</td> <td>{% if application.number %}{{ application.number }}{% else %}-{% endif %}</td>
<td><a href="{% url application_view application.id %}">{{ application.public_version.title }}</a></td> <td><a href="{% url application_view application.id %}">{{ application.public_version.title }}</a></td>
{% if min_supporters > 0 %} {% if min_supporters > 0 %}
<td>{{ application.supporter.count }}</td> <td>{{ application.count_supporters }}</td>
{% endif %} {% endif %}
<td>{% if application.status != "pub" %} <td>{% if application.status != "pub" %}
{{ application.get_status_display }}<br> {{ application.get_status_display }}<br>

View File

@ -102,8 +102,6 @@ def overview(request):
if sort.startswith('aversion_'): if sort.startswith('aversion_'):
# limit result to last version of an application # limit result to last version of an application
query = query.filter(aversion__id__in=[x.last_version.id for x in Application.objects.all()]) query = query.filter(aversion__id__in=[x.last_version.id for x in Application.objects.all()])
else:
query = query.order_by('number')
if 'reverse' in sortfilter: if 'reverse' in sortfilter:
query = query.reverse() query = query.reverse()
@ -468,7 +466,7 @@ class ApplicationDelete(DeleteView):
elif self.object: elif self.object:
if not 'delete' in self.object.get_allowed_actions(user=request.user): if not 'delete' in self.object.get_allowed_actions(user=request.user):
messages.error(request, _("You can not delete motion <b>%s</b>.") % self.object) messages.error(request, _("You can not delete motion <b>%s</b>.") % self.object)
else: elif self.get_answer() == 'yes':
title = self.object.title title = self.object.title
self.object.delete(force=True) self.object.delete(force=True)
messages.success(request, _("Motion <b>%s</b> was successfully deleted.") % title) messages.success(request, _("Motion <b>%s</b> was successfully deleted.") % title)
@ -681,7 +679,7 @@ class ApplicationPDF(PDFView):
if preamble: if preamble:
story.append(Paragraph("%s" % preamble.replace('\r\n','<br/>'), stylesheet['Paragraph'])) story.append(Paragraph("%s" % preamble.replace('\r\n','<br/>'), stylesheet['Paragraph']))
story.append(Spacer(0,0.75*cm)) story.append(Spacer(0,0.75*cm))
applications = Application.objects.order_by('number') applications = Application.objects.all()
if not applications: # No applications existing if not applications: # No applications existing
story.append(Paragraph(_("No motions available."), stylesheet['Heading3'])) story.append(Paragraph(_("No motions available."), stylesheet['Heading3']))
else: # Print all Applications else: # Print all Applications
@ -835,9 +833,9 @@ class ApplicationPollPDF(PDFView):
# set number of ballot papers # set number of ballot papers
if ballot_papers_selection == "NUMBER_OF_DELEGATES": if ballot_papers_selection == "NUMBER_OF_DELEGATES":
number = User.objects.filter(profile__type__iexact="delegate").count() number = User.objects.filter(type__iexact="delegate").count()
elif ballot_papers_selection == "NUMBER_OF_ALL_PARTICIPANTS": elif ballot_papers_selection == "NUMBER_OF_ALL_PARTICIPANTS":
number = int(Profile.objects.count()) number = int(User.objects.count())
else: # ballot_papers_selection == "CUSTOM_NUMBER" else: # ballot_papers_selection == "CUSTOM_NUMBER"
number = int(ballot_papers_number) number = int(ballot_papers_number)
number = max(1, number) number = max(1, number)
@ -899,5 +897,5 @@ def get_widgets(request):
Widget( Widget(
name='applications', name='applications',
template='application/widget.html', template='application/widget.html',
context={'applications': Application.objects.all().order_by('number')}, context={'applications': Application.objects.all()},
permission_required='application.can_manage_application')] permission_required='application.can_manage_application')]

View File

@ -122,8 +122,11 @@ class Assignment(models.Model, SlideMixin):
""" """
return True, if person is a candidate. return True, if person is a candidate.
""" """
try:
return self.assignment_candidats.filter(person=person) \ return self.assignment_candidats.filter(person=person) \
.exclude(blocked=True).exists() .exclude(blocked=True).exists()
except AttributeError:
return False
def is_blocked(self, person): def is_blocked(self, person):
""" """
@ -253,6 +256,7 @@ class Assignment(models.Model, SlideMixin):
('can_nominate_self', ugettext_noop("Can nominate themselves")), ('can_nominate_self', ugettext_noop("Can nominate themselves")),
('can_manage_assignment', ugettext_noop("Can manage assignment")), ('can_manage_assignment', ugettext_noop("Can manage assignment")),
) )
ordering = ('name',)
register_slidemodel(Assignment) register_slidemodel(Assignment)

View File

@ -63,8 +63,8 @@
{% for candidate, poll_list in vote_results.items %} {% for candidate, poll_list in vote_results.items %}
<tr class="{% cycle 'odd' '' %}"> <tr class="{% cycle 'odd' '' %}">
<td class="candidate{% if candidate in assignment.elected.all %} elected{% endif %}"> <td class="candidate{% if candidate in assignment.elected %} elected{% endif %}">
{% if candidate in assignment.elected.all %} {% if candidate in assignment.elected %}
<a class="elected"> <a class="elected">
<img src="{% static 'images/icons/voting-yes.png' %}" title="{% trans 'Candidate is elected' %}"> <img src="{% static 'images/icons/voting-yes.png' %}" title="{% trans 'Candidate is elected' %}">
</a> </a>
@ -72,8 +72,8 @@
{{ candidate }} {{ candidate }}
</td> </td>
{% for vote in poll_list %} {% for vote in poll_list %}
<td style="white-space:nowrap;"{% if candidate in assignment.elected.all %} class="elected"{% endif %}> <td style="white-space:nowrap;"{% if candidate in assignment.elected %} class="elected"{% endif %}>
{% if not assignment_publish_winner_results_only or candidate in assignment.elected.all %} {% if not assignment_publish_winner_results_only or candidate in assignment.elected %}
{% if 'Yes' in vote and 'No' in vote and 'Abstain' in vote %} {% if 'Yes' in vote and 'No' in vote and 'Abstain' in vote %}
<img src="{% static 'images/icons/voting-yes.png' %}" title="{% trans 'Yes' %}"> {{ vote.Yes }}<br> <img src="{% static 'images/icons/voting-yes.png' %}" title="{% trans 'Yes' %}"> {{ vote.Yes }}<br>
<img src="{% static 'images/icons/voting-no.png' %}" title="{% trans 'No' %}"> {{ vote.No }}<br> <img src="{% static 'images/icons/voting-no.png' %}" title="{% trans 'No' %}"> {{ vote.No }}<br>

View File

@ -59,7 +59,7 @@ def get_overview(request):
if sort in ['name','status']: if sort in ['name','status']:
query = query.order_by(sort) query = query.order_by(sort)
except KeyError: except KeyError:
query = query.order_by('name') pass
if 'reverse' in request.GET: if 'reverse' in request.GET:
query = query.reverse() query = query.reverse()
@ -353,7 +353,7 @@ class AssignmentPDF(PDFView):
story.append(Paragraph("%s" % preamble.replace('\r\n', '<br/>'), story.append(Paragraph("%s" % preamble.replace('\r\n', '<br/>'),
stylesheet['Paragraph'])) stylesheet['Paragraph']))
story.append(Spacer(0, 0.75 * cm)) story.append(Spacer(0, 0.75 * cm))
assignments = Assignment.objects.order_by('name') assignments = Assignment.objects.all()
if not assignments: # No assignments existing if not assignments: # No assignments existing
story.append(Paragraph(_("No assignments available."), story.append(Paragraph(_("No assignments available."),
stylesheet['Heading3'])) stylesheet['Heading3']))
@ -554,9 +554,9 @@ class AssignmentPollPDF(PDFView):
# set number of ballot papers # set number of ballot papers
if ballot_papers_selection == "NUMBER_OF_DELEGATES": if ballot_papers_selection == "NUMBER_OF_DELEGATES":
number = User.objects.filter(profile__type__iexact="delegate").count() number = User.objects.filter(type__iexact="delegate").count()
elif ballot_papers_selection == "NUMBER_OF_ALL_PARTICIPANTS": elif ballot_papers_selection == "NUMBER_OF_ALL_PARTICIPANTS":
number = int(Profile.objects.count()) number = int(User.objects.count())
else: # ballot_papers_selection == "CUSTOM_NUMBER" else: # ballot_papers_selection == "CUSTOM_NUMBER"
number = int(ballot_papers_number) number = int(ballot_papers_number)
number = max(1, number) number = max(1, number)
@ -567,8 +567,8 @@ class AssignmentPollPDF(PDFView):
candidate = option.candidate candidate = option.candidate
cell.append(Paragraph(candidate.user.get_full_name(), cell.append(Paragraph(candidate.user.get_full_name(),
stylesheet['Ballot_option_name'])) stylesheet['Ballot_option_name']))
if candidate.name_surfix: if candidate.name_suffix:
cell.append(Paragraph("(%s)" % candidate.name_surfix, cell.append(Paragraph("(%s)" % candidate.name_suffix,
stylesheet['Ballot_option_group'])) stylesheet['Ballot_option_group']))
else: else:
cell.append(Paragraph("&nbsp;", cell.append(Paragraph("&nbsp;",
@ -675,5 +675,5 @@ def get_widgets(request):
Widget( Widget(
name=_('Assignments'), name=_('Assignments'),
template='assignment/widget.html', template='assignment/widget.html',
context={'assignments': Assignment.objects.all().order_by('name')}, context={'assignments': Assignment.objects.all()},
permission_required='assignment.can_manage_assignment')] permission_required='assignment.can_manage_assignment')]

File diff suppressed because it is too large Load Diff

View File

@ -113,3 +113,6 @@ class ConfigForm(forms.Form, CssClassMixin):
required=False, required=False,
label=_("Welcome text"), label=_("Welcome text"),
help_text=_("Printed in PDF of first time passwords only.")) help_text=_("Printed in PDF of first time passwords only."))
participant_sort_users_by_first_name = forms.BooleanField(
required=False,
label=_("Sort users by first name"))

View File

@ -19,6 +19,7 @@ from django.utils.translation import ugettext_lazy as _, ugettext_noop
from openslides.utils.person import PersonMixin from openslides.utils.person import PersonMixin
from openslides.utils.person.signals import receive_persons from openslides.utils.person.signals import receive_persons
from openslides.config.models import config
from openslides.config.signals import default_config_value from openslides.config.signals import default_config_value
@ -28,7 +29,7 @@ class User(DjangoUser, PersonMixin):
('male', _('Male')), ('male', _('Male')),
('female', _('Female')), ('female', _('Female')),
) )
TYPE_CHOICE = ( TYPE_CHOICES = (
('delegate', _('Delegate')), ('delegate', _('Delegate')),
('observer', _('Observer')), ('observer', _('Observer')),
('staff', _('Staff')), ('staff', _('Staff')),
@ -43,7 +44,7 @@ class User(DjangoUser, PersonMixin):
max_length=50, choices=GENDER_CHOICES, blank=True, max_length=50, choices=GENDER_CHOICES, blank=True,
verbose_name=_("Gender"), help_text=_('Only for filter the userlist.')) verbose_name=_("Gender"), help_text=_('Only for filter the userlist.'))
type = models.CharField( type = models.CharField(
max_length=100, choices=TYPE_CHOICE, blank=True, max_length=100, choices=TYPE_CHOICES, blank=True,
verbose_name=_("Typ"), help_text=_('Only for filter the userlist.')) verbose_name=_("Typ"), help_text=_('Only for filter the userlist.'))
committee = models.CharField( committee = models.CharField(
max_length=100, null=True, blank=True, verbose_name=_("Committee"), max_length=100, null=True, blank=True, verbose_name=_("Committee"),
@ -99,6 +100,7 @@ class User(DjangoUser, PersonMixin):
('can_manage_participant', ('can_manage_participant',
ugettext_noop("Can manage participant")), ugettext_noop("Can manage participant")),
) )
ordering = ('last_name',)
class Group(DjangoGroup, PersonMixin): class Group(DjangoGroup, PersonMixin):
@ -125,11 +127,21 @@ class Group(DjangoGroup, PersonMixin):
def __unicode__(self): def __unicode__(self):
return unicode(self.name) return unicode(self.name)
class Meta:
ordering = ('name',)
class UsersConnector(object):
class UsersAndGroupsToPersons(object):
"""
Object to send all Users and Groups or a special User or Group to
the Person-API via receice_persons()
"""
def __init__(self, person_prefix_filter=None, id_filter=None): def __init__(self, person_prefix_filter=None, id_filter=None):
self.person_prefix_filter = person_prefix_filter self.person_prefix_filter = person_prefix_filter
self.id_filter = id_filter self.id_filter = id_filter
if config['participant_sort_users_by_first_name']:
self.users = User.objects.all().order_by('first_name')
else:
self.users = User.objects.all() self.users = User.objects.all()
self.groups = Group.objects.filter(group_as_person=True) self.groups = Group.objects.filter(group_as_person=True)
@ -159,7 +171,10 @@ class UsersConnector(object):
@receiver(receive_persons, dispatch_uid="participant") @receiver(receive_persons, dispatch_uid="participant")
def receive_persons(sender, **kwargs): def receive_persons(sender, **kwargs):
return UsersConnector(person_prefix_filter=kwargs['person_prefix_filter'], """
Answers to the Person-API
"""
return UsersAndGroupsToPersons(person_prefix_filter=kwargs['person_prefix_filter'],
id_filter=kwargs['id_filter']) id_filter=kwargs['id_filter'])
@ -172,6 +187,7 @@ def default_config(sender, key, **kwargs):
return { return {
'participant_pdf_system_url': 'http://example.com:8000', 'participant_pdf_system_url': 'http://example.com:8000',
'participant_pdf_welcometext': _('Welcome to OpenSlides!'), 'participant_pdf_welcometext': _('Welcome to OpenSlides!'),
'participant_sort_users_by_first_name': False,
}.get(key) }.get(key)

View File

@ -53,7 +53,7 @@ from openslides.participant.models import User, Group
class Overview(ListView): class Overview(ListView):
""" """
Show all participants. Show all participants (users).
""" """
permission_required = 'participant.can_see_participant' permission_required = 'participant.can_see_participant'
template_name = 'participant/overview.html' template_name = 'participant/overview.html'
@ -96,7 +96,8 @@ class Overview(ListView):
query = query.order_by( query = query.order_by(
'%s' % sortfilter['sort'][0]) '%s' % sortfilter['sort'][0])
else: else:
query = query.order_by('last_name') if config['participant_sort_users_by_first_name']:
query = query.order_by('first_name')
if 'reverse' in sortfilter: if 'reverse' in sortfilter:
query = query.reverse() query = query.reverse()
@ -412,13 +413,16 @@ class Config(FormView):
def get_initial(self): def get_initial(self):
return { return {
'participant_pdf_system_url': config['participant_pdf_system_url'], 'participant_pdf_system_url': config['participant_pdf_system_url'],
'participant_pdf_welcometext': config['participant_pdf_welcometext']} 'participant_pdf_welcometext': config['participant_pdf_welcometext'],
'participant_sort_users_by_first_name': config['participant_sort_users_by_first_name']}
def form_valid(self, form): def form_valid(self, form):
config['participant_pdf_system_url'] = ( config['participant_pdf_system_url'] = (
form.cleaned_data['participant_pdf_system_url']) form.cleaned_data['participant_pdf_system_url'])
config['participant_pdf_welcometext'] = ( config['participant_pdf_welcometext'] = (
form.cleaned_data['participant_pdf_welcometext']) form.cleaned_data['participant_pdf_welcometext'])
config['participant_sort_users_by_first_name'] = (
form.cleaned_data['participant_sort_users_by_first_name'])
messages.success( messages.success(
self.request, self.request,
_('Participants settings successfully saved.')) _('Participants settings successfully saved.'))