Beispiel #1
0
 def get(self, club_id, email_id):
     # check credentials
     if not(check_admin(club_id)):
         add_notify("Error", "You do not have the appropriate permissions")
         self.redirect("/")
         return
     user = users.get_current_user()
     club = Club.get_by_key_name(club_id)
     
     # get the email to be admin-ified
     email = Email.get_by_key_name(email_id)
     if not(email):
         add_notify("Error", "No email to be promoted!")
         self.redirect("/club/%s" % club.slug)
         return
     # find the link to promote it
     query = EmailToClub.all()
     query.filter("email =", email)
     query.filter("club =", club)
     link = query.get()
     if not(link):
         add_notify("Error", "No email to be promoted!")
         self.redirect("/club/%s" % club.slug)
         return
     if not link.enable:
         add_notify("Error", "Can't promote a disabled email")
         self.redirect("/club/%s" % club.slug)
         return
     # flip the admin bit
     link.admin = not(link.admin)
     link.put()
     # make sure we have at least one admin
     query = EmailToClub.all()
     query.filter("club =", club)
     query.filter("admin =", True)
     admin_check = query.get()
     if not(admin_check):
         # reverse the admin
         link.admin = True
         link.put()
     # send an email if you've just been promoted
     if link.admin:
         domain = "http://%s.appspot.com" % get_application_id()
         msg = mail.EmailMessage()
         fromaddr = "noreply@%s.appspotmail.com" % get_application_id()
         msg.sender  = "Flyer Guy <%s>" % fromaddr
         msg.to      = email.email
         msg.subject = "[Flyer] You've an admin of %s!" % club.name
         msg.html    = template.render("templates/email_admin.html",
                                       {"domain":domain,
                                        "club":club.name,
                                        "email":email.id})
         try:
             msg.send()
         except apiproxy_errors.OverQuotaError, (message,):
             # Log the error
             add_notify("Error", "Could not send email")
             logging.error("Could not send email")
             logging.error(message)
Beispiel #2
0
 def post(self, job_id):
     job = Job.get_by_key_name(job_id)
     # make sure the job is recent
     if not(job.active):
         self.error(404)
     email = job.email
     email.enable = False
     email.updated_at = datetime.datetime.now()
     email.put()
     # find the email-club join
     join_query = EmailToClub.all()
     join_query.filter("email =", email)
     joins = join_query.fetch(20)
     # do the delete
     for join in joins:
         join.enable = False
         join.updated_at = datetime.now()
         join.put()
     # mark all the jobs inactive
     job_query = Job.all()
     job_query.filter("email =", email)
     job_query.filter("active =", True)
     jobs = job_query.fetch(20)
     for job in jobs:
         job.active = False
         job.put()
     self.response.out.write(template.render("templates/sorry.html", {}))
Beispiel #3
0
 def post(self, job_id):
     job = Job.get_by_key_name(job_id)
     # make sure the job is recent
     if not(job.active):
         self.error(404)
     club = job.flyer.club
     email = job.email
     # update the email
     email.updated_at = datetime.now()
     email.put()
     # find the email-club join
     join_query = EmailToClub.all()
     join_query.filter("email =", email)
     join_query.filter("club =", club)
     join = join_query.get()
     # do the delete
     join.enable = False
     join.updated_at = datetime.now()
     join.put()
     # mark all the jobs inactive
     flyer_query = Flyer.all()
     flyer_query.filter("club =", club)
     flyer_query.filter("active =", True)
     flyers = flyer_query.fetch(20)
     for flyer in flyers:
         job_query = Job.all()
         job_query.filter("email =", email)
         job_query.filter("flyer =", flyer)
         job_query.filter("active =", True)
         job = job_query.get()
         if job:
             job.active = False
             job.put()
     self.response.out.write(template.render("templates/sorry.html",
                                             {}))
Beispiel #4
0
    def post(self, club_id):
        # check credentials
        if not(check_admin(club_id)):
            add_notify("Error", "You do not have the appropriate permissions")
            self.redirect("/")
            return
        user = users.get_current_user()
        club = Club.get_by_key_name(club_id)
        email = get_email(user)

        # add emails
        email_block = self.request.get("newemails")
        emails_raw = [e for e in re.split("[\s\,\n]", email_block) if e]
        emails = [normalize_email(e) for e in emails_raw]
        emails = [e for e in emails if e]
        for email in emails:
            # add a suffix
            email = normalize_email(email)
            # use a hash for emails, assume it is unique
            email_key = generate_hash(email)[:10]
            email_obj, made = get_or_make(Email, email_key)
            if not(made):
                logging.info("Email already in the system")
                continue
            email_obj.email = email
            email_obj.id = email_key
            email_obj.put()
            # make sure this pair is unique
            query = EmailToClub.all()
            query.filter('email =', email_obj)
            query.filter('club =', club)
            join = query.get()
            if not(join):
                join = EmailToClub(email=email_obj, club=club)
                join.put()

        # create message
        if emails:
            add_notify("Notice", "Emails added")
        if len(emails) != len(emails_raw):
            add_notify("Notice", "Not all emails added")
        self.redirect("/club/%s" % club.slug)
