Пример #1
0
def activitycancle(activity_id):
    activity = Activity.query.get_or_404(activity_id)
    if (activity.status == 1 or activity.status == 0) and session.get('is_arra_monitor'):
        #print Article.query.filter(Article.title==article_title).statement
        flash({'type': 'success', 'content': '活动已经取消。'})
        activity = Activity.query.get_or_404(activity_id)
        activity.status = 4
        duties = Duty.query.filter(Duty.aid == activity_id)

        worktimestr = timeformat_filter(activity.work_start_time, "%Y-%m-%d %H:%M")
        timestr = timeformat_filter(activity.start_time, "%Y-%m-%d %H:%M")
        venue = venuename_filter(activity.venue)
        title = activity.title
        remark = activity.remark
        url = config.BASE_URL + url_for('activitydetail', activity_id=activity.id)
        subject = mail.activity_cancle_tmpl['subject']
        content = mail.activity_cancle_tmpl['content'] % (worktimestr, timestr, venue, title, remark, url, url)

        for duty in duties:
            if duty.status == 7 or duty.status == 8:
                msg_id = mail.send_message(duty.uid, session['uid'], subject, content, 2)
                mail.send_mail(subject, content, duty.member.name, duty.member.email,
                               msgid=msg_id, touid=duty.uid, uid=duty.uid, dutyid=duty.id, activityid=duty.aid)

            duty.status = 9
            db.session.add(duty)
        db.session.add(activity)
        db.session.commit()
    else:
        flash({'type': 'danger', 'content': '非法操作,请重试。'})
    return redirect(url_for('activitydetail', activity_id=activity_id))
Пример #2
0
def activityappoint(activity_id, member_uid):
    activity = Activity.query.get_or_404(activity_id)
    if activity.status == 1 and session.get('is_arra_monitor'):
        member = Member.query.get(member_uid)
        if not Duty.query.filter(Duty.aid == activity_id, Duty.uid == member_uid).count():
            duty = Duty()
            duty.aid = activity_id
            duty.uid = member_uid
            duty.status = 4
            duty.log = ''
            duty.appendprocesse('activity_appoint', '排班班长安排值班')
            db.session.add(duty)
            db.session.commit()
            # need or not
            timestr = timeformat_filter(activity.start_time, "%Y-%m-%d %H:%M")
            worktimestr = timeformat_filter(activity.work_start_time, "%Y-%m-%d %H:%M")
            venue = venuename_filter(activity.venue)
            title = activity.title
            remark = activity.remark
            url = config.BASE_URL + url_for('activitydetail', activity_id=activity.id)
            subject = mail.activity_appoint_tmpl['subject']
            content = mail.activity_appoint_tmpl['content'] % (worktimestr, timestr, venue, title, remark, url, url)
            msg_id = mail.send_message(member_uid, session['uid'], subject, content, 2)
            mail.send_mail(subject, content, member.name, member.email,
                           msgid=msg_id, touid=duty.uid, uid=duty.uid, dutyid=duty.id, activityid=duty.aid)

        else:
            flash({'type': 'danger', 'content': '此人已经安排过值班任务。'})
    else:
        flash({'type': 'danger', 'content': '非法操作,请重试。'})
    return redirect(url_for('activitydetail', activity_id=activity_id))
