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',
context=personal_info_context,
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(),
'summary': config['presentation_argument'] == 'summary',
'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(
request,
name='append_to_list_of_speakers',
display_name=_('List of speakers'),
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'),
template='assignment/widget.html',
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'),
template='motion/widget.html',
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',
context={'users': User.objects.all()},
permission_required='projector.can_manage_projector',
default_column=1)
default_column=1,
default_weight=60)
def get_group_widget(request):
@ -579,4 +580,5 @@ def get_group_widget(request):
template='participant/group_widget.html',
context={'groups': Group.objects.all()},
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
active, that means that they are mentioned in the session.
"""
widgets = SortedDict()
session_widgets = request.session.get('widgets', {})
all_module_widgets = []
for app in settings.INSTALLED_APPS:
try:
mod = import_module(app + '.views')
except ImportError:
continue
try:
modul_widgets = mod.get_widgets(request)
module_widgets = mod.get_widgets(request)
except AttributeError:
continue
for widget in modul_widgets:
all_module_widgets.extend(module_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
request.user.has_perm(widget.permission_required)):
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.
"""
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
if display_name is None:
self.display_name = name.capitalize()
@ -132,9 +133,9 @@ class Widget(object):
context_instance=RequestContext(request))
else:
raise OpenSlidesError('A Widget must have either a html or a template argument.')
self.permission_required = permission_required
self.default_column = default_column
self.default_weight = default_weight
def get_name(self):
return self.name.lower()

View File

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