OpenSlides/openslides/utils/personal_info.py

52 lines
1.7 KiB
Python
Raw Normal View History

from django.dispatch import Signal
from .dispatch import SignalConnectMetaClass
class PersonalInfo(object, metaclass=SignalConnectMetaClass):
"""
2014-05-06 13:21:46 +02:00
Base class for a personal info collection for the personal info widget
on the dashboard.
Every app which wants to add info has to create a class subclassing
2014-05-06 13:21:46 +02:00
from this base class. For the content the headline attribute, the
default_weight attribute and the get_queryset method have to be set.
The metaclass (SignalConnectMetaClass) does the rest of
2014-05-06 13:21:46 +02:00
the magic.
"""
signal = Signal(providing_args=['request'])
headline = None
default_weight = 0
def __init__(self, sender, request, **kwargs):
"""
2014-05-06 13:21:46 +02:00
Initializes the personal info instance. This is done when the
signal is sent.
Only the required request argument is used. Because of Django's signal
API, we have to take also a sender argument and wildcard keyword
arguments. But they are not used here.
"""
self.request = request
@classmethod
def get_dispatch_uid(cls):
"""
2014-05-06 13:21:46 +02:00
Returns the classname as a unique string for each class. Returns
None for the base class so it will not be connected to the signal.
"""
if not cls.__name__ == 'PersonalInfo':
return cls.__name__
def get_queryset(self):
"""
Returns a queryset of objects for the personal info widget.
"""
raise NotImplementedError('Your class %s has to define a get_queryset method.' % self.__class__)
def is_active(self):
"""
Returns True if the infoblock is shown in the widget.
"""
return self.get_queryset() is not None