From a2a6637c89e97582bb28c98dae0f630218acfbf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Sat, 27 Feb 2016 20:25:06 +0100 Subject: [PATCH] Rename and refactor some ProjectorElement methods. Fixed #1631. --- openslides/agenda/projector.py | 4 ++-- openslides/assignments/projector.py | 2 +- openslides/core/models.py | 6 +++--- openslides/core/projector.py | 6 +++--- openslides/mediafiles/projector.py | 2 +- openslides/motions/projector.py | 2 +- openslides/users/projector.py | 2 +- openslides/utils/projector.py | 30 ++++++++++++++++++++-------- tests/integration/core/test_views.py | 3 +-- 9 files changed, 35 insertions(+), 22 deletions(-) diff --git a/openslides/agenda/projector.py b/openslides/agenda/projector.py index 8727236ea..0a8eba9b9 100644 --- a/openslides/agenda/projector.py +++ b/openslides/agenda/projector.py @@ -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.') diff --git a/openslides/assignments/projector.py b/openslides/assignments/projector.py index 30b360fce..5c814082b 100644 --- a/openslides/assignments/projector.py +++ b/openslides/assignments/projector.py @@ -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. diff --git a/openslides/core/models.py b/openslides/core/models.py index e1c129994..843d9dd0e 100644 --- a/openslides/core/models.py +++ b/openslides/core/models.py @@ -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: diff --git a/openslides/core/projector.py b/openslides/core/projector.py index 2d3d29779..b229c84ad 100644 --- a/openslides/core/projector.py +++ b/openslides/core/projector.py @@ -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.') diff --git a/openslides/mediafiles/projector.py b/openslides/mediafiles/projector.py index 748b0ca9b..ead760a25 100644 --- a/openslides/mediafiles/projector.py +++ b/openslides/mediafiles/projector.py @@ -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: diff --git a/openslides/motions/projector.py b/openslides/motions/projector.py index e4adecec6..ae12e728a 100644 --- a/openslides/motions/projector.py +++ b/openslides/motions/projector.py @@ -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. diff --git a/openslides/users/projector.py b/openslides/users/projector.py index 69364ce0c..858f70c12 100644 --- a/openslides/users/projector.py +++ b/openslides/users/projector.py @@ -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.') diff --git a/openslides/utils/projector.py b/openslides/utils/projector.py index 265f5b4a9..855d2767d 100644 --- a/openslides/utils/projector.py +++ b/openslides/utils/projector.py @@ -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): """ diff --git a/tests/integration/core/test_views.py b/tests/integration/core/test_views.py index aa4a7ec55..7545f2bac 100644 --- a/tests/integration/core/test_views.py +++ b/tests/integration/core/test_views.py @@ -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})