Example #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)
Example #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
Example #3
0
 def create(self, creator):
     if self._instance is not None:
         message = "Failed to create group: this form is bound to an existing group."
         raise ProgrammingError(message)
     if not self.is_valid():
         raise InvalidFormError(self.errors)
     instance = Group.create(creator=creator, **self.cleaned_data)
     instance.save()
     return instance
Example #4
0
 def run_cron_job(self, is_scheduled):
     # Ensure that the webapp is properly configured for this cron job.
     if not self.FROM_EMAIL:
         raise ImproperlyConfigured("DEFAULT_FROM_EMAIL not defined in settings.py")
     # If the job is scheduled, run only on the 1st day of month.
     if is_scheduled:
         today = datetime.date.today()
         if today.day != 1:
             message = "Nothing is done: %s is not the 1st day of month." % today.isoformat()
             return message
     # Send top posters to Google Groups.
     groups = [group for group in Group.find_all() if group.google_group]
     mail_sent = 0
     for group in groups:
         try:
             mail_sent += self._send_top_posters(group)
         except Exception, exc:
             logging.error("Failed to send top posters of group %s: %s" % (group.uid, exc))
             logging.exception(exc)
Example #5
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
Example #6
0
 def get_page(self):
     data = self.update_data({"groups": Group.find_all()})
     return render_to_response(self.get_page_template(), data, RequestContext(self.request))