Пример #3
0
def activityedit(activity_id=0):
    if request.method == 'POST':
        form = ActivityForm(request.form)
        if form.validate_on_submit():
            if not form.errors:
                pass#form.username.errors.append('帐号已存在')
        #print form.errors
        if not form.errors:
            activity = Activity.query.get(form.id.data)
            if not session.get('is_arra_monitor'):
                abort(403)
            if not activity:
                activity = Activity()
            info_modify = str(activity.title) != str(form.title.data) or str(activity.venue) != str(form.venue.data) or str(activity.work_start_time) != str(form.work_start_time.data)
            if info_modify:
                dutylist = Duty.query.filter(Duty.aid == activity_id).all()

                worktimestr = timeformat_filter(activity.work_start_time, "%Y-%m-%d %H:%M")
                worktimestr_new = timeformat_filter(form.work_start_time.data, "%Y-%m-%d %H:%M")
                timestr = timeformat_filter(activity.start_time, "%Y-%m-%d %H:%M")
                timestr_new = timeformat_filter(form.start_time.data, "%Y-%m-%d %H:%M")
                venue = venuename_filter(activity.venue)
                venue_new = venuename_filter(form.venue.data)
                title = activity.title
                title_new = form.title.data
                remark = activity.remark
                url = config.BASE_URL + url_for('activitydetail', activity_id=activity.id)
                subject = mail.activity_modify_tmpl['subject']
                content = mail.activity_modify_tmpl['content'] % (worktimestr, worktimestr_new, timestr, timestr_new, venue, venue_new, title, title_new, remark, url, url)
                for duty in dutylist:
                    msg_id = mail.send_message(duty.uid, session['uid'], subject, content, 2)
                    mail.send_mail(subject, content, duty.member.name, duty.member.email,
                                   msgid=msg_id, touid=duty.uid, uid=duty.uid, dutyid=duty.id, activityid=duty.aid)

            activity.title = form.title.data
            activity.remark = form.remark.data
            activity.venue = form.venue.data
            activity.work_start_time = form.work_start_time.data
            activity.start_time = form.start_time.data
            activity.end_time = form.end_time.data
            activity.type = form.type.data
            activity.status = form.status.data
            activity.hostname = form.hostname.data
            db.session.add(activity)
            db.session.commit()

            flash({'type': 'success', 'content': '保存成功!'})
            return redirect('/activitymanage')
        return render_template('activity/activityedit.html', form=form)

    else:
        activity = Activity.query.get(activity_id)
        if not session.get('is_arra_monitor'):
            abort(403)
        form = ActivityForm(obj=activity)
        if Duty.query.filter(Duty.aid == activity_id).count():
            flash({'type': 'warning', 'content': '已有音控员负责此活动,请谨慎操作!'})
        return render_template('activity/activityedit.html', form=form)
Пример #4
0
def register():
    """Page: activity detail"""
    form = RegisterForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            if form.reqcode.data != config.REQCODE:
                form.reqcode.errors.append('邀请码错误')
            if Member.query.filter(Member.uid == form.username.data).count():
                form.username.errors.append('帐号已存在')
            if Member.query.filter(Member.email == form.email.data).count():
                form.email.errors.append('电子邮箱已存在')
            if Member.query.filter(Member.mobile_num == form.mobile_num.data).count():
                form.mobile_num.errors.append('手机号码已存在')
        if not form.errors:
            key = md5.new()
            key.update(form.password.data)
            member = Member()
            member.uid = form.username.data.upper()
            member.name = form.name.data
            member.password = key.hexdigest()
            member.email = form.email.data
            member.mobile_num = form.mobile_num.data
            member.type = 0
            member.update_register_time()
            member.update_lastlogin_time()
            db.session.add(member)
            db.session.commit()

            adminmember = Member.query.get(config.SYS_ADMIN)
            readmeurl = config.BASE_URL + url_for('articledetail', article_title=config.README_TITLE)
            admin_url = config.BASE_URL + url_for('memberdetail', member_uid=config.SYS_ADMIN)
            admin_name = adminmember.name
            subject = mail.register_tmpl['subject']
            content = mail.register_tmpl['content'] % (readmeurl, readmeurl, admin_url, admin_name)
            msg_id = mail.send_message(member.uid, config.SYS_ADMIN, subject, content, 2)
            mail.send_mail(subject, content, member.name, member.email,
                msgid=msg_id, touid=member.uid, uid=member.uid)

            flash({'type': 'success', 'content': '注册成功,请登陆。'})
            if viewtype() == 1:
                return render_template('site/login_mobile.html', form=form)
            else:
                return render_template('site/login.html', form=form)
    if viewtype() == 1:
        return render_template('site/register_mobile.html', form=form)
    else:
        return render_template('site/register.html', form=form)
