Exemple #1
0
def attachment_delete(order_id, aid):
    attachment = Attachment.get(aid)
    target_type = attachment.target_type
    attachment.delete()
    flash(u'删除成功!', 'success')
    if target_type == 'ClientOrder':
        return redirect(url_for("files.client_order_files", order_id=order_id))
    elif target_type == 'Order':
        return redirect(url_for("files.medium_order_files", order_id=order_id))
    elif target_type == 'DoubanOrder':
        return redirect(url_for("files.douban_order_files", order_id=order_id))
    elif target_type == 'AssociatedDoubanOrder':
        return redirect(
            url_for("files.associated_douban_order_files", order_id=order_id))
    elif target_type == 'FrameworkOrder':
        return redirect(
            url_for("files.framework_order_files", order_id=order_id))
    elif target_type == 'searchAdFrameworkOrder':
        return redirect(
            url_for("files.searchAd_framework_order_files", order_id=order_id))
    elif target_type == 'searchAdClientOrder':
        return redirect(
            url_for("files.searchAd_client_order_files", order_id=order_id))
    elif target_type == 'searchAdOrder':
        return redirect(
            url_for("files.searchAd_medium_order_files", order_id=order_id))
    elif target_type == 'ClientMediumOrder':
        return redirect(
            url_for("files.client_meduim_order_files", order_id=order_id))
Exemple #2
0
def _handle_schedule(schedule_id):
    schedule = Schedule.get(Schedule.id == schedule_id)
    if not schedule:
        logger.warn("Schedule is invalid. ID = %s" % schedule_id)
        return
    to_mails = schedule.recipients.split(",")
    attachments = Attachment.gets_by_schedule(schedule_id)
    atta_dicts = [a.to_mandrill_dict() for a in attachments]
    rs = send_mail(
        subject=schedule.subject,
        from_mail=SEND_ADDRESS,
        to_mails=to_mails,
        html=schedule.content,
        attachments=atta_dicts,
    )
    if not rs:
        logger.warn("Schedule send fail. ID = %s" % schedule_id)
        schedule.fail()
        return
    if schedule.repeat_strategy:
        schedule.wait(schedule.repeat_strategy.get_next_time())
    else:
        schedule.send()
    for r in rs:
        logger.info(r)
        now = datetime.utcnow()
        History.create(
            recipient=r.get("email"),
            send_id=r.get("_id", ""),
            schedule_id=schedule.id,
            status=r.get("status"),
            reason=r.get("reject_reason") or "",
            send_time=now,
            update_time=now,
        )
Exemple #3
0
def files_delete(f_type, type, aid, id):
    attachment = Attachment.get(aid)
    attachment.delete()
    flash(FILE_TYPE_CN[int(type)] + u' 删除成功', 'success')
    if f_type == 'medium':
        return redirect(url_for('searchAd_client.medium_detail', medium_id=id))
    elif f_type == 'agent':
        return redirect(url_for('searchAd_client.agent_detail', agent_id=id))
Exemple #4
0
 def post(self):
     files = self.request.POST.getall('attachment')
     attachments = []
     for f in files:
         file = f.file
         if not file:
             continue
         filename = f.filename.encode('utf-8') if f.filename else 'undefined'
         filetype = f.type or 'application/octet-stream'
         atta = Attachment.create(schedule_id=0,
                                  filename=filename,
                                  filetype=filetype,
                                  file=file.read(),
                                  create_time=datetime.utcnow())
         a = {'filename':filename, 'id': atta.id}
         attachments.append(a)
     self.json({'attachments': attachments})
Exemple #5
0
def attachment_delete(order_id, aid):
    attachment = Attachment.get(aid)
    target_type = attachment.target_type
    attachment.delete()
    flash(u'删除成功!', 'success')
    if target_type == 'ClientOrder':
        return redirect(url_for("files.client_order_files", order_id=order_id))
    elif target_type == 'Order':
        return redirect(url_for("files.medium_order_files", order_id=order_id))
    elif target_type == 'DoubanOrder':
        return redirect(url_for("files.douban_order_files", order_id=order_id))
    elif target_type == 'AssociatedDoubanOrder':
        return redirect(url_for("files.associated_douban_order_files", order_id=order_id))
    elif target_type == 'FrameworkOrder':
        return redirect(url_for("files.framework_order_files", order_id=order_id))
    elif target_type == 'searchAdFrameworkOrder':
        return redirect(url_for("files.searchAd_framework_order_files", order_id=order_id))
    elif target_type == 'searchAdClientOrder':
        return redirect(url_for("files.searchAd_client_order_files", order_id=order_id))
    elif target_type == 'searchAdOrder':
        return redirect(url_for("files.searchAd_medium_order_files", order_id=order_id))
    elif target_type == 'ClientMediumOrder':
        return redirect(url_for("files.client_meduim_order_files", order_id=order_id))
