Add default sorting of widgets. Fix #493

This commit is contained in:
Norman Jäckel 2013-09-07 15:09:37 +02:00
parent 611c743364
commit a50617676a
8 changed files with 39 additions and 21 deletions

View File

@ -72,4 +72,5 @@ def get_personal_info_widget(request):
template='account/personal_info_widget.html', template='account/personal_info_widget.html',
context=personal_info_context, context=personal_info_context,
permission_required=None, permission_required=None,
default_column=1) default_column=1,
default_weight=80)

View File

@ -593,11 +593,15 @@ def get_widgets(request):
'items': Item.objects.all(), 'items': Item.objects.all(),
'summary': config['presentation_argument'] == 'summary', 'summary': config['presentation_argument'] == 'summary',
'speakers': config['presentation_argument'] == 'show_list_of_speakers'}, 'speakers': config['presentation_argument'] == 'show_list_of_speakers'},
permission_required='projector.can_manage_projector'), permission_required='projector.can_manage_projector',
default_column=1,
default_weight=20),
Widget( Widget(
request, request,
name='append_to_list_of_speakers', name='append_to_list_of_speakers',
display_name=_('List of speakers'), display_name=_('List of speakers'),
template='agenda/speaker_widget.html', template='agenda/speaker_widget.html',
permission_required='agenda.can_be_speaker')] permission_required='agenda.can_be_speaker',
default_column=1,
default_weight=30)]

View File

@ -641,4 +641,6 @@ def get_widgets(request):
display_name=_('Elections'), display_name=_('Elections'),
template='assignment/widget.html', template='assignment/widget.html',
context={'assignments': Assignment.objects.all()}, context={'assignments': Assignment.objects.all()},
permission_required='projector.can_manage_projector')] permission_required='projector.can_manage_projector',
default_column=1,
default_weight=50)]

View File

@ -837,4 +837,6 @@ def get_widgets(request):
display_name=_('Motions'), display_name=_('Motions'),
template='motion/widget.html', template='motion/widget.html',
context={'motions': Motion.objects.all()}, context={'motions': Motion.objects.all()},
permission_required='projector.can_manage_projector')] permission_required='projector.can_manage_projector',
default_column=1,
default_weight=40)]

View File

@ -564,7 +564,8 @@ def get_user_widget(request):
template='participant/user_widget.html', template='participant/user_widget.html',
context={'users': User.objects.all()}, context={'users': User.objects.all()},
permission_required='projector.can_manage_projector', permission_required='projector.can_manage_projector',
default_column=1) default_column=1,
default_weight=60)
def get_group_widget(request): def get_group_widget(request):
@ -579,4 +580,5 @@ def get_group_widget(request):
template='participant/group_widget.html', template='participant/group_widget.html',
context={'groups': Group.objects.all()}, context={'groups': Group.objects.all()},
permission_required='projector.can_manage_projector', permission_required='projector.can_manage_projector',
default_column=1) default_column=1,
default_weight=70)

View File

@ -128,19 +128,21 @@ def get_all_widgets(request, session=False):
The session flag decides whether to return only the widgets which are The session flag decides whether to return only the widgets which are
active, that means that they are mentioned in the session. active, that means that they are mentioned in the session.
""" """
widgets = SortedDict() all_module_widgets = []
session_widgets = request.session.get('widgets', {})
for app in settings.INSTALLED_APPS: for app in settings.INSTALLED_APPS:
try: try:
mod = import_module(app + '.views') mod = import_module(app + '.views')
except ImportError: except ImportError:
continue continue
try: try:
modul_widgets = mod.get_widgets(request) module_widgets = mod.get_widgets(request)
except AttributeError: except AttributeError:
continue continue
all_module_widgets.extend(module_widgets)
for widget in modul_widgets: all_module_widgets.sort(key=lambda widget: widget.default_weight)
session_widgets = request.session.get('widgets', {})
widgets = SortedDict()
for widget in all_module_widgets:
if (widget.permission_required is None or if (widget.permission_required is None or
request.user.has_perm(widget.permission_required)): request.user.has_perm(widget.permission_required)):
if not session or session_widgets.get(widget.get_name(), True): if not session or session_widgets.get(widget.get_name(), True):

View File

@ -116,7 +116,8 @@ class Widget(object):
Class for a Widget for the Projector-Tab. Class for a Widget for the Projector-Tab.
""" """
def __init__(self, request, name, html=None, template=None, context={}, def __init__(self, request, name, html=None, template=None, context={},
permission_required=None, display_name=None, default_column=1): permission_required=None, display_name=None, default_column=1,
default_weight=0):
self.name = name self.name = name
if display_name is None: if display_name is None:
self.display_name = name.capitalize() self.display_name = name.capitalize()
@ -132,9 +133,9 @@ class Widget(object):
context_instance=RequestContext(request)) context_instance=RequestContext(request))
else: else:
raise OpenSlidesError('A Widget must have either a html or a template argument.') raise OpenSlidesError('A Widget must have either a html or a template argument.')
self.permission_required = permission_required self.permission_required = permission_required
self.default_column = default_column self.default_column = default_column
self.default_weight = default_weight
def get_name(self): def get_name(self):
return self.name.lower() return self.name.lower()

View File

@ -383,7 +383,8 @@ def get_widgets(request):
template='projector/welcome_widget.html', template='projector/welcome_widget.html',
context={'welcometext': config['welcome_text']}, context={'welcometext': config['welcome_text']},
permission_required='projector.can_see_dashboard', permission_required='projector.can_see_dashboard',
default_column=1)) default_column=1,
default_weight=10))
# Projector live view widget # Projector live view widget
widgets.append(Widget( widgets.append(Widget(
@ -392,7 +393,8 @@ def get_widgets(request):
display_name=_('Projector live view'), display_name=_('Projector live view'),
template='projector/live_view_widget.html', template='projector/live_view_widget.html',
permission_required='projector.can_see_projector', permission_required='projector.can_see_projector',
default_column=2)) default_column=2,
default_weight=10))
# Overlay widget # Overlay widget
overlays = [] overlays = []
@ -407,6 +409,7 @@ def get_widgets(request):
template='projector/overlay_widget.html', template='projector/overlay_widget.html',
permission_required='projector.can_manage_projector', permission_required='projector.can_manage_projector',
default_column=2, default_column=2,
default_weight=20,
context=context)) context=context))
# Custom slide widget # Custom slide widget
@ -419,6 +422,7 @@ def get_widgets(request):
'slides': ProjectorSlide.objects.all().order_by('weight'), 'slides': ProjectorSlide.objects.all().order_by('weight'),
'welcomepage_is_active': not bool(config["presentation"])}, 'welcomepage_is_active': not bool(config["presentation"])},
permission_required='projector.can_manage_projector', permission_required='projector.can_manage_projector',
default_column=2)) default_column=2,
default_weight=30))
return widgets return widgets