Пример #5
0
def _register(username, password, name, email, mobile):
    key = md5.new()
    key.update(password)
    member = Member()
    member.uid = username.upper().replace(' ', '')
    member.name = name.replace(' ', '')
    member.password = key.hexdigest()
    member.email = email.replace(' ', '')
    member.mobile_num = mobile.replace(' ', '')
    member.type = 0
    member.update_register_time()
    member.update_lastlogin_time()
    db.session.add(member)
    db.session.commit()

    adminmember = Member.query.get(config.SYS_ADMIN)
    readmeurl = config.BASE_URL + url_for('articledetail', article_title=config.README_TITLE)
    admin_url = config.BASE_URL + url_for('memberdetail', member_uid=config.SYS_ADMIN)
    admin_name = adminmember.name
    subject = mail.register_tmpl['subject']
    content = mail.register_tmpl['content'] % (readmeurl, readmeurl, admin_url, admin_name)
    msg_id = mail.send_message(member.uid, config.SYS_ADMIN, subject, content, 2)
    mail.send_mail(subject, content, member.name, member.email,
                   msgid=msg_id, touid=member.uid, uid=member.uid)
Пример #6
0
def activity_spider(content):
    log = []
    url = 'http://cdzl.student.hust.edu.cn/Api'
    sid2ven = {u'5': 1, u'8': 2, u'10': 3}
    #Fetch contents
    if not content:
        try:
            if config.HTTP_PROXY:
                proxy_handler = urllib2.ProxyHandler({"http": config.HTTP_PROXY})
                opener = urllib2.build_opener(proxy_handler)
                urllib2.install_opener(opener)
            content = urllib2.urlopen(url).read()
        except:
            log.append('Can\'t fetch vrs api')
            content = '{}'
        #print content
        #Parse contents

    activities = json.loads(content)
    oidlist = []
    warnings = []
    for act in activities:
        oid = act['id']
        oidlist.append(str(oid))
        title = act['activity']
        remark = act['remark']
        venue = sid2ven[act['sid']]
        start_time = act['time']
        work_start_time = int(act['time']) - 3600
        # type = activitytypeclassify(title)
        type = 0
        #if exist

        sql = 'select id,venue,title,remark,work_start_time,start_time from activity where oid = "%s";' % oid
        #print sql
        #print 'test oid:'+oid
        res = db.session.execute(sql)
        db.session.commit()
        if not res.rowcount:
            title = title.replace(':', '\:')
            remark = remark.replace(':', '\:')
            sql = 'insert into activity ( oid, title, remark, venue, work_start_time, start_time, type, status) values ("%s", "%s", "%s", "%s", "%s", "%s", "%s", "1");' % (oid, title, remark, venue, work_start_time, start_time, type)
            #print sql
            # help! Done
            new_obj = db.session.execute(sql)
            #print new_obj.lastrowid
            db.session.commit()
            new_id = new_obj.lastrowid
            log.append('New record inserted new_id:%s oid=%s.' % (new_id, oid))
        else:
            d = {}
            for r in res:
                d = {'id': r[0], 'sid': r[1], 'title': r[2], 'remark': r[3], 'worktime': r[4], 'time': r[5]}
            #print d
            if str(title)[:32] != str(d['title'])[:32] or str(remark) != str(d['remark']) or str(venue) != str(d['sid']) or int(start_time) != int(d['time']):
                #sql = 'update activity set title = "%s", remark = "%s", venue = "%s", start_time = "%s" where oid = "%s";' % (title, remark, venue, start_time, oid)
                #db.session.execute(sql)
                #db.session.commit()
                log.append('Same record exists but modified id: %s oid:%s.' % (d['id'], oid))
                if int(d['time']) == int(start_time):
                    timestr_modify = u'%s 不变' % timeformat_filter(d['time'], "%Y-%m-%d %H:%M")
                else:
                    timestr_modify = u'<strong>%s 变为 %s</strong>' % (timeformat_filter(d['time'], "%Y-%m-%d %H:%M"), timeformat_filter(start_time, "%Y-%m-%d %H:%M"))
                if d['sid'] == venue:
                    venue_modify = u'%s 不变' % venuename_filter(d['sid'])
                else:
                    venue_modify = u'<strong>%s 变为 %s</strong>' % (venuename_filter(d['sid']), venuename_filter(venue))
                if d['title'] == title:
                    title_modify = u'%s 不变' % d['title']
                else:
                    title_modify = u'<strong>%s 变为 %s</strong>' % (d['title'], title)
                if d['remark'] == remark:
                    remark_modify = u'%s 不变' % d['remark']
                else:
                    remark_modify = u'<strong>%s 变为 %s</strong>' % (d['remark'], remark)

                activity = Activity.query.get(d['id'])
                url = config.BASE_URL + url_for('activitydetail', activity_id=activity.id)
                #subject = mail.notice_activity_modify_tmpl['subject']
                content = mail.notice_activity_modify_tmpl['content'] % (timestr_modify, venue_modify, title_modify, remark_modify, url, url)
                warnings.append(content)
                #duty_list = Duty.query.filter(Duty.aid==d['id']).all()

                #timestr_old = timeformat_filter(d['time'],"%Y-%m-%d %H:%M")
                #timestr_new = timeformat_filter(start_time,"%Y-%m-%d %H:%M")
                #venue_old = venuename_filter(d['sid'])
                #venue_new = venuename_filter(venue)
                #title_old = d['title']
                #title_new = title
                #activity = Activity.query.get(d['id'])
                #url = config.BASE_URL + url_for('activitydetail',activity_id=activity.id)
                #subject = mail.activity_modify_tmpl['subject']
                #content = mail.activity_modify_tmpl['content'] % ( timestr_old, timestr_new, venue_old, venue_new, title_old, title_new, remark, url, url )
                #for duty in duty_list:
                #    mail.send_message(duty.uid,'ADMIN',subject,content,2)
                #    mail.send_mail(subject, content, duty.uid, duty.member.email)

            else:
                pass#log.append('Same record exists ignore' )
            #print "MySQL Error [%d]: %s" % (e.args[0], e.args[1])
    db.session.commit()

    if oidlist:
        #for oid in oidlist:
        ts = time.localtime()
        todaytime = int(time.time()) - ts.tm_hour * 3600 - ts.tm_min * 60 - ts.tm_sec
        oidstr = ','.join(oidlist)
        sql = 'select id, oid, start_time, venue, title from activity where status != "' + str(CONST.ACTIVITY_CANCELED) + '" and start_time >= "%d" and oid not in( %s);' % (todaytime, oidstr)
        #print sql
        res = db.session.execute(sql)
        for row in res:
            log.append('Record deleted id: %s oid:%s.' % (row[0], row[1]))
            timestr = timeformat_filter(row[2], "%Y-%m-%d %H:%M")
            venue = venuename_filter(row[3])
            title = row[4]
            url = config.BASE_URL + url_for('activitydetail', activity_id=row[0])
            #subject = mail.notice_activity_cancel_tmpl['subject']
            content = mail.notice_activity_cancel_tmpl['content'] % (timestr, venue, title, url, url)
            warnings.append(content)

    log.append('Success on %s.' % time.strftime('%Y-%m-%d %H:%M:%S'))

    if warnings:
        now = int(time.time())
        nowstr = timeformat_filter(now, "%Y-%m-%d %H:%M:%S")

        subject = mail.spider_notice_tmpl['subject']
        content = mail.spider_notice_tmpl['content'] % nowstr + '<hr />'.join(warnings)
        for uid in config.ARRA_MONITOR:
            member = Member.query.get(uid)
            if notify.is_notify(uid, notify.NOTIFY_MESSAGE, notify.NOTIFY_SPIDER):
                msg_id = mail.send_message(uid, config.SYS_ADMIN, subject, content, 2)
            else:
                msg_id = 0
            if notify.is_notify(uid, notify.NOTIFY_EMAIL, notify.NOTIFY_SPIDER):
                mail.send_mail(subject, content, member.name, member.email, msgid=msg_id)
            if notify.is_notify(uid, notify.NOTIFY_APP, notify.NOTIFY_SPIDER):
                push_alias(uid, subject, content=content, msgid=msg_id)
                pass  # TODO app notify
            if notify.is_notify(uid, notify.NOTIFY_SMS, notify.NOTIFY_SPIDER):
                pass  #

    return log