Exemple #6
0
 def add_outsource_attachment(self, user, filename):
     Attachment.add(self.target_type, self.target_id,
                    filename, ATTACHMENT_TYPE_OUTSOURCE, user,
                    datetime.datetime.now())
     return self.get_last_schedule()
Exemple #7
0
 def add_finish_attachment(self, user, filename):
     Attachment.add(self.target_type, self.target_id, filename,
                    ATTACHMENT_TYPE_FINISH, user, datetime.datetime.now())
     return self.get_last_finish()
Exemple #8
0
 def add_contract_attachment(self, user, filename):
     Attachment.add(self.target_type, self.target_id, filename,
                    ATTACHMENT_TYPE_CONTRACT, user, datetime.datetime.now())
     return self.get_last_contract()
Exemple #9
0
 def add_medium_files(self, user, filename, type):
     Attachment.add(self.target_type, self.target_id, filename, type, user,
                    datetime.datetime.now())
     return self.get_last_medium(type)
Exemple #10
0
 def add_client_attachment(self, user, filename, type):
     Attachment.add(self.target_type, self.target_id, filename, type, user,
                    datetime.datetime.now())
     return self.get_last_schedule()
Exemple #11
0
 def add_client_attachment(self, user, filename, type):
     Attachment.add(self.target_type, self.target_id, filename,
                    type, user, datetime.datetime.now())
     return self.get_last_schedule()
Exemple #12
0
 def add_other_attachment(self, user, filename):
     Attachment.add(self.target_type, self.target_id, filename,
                    ATTACHMENT_TYPE_OTHERS, user, datetime.datetime.now())
     return self.get_last_others()
Exemple #13
0
 def add_medium_group_attachment(self, user, filename):
     Attachment.add(self.target_type, self.target_id, filename,
                    ATTACHMENT_TYPE_MEDIUM_GROUP, user, datetime.datetime.now())
     return self.get_last_schedule()
Exemple #14
0
 def add_agent_attachment(self, user, filename):
     Attachment.add(self.target_type, self.target_id, filename,
                    ATTACHMENT_TYPE_AGENT, user, datetime.datetime.now())
     return self.get_last_schedule()
Exemple #15
0
 def add_outsource_attachment(self, user, filename):
     Attachment.add(self.target_type, self.target_id, filename,
                    ATTACHMENT_TYPE_OUTSOURCE, user, datetime.datetime.now())
     return self.get_last_schedule()
Exemple #16
0
 def add_finish_attachment(self, user, filename):
     Attachment.add(self.target_type, self.target_id, filename,
                    ATTACHMENT_TYPE_FINISH, user, datetime.datetime.now())
     return self.get_last_finish()
Exemple #17
0
 def add_contract_attachment(self, user, filename):
     Attachment.add(self.target_type, self.target_id, filename,
                    ATTACHMENT_TYPE_CONTRACT, user, datetime.datetime.now())
     return self.get_last_contract()
Exemple #18
0
 def add_medium_files(self, user, filename, type):
     Attachment.add(self.target_type, self.target_id, filename,
                    type, user, datetime.datetime.now())
     return self.get_last_medium(type)
Exemple #19
0
 def add_medium_attachment(self, user, filename):
     Attachment.add(self.target_type, self.target_id, filename,
                    ATTACHMENT_TYPE_MEDIUM, user, datetime.datetime.now())
     return self.get_last_schedule()
Exemple #20
0
def agent_files_delete(agent_id, aid):
    attachment = Attachment.get(aid)
    attachment.delete()
    flash(u'删除成功!', 'success')
    return redirect(url_for("searchAd_client.agent_detail", agent_id=agent_id))
def remove_attachment():
    q = Attachment.delete().where(Attachment.schedule_id == 0 ,
                                  Attachment.create_time <
                                  (datetime.utcnow() - timedelta(days=1)))
    cnt = q.execute()
    logger.info('%s useless attachments removed' % cnt)
