def _get_new_mentions(self, obj: object, old_comment: str, new_comment: str): old_mentions = notifications_services.get_mentions( obj.project, old_comment) submitted_mentions = notifications_services.get_mentions( obj, new_comment) return list(set(submitted_mentions) - set(old_mentions))
def _get_submitted_mentions(self, obj): mention_fields = ['description', 'content'] new_mentions = [] for field_name in mention_fields: if not hasattr(obj, field_name) or not hasattr(obj, "get_project"): continue value = self.request.DATA.get(field_name) if not value: continue new_mentions += services.get_mentions(obj.get_project(), value) return new_mentions
def update(self, request, *args, **kwargs): if not getattr(self, 'object', None): self.object = self.get_object_or_none() obj = self.object if obj and obj.id: if hasattr(obj, "watchers"): self._old_watchers = [ watcher.id for watcher in obj.get_watchers() ] mention_fields = ['description', 'content'] for field_name in mention_fields: if not hasattr(obj, field_name) or not hasattr(obj, "get_project"): continue self._old_mentions += services.get_mentions(obj.get_project(), getattr(obj, field_name)) slack.send_slack_notification(request, obj) return super().update(request, *args, **kwargs)
def _get_new_mentions_in_field(self, obj, field_name): value = self.request.DATA.get(field_name) if not value: return [] return services.get_mentions(obj, value)
def _get_old_mentions_in_field(self, obj, field_name): if not hasattr(obj, field_name): return [] return services.get_mentions(obj, getattr(obj, field_name))
def _get_mentions_in_comment(self, obj): comment = self.request.DATA.get('comment') if comment: return services.get_mentions(obj, comment) return []
def _get_mentions_in_comment(self, obj): comment = self.request.DATA.get('comment') if not comment or not hasattr(obj, "get_project"): return [] return services.get_mentions(obj.get_project(), comment)
def _get_new_mentions_in_field(self, obj, field_name): value = self.request.DATA.get(field_name) if not value: return [] return services.get_mentions(obj, value)
def _get_old_mentions_in_field(self, obj, field_name): if not hasattr(obj, field_name): return [] return services.get_mentions(obj, getattr(obj, field_name))
def _get_mentions_in_comment(self, obj): comment = self.request.DATA.get('comment') if comment: return services.get_mentions(obj, comment) return []