Merge pull request #18 from normanjaeckel/Default_Sorting

Default sorting using Meta Class option and new config var
This commit is contained in:
Oskar Hahn 2012-09-15 00:23:50 -07:00
commit 5aa2bc650f
7 changed files with 38 additions and 15 deletions

View File

@ -534,6 +534,7 @@ class Application(models.Model, SlideMixin):
('can_support_application', ugettext_noop("Can support motions")),
('can_manage_application', ugettext_noop("Can manage motions")),
)
ordering = ('number',)
class AVersion(models.Model):

View File

@ -102,8 +102,6 @@ def overview(request):
if sort.startswith('aversion_'):
# limit result to last version of an application
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:
query = query.reverse()
@ -681,7 +679,7 @@ class ApplicationPDF(PDFView):
if preamble:
story.append(Paragraph("%s" % preamble.replace('\r\n','<br/>'), stylesheet['Paragraph']))
story.append(Spacer(0,0.75*cm))
applications = Application.objects.order_by('number')
applications = Application.objects.all()
if not applications: # No applications existing
story.append(Paragraph(_("No motions available."), stylesheet['Heading3']))
else: # Print all Applications
@ -899,5 +897,5 @@ def get_widgets(request):
Widget(
name='applications',
template='application/widget.html',
context={'applications': Application.objects.all().order_by('number')},
context={'applications': Application.objects.all()},
permission_required='application.can_manage_application')]

View File

@ -253,6 +253,7 @@ class Assignment(models.Model, SlideMixin):
('can_nominate_self', ugettext_noop("Can nominate themselves")),
('can_manage_assignment', ugettext_noop("Can manage assignment")),
)
ordering = ('name',)
register_slidemodel(Assignment)

View File

@ -59,7 +59,7 @@ def get_overview(request):
if sort in ['name','status']:
query = query.order_by(sort)
except KeyError:
query = query.order_by('name')
pass
if 'reverse' in request.GET:
query = query.reverse()
@ -353,7 +353,7 @@ class AssignmentPDF(PDFView):
story.append(Paragraph("%s" % preamble.replace('\r\n', '<br/>'),
stylesheet['Paragraph']))
story.append(Spacer(0, 0.75 * cm))
assignments = Assignment.objects.order_by('name')
assignments = Assignment.objects.all()
if not assignments: # No assignments existing
story.append(Paragraph(_("No assignments available."),
stylesheet['Heading3']))
@ -675,5 +675,5 @@ def get_widgets(request):
Widget(
name=_('Assignments'),
template='assignment/widget.html',
context={'assignments': Assignment.objects.all().order_by('name')},
context={'assignments': Assignment.objects.all()},
permission_required='assignment.can_manage_assignment')]

View File

@ -113,3 +113,6 @@ class ConfigForm(forms.Form, CssClassMixin):
required=False,
label=_("Welcome text"),
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.signals import receive_persons
from openslides.config.models import config
from openslides.config.signals import default_config_value
@ -28,7 +29,7 @@ class User(DjangoUser, PersonMixin):
('male', _('Male')),
('female', _('Female')),
)
TYPE_CHOICE = (
TYPE_CHOICES = (
('delegate', _('Delegate')),
('observer', _('Observer')),
('staff', _('Staff')),
@ -43,7 +44,7 @@ class User(DjangoUser, PersonMixin):
max_length=50, choices=GENDER_CHOICES, blank=True,
verbose_name=_("Gender"), help_text=_('Only for filter the userlist.'))
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.'))
committee = models.CharField(
max_length=100, null=True, blank=True, verbose_name=_("Committee"),
@ -99,6 +100,7 @@ class User(DjangoUser, PersonMixin):
('can_manage_participant',
ugettext_noop("Can manage participant")),
)
ordering = ('last_name',)
class Group(DjangoGroup, PersonMixin):
@ -125,12 +127,22 @@ class Group(DjangoGroup, PersonMixin):
def __unicode__(self):
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):
self.person_prefix_filter = person_prefix_filter
self.id_filter = id_filter
self.users = User.objects.all()
if config['participant_sort_users_by_first_name']:
self.users = User.objects.all().order_by('first_name')
else:
self.users = User.objects.all()
self.groups = Group.objects.filter(group_as_person=True)
def __iter__(self):
@ -159,7 +171,10 @@ class UsersConnector(object):
@receiver(receive_persons, dispatch_uid="participant")
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'])
@ -172,6 +187,7 @@ def default_config(sender, key, **kwargs):
return {
'participant_pdf_system_url': 'http://example.com:8000',
'participant_pdf_welcometext': _('Welcome to OpenSlides!'),
'participant_sort_users_by_first_name': False,
}.get(key)

View File

@ -53,7 +53,7 @@ from openslides.participant.models import User, Group
class Overview(ListView):
"""
Show all participants.
Show all participants (users).
"""
permission_required = 'participant.can_see_participant'
template_name = 'participant/overview.html'
@ -96,7 +96,8 @@ class Overview(ListView):
query = query.order_by(
'%s' % sortfilter['sort'][0])
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:
query = query.reverse()
@ -412,13 +413,16 @@ class Config(FormView):
def get_initial(self):
return {
'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):
config['participant_pdf_system_url'] = (
form.cleaned_data['participant_pdf_system_url'])
config['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(
self.request,
_('Participants settings successfully saved.'))