Exemple #22
0
    def post(self):
        recipients = self.request.POST.getall('recipient')
        subject = self.request.POST.get('subject', '')
        content = self.request.POST.get('content', '')
        send_type = self.request.POST.get('send_type')
        attachment_id = self.request.POST.getall('attachment_id') or []
        repeat_strategy = None

        to_mails = []
        for recipient in recipients:
            if not recipient or not validate_email(recipient):
                self.abort(400, 'recipient is invalid')
            to_mails.append(recipient.strip())
        to_mails = ','.join(to_mails)
        if len(to_mails) > RECIPIENTS_MAX_LEN:
            self.abort(400, 'recipients is too long')
        if len(subject) > SUBJECT_MAX_LEN:
            self.abort(400, 'subject is too long')
        if not send_type or send_type not in ['later', 'estimated', 'repeat']:
            self.abort(400, 'send type is invalid')
        now = datetime.utcnow()
        if send_type == 'later':
            later_value = self.request.POST.get('later_value')
            later_type = self.request.POST.get('later_type')
            if not later_value or not later_type:
                self.abort(400, 'send time is empty')
            try:
                later_value = int(later_value)
            except:
                self.abort(400, 'send time invalid')
            if later_type == 'minute':
                delta = timedelta(minutes=later_value)
            elif later_type == 'hour':
                delta = timedelta(hours=later_value)
            elif later_type == 'day':
                delta = timedelta(days=later_value)
            else:
                self.abort(400, 'send time invalid')
            estimated_time = (now + delta).replace(microsecond=0)
        elif send_type == 'estimated':
            estimated_time = self.request.POST.get('estimated_time')
            if not estimated_time:
                self.abort(400, 'estimated time is empty')
            try:
                estimated_time = datetime.strptime(estimated_time, DATE_FORMAT)
                estimated_time = convert_to_utc(estimated_time)
            except:
                self.abort(400, 'estimated time invalid')
        elif send_type == 'repeat':
            repeat_type = self.request.POST.get('repeat_type')
            repeat_time = self.request.POST.get('repeat_time')
            if not repeat_type or not repeat_time:
                self.abort(400, 'repeat time is empty')
            try:
                r_type = RepeatType(int(repeat_type))
                r_time = datetime.strptime(repeat_time, TIME_FORMAT).time()
                repeat_strategy = RepeatStrategy.init_from_local(r_type,
                                                                 r_time)
            except:
                self.abort(400, 'repeat time invalid')
            estimated_time = repeat_strategy.get_next_time()

        sche = Schedule.create(recipients=to_mails,
                               subject=subject,
                               content=content,
                               status=ScheduleStatus.inited.value,
                               estimated_time=estimated_time,
                               create_time=now,
                               repeat = repeat_strategy.to_json()
                                        if repeat_strategy
                                        else '')
        for aid in attachment_id:
            Attachment.link(aid, sche.id)
        return redirect('/schedule')
Exemple #23
0
 def add_user_pic_file(self, user, filename):
     Attachment.add(self.target_type, self.target_id, filename,
                    ATTACHMENT_TYPE_USER_PIC, user, datetime.datetime.now())
     return self.get_last_user_pic_file()
Exemple #24
0
 def add_other_attachment(self, user, filename):
     Attachment.add(self.target_type, self.target_id, filename,
                    ATTACHMENT_TYPE_OTHERS, user, datetime.datetime.now())
     return self.get_last_others()
Exemple #25
0
 def add_user_pic_file(self, user, filename):
     Attachment.add(self.target_type, self.target_id, filename,
                    ATTACHMENT_TYPE_USER_PIC, user, datetime.datetime.now())
     return self.get_last_user_pic_file()
Exemple #26
0
def medium_files_delete(medium_id, aid):
    attachment = Attachment.get(aid)
    attachment.delete()
    flash(u'删除成功!', 'success')
    return redirect(url_for("searchAd_client.medium_detail", medium_id=medium_id))
Exemple #27
0
def files_delete(mid, aid):
    attachment = Attachment.get(aid)
    type = attachment.attachment_type
    attachment.delete()
    flash(u'删除成功!', 'success')
    return redirect(url_for("mediums_files.info_last", mid=mid, type=type))