Exemplo n.º 1
0
 def notify_self(self):
     from notification import Notification
     from follower import Follower
     follower = Follower.query.filter(
         and_(Follower.Type == self.Type,
              Follower.ParentID == self.ParentID,
              Follower.UserID == self.UserID)).first()
     if follower:
         note = Notification(UserID=self.UserID,
                             Type="Comments",
                             ParentID=self.CommentID,
                             FollowerID=follower.FollowerID)
         note.save()
Exemplo n.º 2
0
 def group_notify(cls,
                  groups,
                  subject,
                  body,
                  link=None,
                  delay=None,
                  tag=None):
     """
     Send notification to a list of groups
     Prevent duplicated messages
     """
     if not subject and not body:
         return
     if subject is None:
         subject = ""
     if body is None:
         body = ""
     if not isinstance(subject, dict):
         subject = {LANGUAGE_CODE: subject}
     if not isinstance(body, dict):
         body = {LANGUAGE_CODE: body}
     ngs = set()
     lang = {}  # (method, params) -> lang
     for g in groups:
         for method, params, l in g.active_members:
             ngs.add((method, params))
             lang[(method, params)] = l
     for method, params in ngs:
         l = lang[(method, params)]
         n = Notification(notification_method=method,
                          notification_params=params,
                          subject=cls.get_effective_message(subject, l),
                          body=cls.get_effective_message(body, l),
                          link=link)
         if delay:
             n.next_try = datetime.datetime.now() + datetime.timedelta(
                 seconds=delay)
         if tag:
             n.tag = tag
         n.save()