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'
|
||||
|
||||
def get_context(self):
|
||||
def check_data(self):
|
||||
pk = self.config_entry.get('id')
|
||||
if pk is not None:
|
||||
# Children slide.
|
||||
@ -48,7 +48,7 @@ class ListOfSpeakersSlide(ProjectorElement):
|
||||
"""
|
||||
name = 'agenda/list-of-speakers'
|
||||
|
||||
def get_context(self):
|
||||
def check_data(self):
|
||||
pk = self.config_entry.get('id')
|
||||
if pk is None:
|
||||
raise ProjectorException('Id must not be None.')
|
||||
|
@ -14,7 +14,7 @@ class AssignmentSlide(ProjectorElement):
|
||||
"""
|
||||
name = 'assignments/assignment'
|
||||
|
||||
def get_context(self):
|
||||
def check_data(self):
|
||||
pk = self.config_entry.get('id')
|
||||
if pk is not None:
|
||||
# Detail slide.
|
||||
|
@ -70,8 +70,8 @@ class Projector(RESTModelMixin, models.Model):
|
||||
@property
|
||||
def elements(self):
|
||||
"""
|
||||
Retrieve all projector elements given in the config
|
||||
field. For every element the method get_data() is called and its
|
||||
Retrieve all projector elements given in the config field. For
|
||||
every element the method check_and_update_data() is called and its
|
||||
result is also used.
|
||||
"""
|
||||
# Get all elements from all apps.
|
||||
@ -90,7 +90,7 @@ class Projector(RESTModelMixin, models.Model):
|
||||
result[key]['error'] = 'Projector element does not exist.'
|
||||
else:
|
||||
try:
|
||||
result[key].update(element.get_data(
|
||||
result[key].update(element.check_and_update_data(
|
||||
projector_object=self,
|
||||
config_entry=value))
|
||||
except ProjectorException as e:
|
||||
|
@ -14,7 +14,7 @@ class CustomSlideSlide(ProjectorElement):
|
||||
"""
|
||||
name = 'core/customslide'
|
||||
|
||||
def get_context(self):
|
||||
def check_data(self):
|
||||
if not CustomSlide.objects.filter(pk=self.config_entry.get('id')).exists():
|
||||
raise ProjectorException('Custom slide does not exist.')
|
||||
|
||||
@ -74,7 +74,7 @@ class Countdown(ProjectorElement):
|
||||
"""
|
||||
name = 'core/countdown'
|
||||
|
||||
def get_context(self):
|
||||
def check_data(self):
|
||||
self.validate_config(self.config_entry)
|
||||
|
||||
@classmethod
|
||||
@ -136,6 +136,6 @@ class Message(ProjectorElement):
|
||||
"""
|
||||
name = 'core/message'
|
||||
|
||||
def get_context(self):
|
||||
def check_data(self):
|
||||
if self.config_entry.get('message') is None:
|
||||
raise ProjectorException('No message given.')
|
||||
|
@ -11,7 +11,7 @@ class MediafileSlide(ProjectorElement):
|
||||
"""
|
||||
name = 'mediafiles/mediafile'
|
||||
|
||||
def get_context(self):
|
||||
def check_data(self):
|
||||
try:
|
||||
Mediafile.objects.get(pk=self.config_entry.get('id'))
|
||||
except Mediafile.DoesNotExist:
|
||||
|
@ -14,7 +14,7 @@ class MotionSlide(ProjectorElement):
|
||||
"""
|
||||
name = 'motions/motion'
|
||||
|
||||
def get_context(self):
|
||||
def check_data(self):
|
||||
pk = self.config_entry.get('id')
|
||||
if pk is not None:
|
||||
# Detail slide.
|
||||
|
@ -10,7 +10,7 @@ class UserSlide(ProjectorElement):
|
||||
"""
|
||||
name = 'users/user'
|
||||
|
||||
def get_context(self):
|
||||
def check_data(self):
|
||||
if not User.objects.filter(pk=self.config_entry.get('id')).exists():
|
||||
raise ProjectorException('User does not exist.')
|
||||
|
||||
|
@ -34,23 +34,37 @@ class ProjectorElement(object, metaclass=SignalConnectMetaClass):
|
||||
if not cls.__name__ == 'ProjectorElement':
|
||||
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
|
||||
the config entry have to be given.
|
||||
Checks projector element data via self.check_data() and updates
|
||||
them via self.update_data(). The projector object and the config
|
||||
entry have to be given.
|
||||
"""
|
||||
self.projector_object = projector_object
|
||||
self.config_entry = config_entry
|
||||
assert self.config_entry.get('name') == self.name, (
|
||||
'To get data of a projector element, the correct config entry has to be given.')
|
||||
return {
|
||||
'context': self.get_context()}
|
||||
self.check_data()
|
||||
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):
|
||||
"""
|
||||
|
@ -34,8 +34,7 @@ class ProjectorAPI(TestCase):
|
||||
'aae4a07b26534cfb9af4232f361dce73':
|
||||
{'id': customslide.id,
|
||||
'uuid': 'aae4a07b26534cfb9af4232f361dce73',
|
||||
'name': 'core/customslide',
|
||||
'context': None}},
|
||||
'name': 'core/customslide'}},
|
||||
'scale': 0,
|
||||
'scroll': 0})
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user