Exemple #1
0
 def clean_user(self):
     username_or_email = self.cleaned_data["user"]
     user = users.get_user(username_or_email, create=False)
     if user is None:
         message = "User %s cannot be found." % username_or_email
         raise forms.ValidationError(message)
     return user
Exemple #2
0
 def create_instance(self, csv_row):
     # Ignore all emails that are not in the supported domain.
     email = csv_row[0].lower()
     if not email.endswith("@" + self._EMAIL_DOMAIN):
         return None
     # Ignore all members that already exist.
     group = self.cleaned_data["group"]
     user = users.get_user(email)
     if Member.get_unique(group=group, user=user) is not None:
         return None
     # Create a new Member instance.
     if csv_row[2] == "manager" or csv_row[2] == "owner":
         role = Member.MODERATOR
     else:
         role = Member.MEMBER
     join_date = datetime.date(int(csv_row[6]), int(csv_row[7]), int(csv_row[8]))
     return Member.create(
         user=user,
         group=group,
         role=role,
         join_date=join_date,
         is_approved=True
     )
Exemple #3
0
 def _send_top_posters(self, group):
     group_stat = GroupStat.get_unique(group=group, date=datetime.date.today(), month_delta=-1)
     if not group_stat:
         return 0
     top_posters = PosterStat.find_by_group_stat(group_stat=group_stat, limit=3)
     if not top_posters:
         return 0
     data = {
         "group_stat": group_stat,
         "top_posters": top_posters,
         "http_host": getattr(settings, "MY_HTTP_HOST", None),
     }
     message = render_to_string("cronjobs/mails/top_posters.txt", data)
     author = users.get_user(self.FROM_EMAIL)
     recipient = "*****@*****.**" % group.google_group
     something_happened.send(
         sender=Group.__name__,
         subject=None,
         message=message,
         author=author,
         recipients=[recipient]
     )
     return 1
Exemple #4
0
 def __init__(self, request, group_uid, username):
     super(BaseMemberAction, self).__init__(request, group_uid)
     self._username = username
     self._user = users.get_user(username, create=False)