Beispiel #5
0
 def post(self):
     # check there's someone signed in
     user = users.get_current_user()
     if not(user):
         add_notify("Error", "You do not have the appropriate permissions")
         self.redirect("/")
         return
     # get associated email
     email_query = Email.all()
     email_query.filter("user = "******"Error", "You do not have the appropriate permissions")
         self.redirect("/")
         return
     # basic sanity check
     clubname = self.request.get("name")
     if not(clubname):
         add_notify("Error", "Please enter a club name")
         self.redirect("/")
         return
     # convert to slug
     clubslug = slugify(clubname)
     # basics of get_or_insert, with insertion
     club, made = get_or_make(Club, clubslug)
     if not(made):
         # generate an error
         add_notify("Error", "That particular club name is taken. Sorry!")
         self.redirect("/")
         return
     # make a club, add current user as an admin
     club.name = clubname
     club.slug = clubslug
     club.put()
     join = EmailToClub(email=email, club=club, admin=True)
     join.put()
     club_url = "/club/%s" % clubslug
     self.redirect(club_url)
Beispiel #6
0
def check_admin(club_id):
    """See if we have admin access to a certain club's pages"""
    user = users.get_current_user()
    email = get_email(user)
    club = Club.get_by_key_name(club_id)
    if not(user) or not(email) or not(club) or not(email.user_enable):
        return False
    # do a joint query
    query = EmailToClub.all()
    query.filter("email =", email)
    query.filter("club =", club)
    joint = query.get()
    if not(joint):
        return False
    return joint.admin
Beispiel #7
0
    def get(self, club_id, email_id):
        # check credentials
        if not(check_admin(club_id)):
            add_notify("Error", "You do not have the appropriate permissions")
            self.redirect("/")
            return
        club = Club.get_by_key_name(club_id)

        # get the email link to be deleted
        email = Email.get_by_key_name(email_id)
        if not(email):
            add_notify("Error", "No email to be deleted!")
            self.redirect("/club/%s" % club.slug)
            return
        # find the link
        query = EmailToClub.all()
        query.filter("email =", email)
        query.filter("club =", club)
        link = query.get()
        if not(link):
            add_notify("Error", "No email to be deleted!")
            self.redirect("/club/%s" % club.slug)
            return
        # make sure it's not the last admin
        query = EmailToClub.all()
        query.filter("club =", club)
        admins = query.fetch(2)
        if len(admins) < 2 and link.admin:
            add_notify("Error", "Will not delete the last club admin")
            self.redirect("/club/%s" % club.slug)
            return
        # delete the link
        link.delete()
        # hail our success
        add_notify("Notice", "Email deleted")
        self.redirect("/club/%s" % club.slug)
Beispiel #8
0
    def get(self):
        timestamp = time.mktime(datetime.now().timetuple())-24*3600
        yesterday = datetime.fromtimestamp(timestamp)
        # count how many flyers are going out
        current_date = datetime.now(CurrentTimeZone())
        day = current_date.weekday() # starts 0=monday... 6=sunday
        if day < 5:
            job_query = Job.all()
            job_query.filter("active =", True)
            job_query.filter("state !=", DONE)
            flyer_count = job_query.count()
        else:
            flyer_count = 0
        # get new clubs
        club_query = Club.all()
        club_query.filter("created_at >", yesterday)
        new_clubs = club_query.fetch(20)
        # get new emails
        email_query = Email.all()
        email_query.filter("created_at >", yesterday)
        new_emails = email_query.fetch(100)
        # get new flyers
        flyer_query = Flyer.all()
        flyer_query.filter("created_at >", yesterday)
        new_flyers = flyer_query.fetch(50)
        # get new EmailToClub
        joint_query = EmailToClub.all()
        joint_query.filter("created_at >", yesterday)
        new_joints = joint_query.fetch(100)
        # and get the newly disabled links
        joint_query = EmailToClub.all()
        joint_query.filter("updated_at >", yesterday)
        joint_query.filter("enable =", False)
        dead_joints = joint_query.fetch(100)

        if (not(new_clubs) and not(new_emails) and not(new_flyers)
            and not(new_joints)):
            self.response.out.write("Nothing to email")
            return

        # email sending pre-computation
        fromaddr = "noreply@%s.appspotmail.com" % get_application_id()
        date = time.strftime("%Y/%m/%d")

        # send the emails
        msg = mail.EmailMessage(sender = "Flyer Guy <%s>" % fromaddr,
                                to = ADMIN_EMAIL)
        msg.subject = "[Flyer] Admin stats (%s)" % date
        msg.html    = template.render("templates/email_stats.html",
                                      {"flyer_count": flyer_count,
                                       "clubs": new_clubs,
                                       "emails": new_emails,
                                       "flyers": new_flyers,
                                       "joints": new_joints,
                                       "dead_joints": dead_joints})
        try:
            msg.send()
        except apiproxy_errors.OverQuotaError, (message,):
            # Log the error.
            logging.error("Could not send email")
            logging.error(message)