2013-12-03 01:50:10 +01:00
|
|
|
from django.dispatch import Signal
|
|
|
|
|
|
|
|
from .dispatch import SignalConnectMetaClass
|
|
|
|
|
|
|
|
|
2014-08-16 09:25:18 +02:00
|
|
|
class PersonalInfo(object, metaclass=SignalConnectMetaClass):
|
2013-12-03 01:50:10 +01:00
|
|
|
"""
|
2014-05-06 13:21:46 +02:00
|
|
|
Base class for a personal info collection for the personal info widget
|
|
|
|
on the dashboard.
|
2013-12-03 01:50:10 +01:00
|
|
|
|
|
|
|
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.
|
2014-08-16 09:25:18 +02:00
|
|
|
The metaclass (SignalConnectMetaClass) does the rest of
|
2014-05-06 13:21:46 +02:00
|
|
|
the magic.
|
2013-12-03 01:50:10 +01:00
|
|
|
"""
|
|
|
|
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.
|
2013-12-03 01:50:10 +01:00
|
|
|
|
|
|
|
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.
|
2013-12-03 01:50:10 +01:00
|
|
|
"""
|
|
|
|
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
|