Пример #7
0
def cron():
    try:
        last_cron = int(open(config.BASE_DIR + 'data/last_cron.time', 'r').read())
    except:
        last_cron = 0
    now = int(time.time())
    nowstr = timeformat_filter(now, "%Y-%m-%d %H:%M:%S")
    if last_cron / (30 * 60) < now / (30 * 60):
        now = now / (30 * 60) * (30 * 60)
        logs = []
        # 1 hours before activity start
        activitylist = Activity.query.filter(Activity.work_start_time == now + 3600, Activity.status == 1).all()
        for activity in activitylist:
            work_timestr = timeformat_filter(activity.work_start_time, "%Y-%m-%d %H:%M")
            timestr = timeformat_filter(activity.start_time, "%Y-%m-%d %H:%M")
            venue = venuename_filter(activity.venue)
            title = activity.title
            remark = activity.remark
            url = config.BASE_URL + url_for('activitydetail', activity_id=activity.id)
            subject = mail.activity_nearly_begin_tmpl['subject']
            content = mail.activity_nearly_begin_tmpl['content'] % (work_timestr, timestr, venue, title, remark, url, url)
            # TODO %d or %s ?
            logs.append("%s: Activity almost start id:%d" % (nowstr, activity.id))
            for duty in activity.duties:
                #print subject, content, duty.member.name, duty.member.email, subject, content
                if duty.status == 7 or duty.status == 8:
                    mail.send_mail(subject, content, duty.member.name, duty.member.email,
                                   touid=duty.uid, uid=duty.uid, dutyid=duty.id, activityid=duty.aid)
                    logs.append("%s: Send mail to %s" % (nowstr, duty.uid))

        # on activity start
        activitylist = Activity.query.filter(Activity.start_time == now, Activity.status == 1).all()
        dutylist = Duty.query.join(Activity).filter(Activity.start_time == now, Activity.status == 1, or_(Duty.status == 6, Duty.status == 7)).all()
        for activity in activitylist:
            logs.append("%s : Activity starts, change activity status id:%d" % (nowstr, activity.id))
            activity.status = 2
            db.session.add(activity)
        # TODO other duty status
        for duty in dutylist:
            logs.append("%s : Activity starts, change duty status id:%d" % (nowstr, duty.id))
            duty.status = 10
            db.session.add(duty)
        db.session.commit()

        # 6 hours after activity start

        ts = time.localtime(now)
        if ts.tm_hour == 20 and ts.tm_min == 0 and ts.tm_sec == 0:
            # auto sync
            sync()
        if ts.tm_hour == 21 and ts.tm_min == 30 and ts.tm_sec == 0:
            range_start = 86400 + now - 21 * 3600 - 1800
            range_end = 2 * 86400 + now + 2 * 3600 + 1800
            activitylist = Activity.query.filter(Activity.start_time >= range_start, Activity.start_time < range_end, Activity.status == 1).all()
            warnings = []
            for activity in activitylist:
                ready_num = 0
                for duty in activity.duties:
                    if duty.status in [1, 2, 4, 6, 7]:
                        ready_num += 1
                    if duty.status in [1, 2, 4]:
                        membername = duty.member.name
                        memberurl = url_for('memberdetail', member_uid=duty.uid)
                        worktimestr = timeformat_filter(activity.work_start_time, "%Y-%m-%d %H:%M")
                        timestr = timeformat_filter(activity.start_time, "%Y-%m-%d %H:%M")
                        venue = venuename_filter(activity.venue)
                        title = activity.title
                        url = config.BASE_URL + url_for('activitydetail', activity_id=activity.id)
                        statusname = dutystatusname_filter(duty.status)
                        content = mail.todo_duty_tmpl['content'] % (memberurl, membername, worktimestr, timestr, venue, title, url, url, statusname)
                        warnings.append(content)
                if ready_num == 0:
                    timestr = timeformat_filter(activity.start_time, "%Y-%m-%d %H:%M")
                    venue = venuename_filter(activity.venue)
                    title = activity.title
                    url = config.BASE_URL + url_for('activitydetail', activity_id=activity.id)
                    content = mail.todo_activity_tmpl['content'] % (timestr, venue, title, url, url)
                    warnings.append(content)

            if warnings:
                now = int(time.time())
                nowstr = timeformat_filter(now, "%Y-%m-%d %H:%M:%S")

                subject = mail.todo_notice_tmpl['subject']
                content = mail.todo_notice_tmpl['content'] + '<hr />'.join(warnings)
                for uid in config.ARRA_MONITOR:
                    member = Member.query.get(uid)
                    msg_id = mail.send_message(uid, config.SYS_ADMIN, subject, content, 2)
                    mail.send_mail(subject, content, member.name, member.email,
                        msgid=msg_id)

        if ts.tm_hour == 22 and ts.tm_min == 30 and ts.tm_sec == 0:
            activitylist = Activity.query.filter(Activity.start_time >= now - 22 * 3600 - 1800, Activity.start_time < now + 3600 + 1800, Activity.status == 2).all()
            for activity in activitylist:
                worktimestr = timeformat_filter(activity.work_start_time, "%Y-%m-%d %H:%M")
                timestr = timeformat_filter(activity.start_time, "%Y-%m-%d %H:%M")
                venue = venuename_filter(activity.venue)
                title = activity.title
                remark = activity.remark
                url = config.BASE_URL + url_for('activitydetail', activity_id=activity.id)
                subject = mail.activity_mark_endtime_tmpl['subject']
                content = mail.activity_mark_endtime_tmpl['content'] % (worktimestr, timestr, venue, title, remark, url, url)
                logs.append("%s : Activity almost end id:%d" % (nowstr, activity.id))
                for duty in activity.duties:
                    if duty.status == 10:
                        #print subject, content
                        mail.send_mail(subject, content, duty.member.name, duty.member.email,
                                       touid=duty.uid, uid=duty.uid, dutyid=duty.id, activityid=duty.aid)
                        logs.append("%s : Send mail to %s" % (nowstr, duty.uid))

        open(config.BASE_DIR + 'data/last_cron.time', 'w').write(str(now))

        try:
            fp = open(config.BASE_DIR + 'log/cron.log', 'a')
        except:
            fp = open(config.BASE_DIR + 'log/cron.log', 'w')
        fp.write("crontab %s : %d\n" % (nowstr, now))
        for log in logs:
            fp.write("%s\n" % log)
        fp.close()

        return "now" + str(now)
    else:
        try:
            fp = open(config.BASE_DIR + 'log/cron.log', 'a')
        except:
            fp = open(config.BASE_DIR + 'log/cron.log', 'w')
        fp.write("crontab_last %s : %d\n" % (nowstr, now))
        fp.close()
        return "last_cron" + str(last_cron)
