From 30acf40648b7c1a84aec493a4db57a8d9be545e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Thu, 18 May 2017 12:28:04 +0200 Subject: [PATCH] WIP --- taiga/events/events.py | 8 ++++++-- taiga/projects/models.py | 2 ++ taiga/projects/validators.py | 8 ++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/taiga/events/events.py b/taiga/events/events.py index 0fe4ac3c..704a4765 100644 --- a/taiga/events/events.py +++ b/taiga/events/events.py @@ -38,6 +38,7 @@ watched_types = set([ "tasks.task", "wiki.wiki_page", "milestones.milestone", + "projects.game", ]) @@ -79,8 +80,11 @@ def emit_event_for_model(obj, *, type:str="change", channel:str="events", projectid = getattr(obj, "project_id") pk = getattr(obj, "pk", None) - app_name, model_name = content_type.split(".", 1) - routing_key = "changes.project.{0}.{1}".format(projectid, app_name) + if hasattr(obj, '_event_tag'): + event_tag = obj._event_tag + else: + event_tag, model_name = content_type.split(".", 1) + routing_key = "changes.project.{0}.{1}".format(projectid, event_tag) data = {"type": type, "matches": content_type, diff --git a/taiga/projects/models.py b/taiga/projects/models.py index f7894228..cb41ff7c 100644 --- a/taiga/projects/models.py +++ b/taiga/projects/models.py @@ -1277,6 +1277,8 @@ class Game(models.Model): userstories = JSONField() scales = JSONField() roles = JSONField() + _importing = None + _event_tag = "games" def save(self, *args, **kwargs): if not self.uuid: diff --git a/taiga/projects/validators.py b/taiga/projects/validators.py index d2d512fb..d834cab8 100644 --- a/taiga/projects/validators.py +++ b/taiga/projects/validators.py @@ -333,11 +333,11 @@ class GameValidator(validators.ModelValidator): if not isinstance(roles, list): raise ValidationError(_("Invalid roles format")) - for role in roles: - if "id" not in role or "name" not in role: - raise ValidationError(_("Invalid role format")) + for role_id in roles: + if not isinstance(role_id, int): + raise ValidationError(_("Invalid role id format")) - if project.roles.filter(id=role['id']).count() == 0: + if project.roles.filter(id=role_id).count() == 0: raise ValidationError(_("Invalid role for the project")) return attrs