コード例 #1
0
    def post(self):
        flyer = Flyer()
        pdf = self.request.get("flyer")
        flyer.flyer = db.Blob(pdf)
        flyer.name = self.request.get("name")
        flyer.put()
        flyer.id = str(flyer.key().id())
        flyer.put()

        recipients = self.request.get("content")
        lines = [
            r.split(" ") for r in recipients.strip(" \t").split("\n")
            if len(r) > 0
        ]
        for line in lines:
            email = line[0]
            msg = " ".join(line[1:])
            job = Job(flyer_id=flyer.id,
                      email=email,
                      msg=msg,
                      count=5,
                      state="init",
                      flyer=flyer)
            job.put()

        self.response.out.write(template.render("templates/finish.html", {}))
コード例 #2
0
ファイル: flyer.py プロジェクト: thenoviceoof/flyer-poke
 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",
                                             {}))
コード例 #3
0
ファイル: admin.py プロジェクト: adi-archive/flyer-poke
    def get(self):
        flyerq = Flyer.all()
        flyers = flyerq.fetch(BOUND)
        jobs = Job.all().fetch(BOUND)

        values = {"flyers": flyers, "jobs": jobs}
        self.response.out.write(template.render("templates/list.html", values))
コード例 #4
0
ファイル: admin.py プロジェクト: adi-archive/flyer-poke
 def get(self):
     # clean out the old pdfs
     jobs = Job.all().fetch(BOUND)
     for job in jobs:
         job.delete()
     flyers = Flyer.all().fetch(BOUND)
     for flyer in flyers:
         flyer.delete()
     self.response.out.write(
         template.render("templates/task.html",
                         {"msg": "Removed everything"}))
コード例 #5
0
ファイル: flyer.py プロジェクト: adi-archive/flyer-poke
    def post(self):
        flyer = Flyer()
        pdf = self.request.get("flyer")
        flyer.flyer = db.Blob(pdf)
        flyer.name = self.request.get("name")
        flyer.put()
        flyer.id = str(flyer.key().id())
        flyer.put()

        recipients = self.request.get("content")
        lines = [r.split(" ") for r in recipients.strip(" \t").split("\n")
                 if len(r)>0]
        for line in lines:
            email = line[0]
            msg = " ".join(line[1:])
            job = Job(flyer_id=flyer.id, email=email, msg=msg, count=5,
                      state="init", flyer=flyer)
            job.put()

        self.response.out.write(template.render("templates/finish.html", {}))
コード例 #6
0
ファイル: admin.py プロジェクト: thenoviceoof/flyer-poke
    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)