Пример #8
0
def activityopeartion(opeartion, duty_id):
    duty = Duty.query.get_or_404(duty_id)
    if duty.activity.status == 1 and (not Duty.query.filter(Duty.id != duty_id, Duty.uid == session['uid'], Duty.aid == duty.aid).count()) and \
            ((session['uid'] == duty.member.uid and opeartion in CONST.duty_status_opeartion_selfuser_mapper[duty.status]) or
            (session['uid'] != duty.member.uid and opeartion in CONST.duty_status_opeartion_otheruser_mapper[duty.status]) or
            (session.get('is_arra_monitor') and opeartion in CONST.duty_status_opeartion_monitor_mapper[duty.status])):
        #print Article.query.filter(Article.title==article_title).statement
        if request.method == 'POST':
            reason = request.form['content']
        else:
            reason = ''
        if CONST.dutyoperationname[opeartion].has_key('require_input') and not reason:
            flash({'type': 'error', 'content': '请填写申请理由。'})
            return redirect(url_for('activitydetail', activity_id=duty.aid))

        if opeartion == 'cover_duty':
            if Duty.query.filter(Duty.uid == session['uid'], Duty.aid == duty.aid).count():
                flash({'type': 'danger', 'content': '你在本时间段已经有此活动,请勿重复选班。'})
                return redirect(url_for('activitydetail', activity_id=duty.aid))
            else:
                worktimestr = timeformat_filter(duty.activity.work_start_time, "%Y-%m-%d %H:%M")
                timestr = timeformat_filter(duty.activity.start_time, "%Y-%m-%d %H:%M")
                venue = venuename_filter(duty.activity.venue)
                title = duty.activity.title
                remark = duty.activity.remark
                url = config.BASE_URL + url_for('activitydetail', activity_id=duty.activity.id)
                member_url = config.BASE_URL + url_for('memberdetail', member_uid=session['uid'])
                member_name = session['name']
                subject = mail.cover_duty_tmpl['subject']
                content = mail.cover_duty_tmpl['content'] % (member_url, member_name, worktimestr, timestr, venue, title, remark, url, url)
                msg_id = mail.send_message(duty.uid, session['uid'], subject, content, 2)
                mail.send_mail(subject, content, duty.member.name, duty.member.email,
                               msgid=msg_id, touid=duty.uid, uid=duty.uid, dutyid=duty.id, activityid=duty.aid)

                new_duty = Duty(aid=duty.aid, uid=session['uid'], status=6, log='')
                new_duty.appendprocesse('cover_duty', '')
                db.session.add(new_duty)
        elif opeartion == 'approve_apply' or opeartion == 'decline_apply':
            worktimestr = timeformat_filter(duty.activity.work_start_time, "%Y-%m-%d %H:%M")
            timestr = timeformat_filter(duty.activity.start_time, "%Y-%m-%d %H:%M")
            venue = venuename_filter(duty.activity.venue)
            title = duty.activity.title
            remark = duty.activity.remark
            url = config.BASE_URL + url_for('activitydetail', activity_id=duty.activity.id)
            if opeartion == 'approve_apply':
                subject = mail.approve_apply_tmpl['subject']
                content = mail.approve_apply_tmpl['content'] % (worktimestr, timestr, venue, title, remark, url, url)
            else:
                subject = mail.decline_apply_tmpl['subject']
                content = mail.decline_apply_tmpl['content'] % (worktimestr, timestr, venue, title, remark, url, url)
            msg_id = mail.send_message(duty.uid, session['uid'], subject, content, 2)
            mail.send_mail(subject, content, duty.member.name, duty.member.email,
                           msgid=msg_id, touid=duty.uid, uid=duty.uid, dutyid=duty.id, activityid=duty.aid)
        elif opeartion == 'decline_duty':
            uname = session['name']
            worktimestr = timeformat_filter(duty.activity.work_start_time, "%Y-%m-%d %H:%M")
            timestr = timeformat_filter(duty.activity.start_time, "%Y-%m-%d %H:%M")
            venue = venuename_filter(duty.activity.venue)
            title = duty.activity.title
            remark = duty.activity.remark
            url = config.BASE_URL + url_for('activitydetail', activity_id=duty.activity.id)
            subject = mail.decline_duty_tmpl['subject']
            content = mail.decline_duty_tmpl['content'] % (uname, reason, worktimestr, timestr, venue, title, remark, url, url)
            for uid in config.ARRA_MONITOR:
                member = Member.query.get(uid)
                msg_id = mail.send_message(uid, session['uid'], subject, content, 2)
                mail.send_mail(subject, content, member.name, member.email,
                               msgid=msg_id, touid=uid, uid=duty.uid, dutyid=duty.id, activityid=duty.aid)

        elif opeartion == 'cancle_task':
            pass#timestr = timeformat_filter(duty.activity.start_time,"%Y-%m-%d %H:%M")
            #venue = venuename_filter(duty.activity.venue)
            #title = duty.activity.title
            #remark = duty.activity.remark
            #url = config.BASE_URL + url_for('activitydetail',activity_id=duty.activity.id)
            #subject = mail.approve_apply_tmpl['subject']
            #content = mail.approve_apply_tmpl['content'] % ( timestr, venue, title, remark, url , url )
            #msg_id = mail.send_message(duty.uid,session['uid'],subject,content,2)
            #mail.send_mail(subject, content, duty.member.name, duty.member.email, msg_id)

        duty.status = CONST.duty_status_opeartion_next[opeartion]
        duty.appendprocesse(opeartion, reason)
        db.session.add(duty)
        db.session.commit()
        flash({'type': 'success', 'content': '操作成功!'})
    else:
        flash({'type': 'danger', 'content': '非法操作,请重试。'})
    return redirect(url_for('activitydetail', activity_id=duty.aid))