Merge pull request #2016 from normanjaeckel/GetContext
Rename and refactor some ProjectorElement methods. Fixed #1631.
This commit is contained in:
commit
872d73b5cf
@ -18,7 +18,7 @@ class ItemListSlide(ProjectorElement):
|
|||||||
"""
|
"""
|
||||||
name = 'agenda/item-list'
|
name = 'agenda/item-list'
|
||||||
|
|
||||||
def get_context(self):
|
def check_data(self):
|
||||||
pk = self.config_entry.get('id')
|
pk = self.config_entry.get('id')
|
||||||
if pk is not None:
|
if pk is not None:
|
||||||
# Children slide.
|
# Children slide.
|
||||||
@ -48,7 +48,7 @@ class ListOfSpeakersSlide(ProjectorElement):
|
|||||||
"""
|
"""
|
||||||
name = 'agenda/list-of-speakers'
|
name = 'agenda/list-of-speakers'
|
||||||
|
|
||||||
def get_context(self):
|
def check_data(self):
|
||||||
pk = self.config_entry.get('id')
|
pk = self.config_entry.get('id')
|
||||||
if pk is None:
|
if pk is None:
|
||||||
raise ProjectorException('Id must not be None.')
|
raise ProjectorException('Id must not be None.')
|
||||||
|
@ -14,7 +14,7 @@ class AssignmentSlide(ProjectorElement):
|
|||||||
"""
|
"""
|
||||||
name = 'assignments/assignment'
|
name = 'assignments/assignment'
|
||||||
|
|
||||||
def get_context(self):
|
def check_data(self):
|
||||||
pk = self.config_entry.get('id')
|
pk = self.config_entry.get('id')
|
||||||
if pk is not None:
|
if pk is not None:
|
||||||
# Detail slide.
|
# Detail slide.
|
||||||
|
@ -70,8 +70,8 @@ class Projector(RESTModelMixin, models.Model):
|
|||||||
@property
|
@property
|
||||||
def elements(self):
|
def elements(self):
|
||||||
"""
|
"""
|
||||||
Retrieve all projector elements given in the config
|
Retrieve all projector elements given in the config field. For
|
||||||
field. For every element the method get_data() is called and its
|
every element the method check_and_update_data() is called and its
|
||||||
result is also used.
|
result is also used.
|
||||||
"""
|
"""
|
||||||
# Get all elements from all apps.
|
# Get all elements from all apps.
|
||||||
@ -90,7 +90,7 @@ class Projector(RESTModelMixin, models.Model):
|
|||||||
result[key]['error'] = 'Projector element does not exist.'
|
result[key]['error'] = 'Projector element does not exist.'
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
result[key].update(element.get_data(
|
result[key].update(element.check_and_update_data(
|
||||||
projector_object=self,
|
projector_object=self,
|
||||||
config_entry=value))
|
config_entry=value))
|
||||||
except ProjectorException as e:
|
except ProjectorException as e:
|
||||||
|
@ -14,7 +14,7 @@ class CustomSlideSlide(ProjectorElement):
|
|||||||
"""
|
"""
|
||||||
name = 'core/customslide'
|
name = 'core/customslide'
|
||||||
|
|
||||||
def get_context(self):
|
def check_data(self):
|
||||||
if not CustomSlide.objects.filter(pk=self.config_entry.get('id')).exists():
|
if not CustomSlide.objects.filter(pk=self.config_entry.get('id')).exists():
|
||||||
raise ProjectorException('Custom slide does not exist.')
|
raise ProjectorException('Custom slide does not exist.')
|
||||||
|
|
||||||
@ -74,7 +74,7 @@ class Countdown(ProjectorElement):
|
|||||||
"""
|
"""
|
||||||
name = 'core/countdown'
|
name = 'core/countdown'
|
||||||
|
|
||||||
def get_context(self):
|
def check_data(self):
|
||||||
self.validate_config(self.config_entry)
|
self.validate_config(self.config_entry)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -136,6 +136,6 @@ class Message(ProjectorElement):
|
|||||||
"""
|
"""
|
||||||
name = 'core/message'
|
name = 'core/message'
|
||||||
|
|
||||||
def get_context(self):
|
def check_data(self):
|
||||||
if self.config_entry.get('message') is None:
|
if self.config_entry.get('message') is None:
|
||||||
raise ProjectorException('No message given.')
|
raise ProjectorException('No message given.')
|
||||||
|
@ -11,7 +11,7 @@ class MediafileSlide(ProjectorElement):
|
|||||||
"""
|
"""
|
||||||
name = 'mediafiles/mediafile'
|
name = 'mediafiles/mediafile'
|
||||||
|
|
||||||
def get_context(self):
|
def check_data(self):
|
||||||
try:
|
try:
|
||||||
Mediafile.objects.get(pk=self.config_entry.get('id'))
|
Mediafile.objects.get(pk=self.config_entry.get('id'))
|
||||||
except Mediafile.DoesNotExist:
|
except Mediafile.DoesNotExist:
|
||||||
|
@ -14,7 +14,7 @@ class MotionSlide(ProjectorElement):
|
|||||||
"""
|
"""
|
||||||
name = 'motions/motion'
|
name = 'motions/motion'
|
||||||
|
|
||||||
def get_context(self):
|
def check_data(self):
|
||||||
pk = self.config_entry.get('id')
|
pk = self.config_entry.get('id')
|
||||||
if pk is not None:
|
if pk is not None:
|
||||||
# Detail slide.
|
# Detail slide.
|
||||||
|
@ -10,7 +10,7 @@ class UserSlide(ProjectorElement):
|
|||||||
"""
|
"""
|
||||||
name = 'users/user'
|
name = 'users/user'
|
||||||
|
|
||||||
def get_context(self):
|
def check_data(self):
|
||||||
if not User.objects.filter(pk=self.config_entry.get('id')).exists():
|
if not User.objects.filter(pk=self.config_entry.get('id')).exists():
|
||||||
raise ProjectorException('User does not exist.')
|
raise ProjectorException('User does not exist.')
|
||||||
|
|
||||||
|
@ -34,23 +34,37 @@ class ProjectorElement(object, metaclass=SignalConnectMetaClass):
|
|||||||
if not cls.__name__ == 'ProjectorElement':
|
if not cls.__name__ == 'ProjectorElement':
|
||||||
return cls.__name__
|
return cls.__name__
|
||||||
|
|
||||||
def get_data(self, projector_object, config_entry):
|
def check_and_update_data(self, projector_object, config_entry):
|
||||||
"""
|
"""
|
||||||
Returns all data to be sent to the client. The projector object and
|
Checks projector element data via self.check_data() and updates
|
||||||
the config entry have to be given.
|
them via self.update_data(). The projector object and the config
|
||||||
|
entry have to be given.
|
||||||
"""
|
"""
|
||||||
self.projector_object = projector_object
|
self.projector_object = projector_object
|
||||||
self.config_entry = config_entry
|
self.config_entry = config_entry
|
||||||
assert self.config_entry.get('name') == self.name, (
|
assert self.config_entry.get('name') == self.name, (
|
||||||
'To get data of a projector element, the correct config entry has to be given.')
|
'To get data of a projector element, the correct config entry has to be given.')
|
||||||
return {
|
self.check_data()
|
||||||
'context': self.get_context()}
|
return self.update_data() or {}
|
||||||
|
|
||||||
def get_context(self):
|
def check_data(self):
|
||||||
"""
|
"""
|
||||||
Returns the context of the projector element.
|
Method can be overridden to validate projector element data. This
|
||||||
|
may raise ProjectorException in case of an error.
|
||||||
|
|
||||||
|
Default: Does nothing.
|
||||||
"""
|
"""
|
||||||
return None
|
pass
|
||||||
|
|
||||||
|
def update_data(self):
|
||||||
|
"""
|
||||||
|
Method can be overridden to update the projector element data
|
||||||
|
output. This should return a dictonary. Use this for server
|
||||||
|
calculated data which have to be forwared to the client.
|
||||||
|
|
||||||
|
Default: Does nothing.
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
def get_requirements(self, config_entry):
|
def get_requirements(self, config_entry):
|
||||||
"""
|
"""
|
||||||
|
@ -34,8 +34,7 @@ class ProjectorAPI(TestCase):
|
|||||||
'aae4a07b26534cfb9af4232f361dce73':
|
'aae4a07b26534cfb9af4232f361dce73':
|
||||||
{'id': customslide.id,
|
{'id': customslide.id,
|
||||||
'uuid': 'aae4a07b26534cfb9af4232f361dce73',
|
'uuid': 'aae4a07b26534cfb9af4232f361dce73',
|
||||||
'name': 'core/customslide',
|
'name': 'core/customslide'}},
|
||||||
'context': None}},
|
|
||||||
'scale': 0,
|
'scale': 0,
|
||||||
'scroll': 0})
|
'scroll': 0})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user