示例#1
0
def count_post(subject, poster_email, recipients):
    # TODO: currently we support only vivelevendredi Google Group.
    RECIPIENT_TO_GROUP_UID = {
        "*****@*****.**": "vivelevendredi",
    }
    try:
        recipients = [
            recipient.lower()
            for recipient in recipients
            if recipient.lower() in RECIPIENT_TO_GROUP_UID
        ]
        recipients = set(recipients)  # to remove duplicates.
        for recipient in recipients:
            group = Group.get_unique(uid=RECIPIENT_TO_GROUP_UID[recipient])
            if group is None:
                logging.warning("Ignored recipient %s: group cannot be found." % recipient)
                continue
            group_stat = GroupStat.get_or_create(group=group, date=datetime.date.today())
            group_stat.post_count += 1
            group_stat.save()
            poster = users.get_user_by_email(poster_email)
            if poster is None:
                logging.warning("Ignored poster %s: user cannot be found." % poster_email)
            else:
                poster_stat = PosterStat.get_or_create(group_stat=group_stat, poster=poster)
                poster_stat.post_count += 1
                poster_stat.save()
    except Exception, exc:
        logging.error("Failed to count post: %s" % exc)
        logging.exception(exc)
示例#2
0
 def clean_group(self):
     group_uid = self.cleaned_data["group"]
     group = Group.get_unique(uid=group_uid)
     if group is None:
         message = "Group %s cannot be found." % group_uid
         raise forms.ValidationError(message)
     return group
示例#3
0
 def get_group(self):
     group = Group.get_unique(uid=self.group_uid)
     if not group:
         message = "searched by group uid %s." % self.group_uid
         raise EntityNotFoundError(Group, message)
     return group