def timeManagementYearlyPlanEdit(id): yearlyPlan = YearlyPlan.objects(id=id).first() levels = current_app.config['PLAN_LEVEL'] if request.method == 'GET': return render_template('admin/timeManagementYearlyPlanEdit.html', levels=levels, yearlyPlan=yearlyPlan, startTime=str(yearlyPlan.startTime).split(' ')[0], endTime=str(yearlyPlan.endTime).split(' ')[0]) if request.method == 'POST': title = request.form['title'] startTime = request.form['startTime'] endTime = request.form['endTime'] planLevel = request.form.getlist('planLevel[]') planTitle = request.form.getlist('planTitle[]') isDone = request.form.getlist('isDone[]') if not strLength(title,1,100): return jsonify({'status': False, 'info': u'请输入1-100个字符的年计划标题'}) if not startTime or not endTime: return jsonify({'status': False, 'info': u'请选择时间范围'}) startTime = strToDatetime('%s 00:00:00' % startTime) endTime = strToDatetime('%s 23:59:59' % endTime) if endTime <= startTime: return jsonify({'status': False, 'info': u'结束时间要晚于开始时间'}) # 判断年计划时间是否冲突 yps = YearlyPlan.objects for i in yps: if i == yearlyPlan: continue if not (startTime > i.endTime or endTime < i.startTime): return jsonify({'status': False, 'info': u'年计划时间范围(%s - %s)与其他年计划时间(%s - %s)冲突!' % (startTime, endTime, i.startTime, i.endTime)}) plans = [] for index, t in enumerate(planTitle): if len(t)>0: p = Plan() p.title = t p.level = planLevel[index] if isDone[index] == 'y': p.isDone = True else: p.isDone = False plans.append(p) yearlyPlan.title = title yearlyPlan.startTime = startTime yearlyPlan.endTime = endTime yearlyPlan.plans = plans yearlyPlan.save() return jsonify({'status': True, 'info': u'年计划修改成功'})
def timeManagementWeeklyPlanAdd(): title = request.form['title'] monthlyPlanId = request.form['monthlyPlanId'] startTime = request.form['startTime'] endTime = request.form['endTime'] planLevel = request.form.getlist('planLevel[]') planTitle = request.form.getlist('planTitle[]') if not strLength(title,1,100): return jsonify({'status': False, 'info': u'请输入1-100个字符的周计划标题!'}) if not startTime or not endTime: return jsonify({'status': False, 'info': u'请选择时间范围!'}) startTime = strToDatetime('%s 00:00:00' % startTime) endTime = strToDatetime('%s 23:59:59' % endTime) if endTime <= startTime: return jsonify({'status': False, 'info': u'结束时间必须要晚于开始时间!'}) m = MonthlyPlan.objects(id=monthlyPlanId).first() #时间范围判断 #周计划的时间范围必须在月计划的时间范围内 if not (startTime>=m.startTime and endTime<=m.endTime): return jsonify({'status': False, 'info': u'周计划的时间范围必须在月计划的时间范围内!'}) #该年计划下的月计划时间范围不冲突 wps = WeeklyPlan.objects(monthlyPlan=m) for i in wps: if not (startTime >= i.endTime or endTime <= i.startTime): return jsonify({'status': False, 'info': u'周计划的时间范围(%s - %s)和“%s”的时间范围(%s - %s)冲突' % (startTime,endTime,i.title,i.startTime,i.endTime)}) plans = [] for index, t in enumerate(planTitle): if len(t) > 0: p = Plan() p.title = t p.level = planLevel[index] plans.append(p) w = WeeklyPlan() w.title = title w.startTime = startTime w.endTime = endTime w.plans = plans w.monthlyPlan = m w.save() return jsonify({'status': True, 'info': u'周计划添加成功!'})
def timeManagementMonthlyPlanAdd(): title = request.form['title'] yearlyPlanId = request.form['yearlyPlanId'] startTime = request.form['startTime'] endTime = request.form['endTime'] planLevel = request.form.getlist('planLevel[]') planTitle = request.form.getlist('planTitle[]') if not strLength(title,1,100): return jsonify({'status': False, 'info': u'请输入1-100个字符的月计划标题!'}) if not startTime or not endTime: return jsonify({'status': False, 'info': u'请选择时间范围'}) startTime = strToDatetime('%s 00:00:00' % startTime) endTime = strToDatetime('%s 23:59:59' % endTime) if endTime <= startTime: return jsonify({'status': False, 'info': u'结束时间必须要晚于开始时间'}) y = YearlyPlan.objects(id=yearlyPlanId).first() #时间范围判断 #月计划的时间范围必须在年计划的时间范围内 if not (startTime>=y.startTime and endTime<=y.endTime): return jsonify({'status': False, 'info': u'月计划的时间范围必须在年计划的时间范围内'}) #该年计划下的月计划时间范围不冲突 mps = MonthlyPlan.objects(yearlyPlan=y) for i in mps: if not (startTime >= i.endTime or endTime <= i.startTime): return jsonify({'status': False, 'info': u'月计划的时间范围(%s - %s)和“%s”的时间范围(%s - %s)冲突' % (startTime,endTime,i.title,i.startTime,i.endTime)}) plans = [] for index, t in enumerate(planTitle): if len(t) > 0: p = Plan() p.title = t p.level = planLevel[index] plans.append(p) m = MonthlyPlan() m.title = title m.startTime = startTime m.endTime = endTime m.plans = plans m.yearlyPlan = y m.save() return jsonify({'status': True, 'info': u'月计划添加成功'})
def timeManagementYearlyPlanAdd(): title = request.form['title'] startTime = request.form['startTime'] endTime = request.form['endTime'] planLevel = request.form.getlist('planLevel[]') planTitle = request.form.getlist('planTitle[]') if not strLength(title,1,100): return jsonify({'status': False, 'info': u'请输入1-100个字符的年计划标题'}) if not startTime or not endTime: return jsonify({'status': False, 'info': u'请选择时间范围'}) startTime = strToDatetime('%s 00:00:00' % startTime) endTime = strToDatetime('%s 23:59:59' % endTime) if endTime <= startTime: return jsonify({'status': False, 'info': u'结束时间必须要晚于开始时间'}) #判断年计划时间是否冲突 yps = YearlyPlan.objects for i in yps: if not (startTime>i.endTime or endTime<i.startTime): return jsonify({'status': False, 'info': u'年计划时间范围(%s - %s)与其他年计划时间(%s - %s)冲突!' % (startTime,endTime,i.startTime,i.endTime)}) plans = [] for index, t in enumerate(planTitle): if len(t) > 0: p = Plan() p.title = t p.level = planLevel[index] plans.append(p) yearlyPlan = YearlyPlan() yearlyPlan.title = title yearlyPlan.startTime = startTime yearlyPlan.endTime = endTime yearlyPlan.plans = plans yearlyPlan.save() return jsonify({'status': True, 'info': u'年计划添加成功'})
def timeManagementDailyPlanEdit(id): d = DailyPlan.objects(id=id).first() if request.method == 'GET': levels = current_app.config['PLAN_LEVEL'] wps = WeeklyPlan.objects.order_by('-id')[:12] return render_template('admin/timeManagementDailyPlanEdit.html', levels=levels, d=d, wps=wps) if request.method == 'POST': weeklyPlanId = request.form['weeklyPlanId'].strip() whichDay = request.form['whichDay'].strip() planLevel = request.form.getlist('planLevel[]') planTitle = request.form.getlist('planTitle[]') isDone = request.form.getlist('isDone[]') try: whichDayTemp = strToDatetime('%s 00:00:00' % whichDay) except: return jsonify({'status': False, 'info': u'请输入正确的时间格式!'}) w = WeeklyPlan.objects(id=weeklyPlanId).first() # 时间范围判断 # 日计划的时间范围必须在周计划的时间范围内 if not (whichDayTemp >= w.startTime and whichDayTemp <= w.endTime): return jsonify({'status': False, 'info': u'日计划的时间范围必须在周计划的时间范围内!'}) # 该周计划下的日计划时间范围不冲突 dps = DailyPlan.objects(weeklyPlan=w) for i in dps: if d == i:continue if i.whichDay == whichDay: return jsonify({'status': False, 'info': u'该日期 “%s” 已经有日计划了!' % whichDay}) plans = [] for index, t in enumerate(planTitle): if len(t) > 0: p = Plan() p.title = t.strip() p.level = planLevel[index].strip() if isDone[index] == 'y': p.isDone = True else: p.isDone = False plans.append(p) d.title = "%s日计划" % whichDay d.whichDay = whichDay d.plans = plans d.weeklyPlan = w d.save() return jsonify({'status': True, 'info': u'日计划修改成功!'})
def timeManagementDailyPlanAdd(): weeklyPlanId = request.form['weeklyPlanId'].strip() whichDay = request.form['whichDay'].strip() planLevel = request.form.getlist('planLevel[]') planTitle = request.form.getlist('planTitle[]') print (planLevel) try: whichDayTemp = strToDatetime('%s 00:00:00' % whichDay) except: return jsonify({'status': False, 'info': u'请输入正确的时间格式!'}) w = WeeklyPlan.objects(id=weeklyPlanId).first() #时间范围判断 #日计划的时间范围必须在周计划的时间范围内 if not (whichDayTemp>=w.startTime and whichDayTemp<=w.endTime): return jsonify({'status': False, 'info': u'日计划的时间范围必须在周计划的时间范围内!'}) #该周计划下的日计划时间范围不冲突 dps = DailyPlan.objects(weeklyPlan=w) for i in dps: if i.whichDay == whichDay: return jsonify({'status': False, 'info': u'该日期 “%s” 已经有日计划了!' % whichDay}) plans = [] for index, t in enumerate(planTitle): if len(t) > 0: p = Plan() p.title = t.strip() p.level = planLevel[index].strip() plans.append(p) d = DailyPlan() d.title = "%s日计划" % whichDay d.whichDay = whichDay d.plans = plans d.weeklyPlan = w d.save() return jsonify({'status': True, 'info': u'日计划添加成功!'})
def timeManagementWeeklyPlanEdit(id): w = WeeklyPlan.objects(id=id).first() if request.method == 'GET': levels = current_app.config['PLAN_LEVEL'] mps = MonthlyPlan.objects.order_by('-id')[:12] return render_template('admin/timeManagementWeeklyPlanEdit.html', levels=levels, w=w, mps=mps, startTime=str(w.startTime).split(' ')[0], endTime=str(w.endTime).split(' ')[0]) if request.method == 'POST': title = request.form['title'] monthlyPlanId = request.form['monthlyPlanId'] startTime = request.form['startTime'] endTime = request.form['endTime'] planLevel = request.form.getlist('planLevel[]') planTitle = request.form.getlist('planTitle[]') isDone = request.form.getlist('isDone[]') if not strLength(title, 1, 100): return jsonify({'status': False, 'info': u'请输入1-100个字符的周计划标题!'}) if not startTime or not endTime: return jsonify({'status': False, 'info': u'请选择时间范围!'}) startTime = strToDatetime('%s 00:00:00' % startTime) endTime = strToDatetime('%s 23:59:59' % endTime) if endTime <= startTime: return jsonify({'status': False, 'info': u'结束时间必须要晚于开始时间!'}) m = MonthlyPlan.objects(id=monthlyPlanId).first() # 时间范围判断 # 周计划的时间范围必须在月计划的时间范围内 if not (startTime >= m.startTime and endTime <= m.endTime): return jsonify({'status': False, 'info': u'周计划的时间范围必须在月计划的时间范围内!'}) # 该月计划下的周计划时间范围不冲突 wps = WeeklyPlan.objects(monthlyPlan=m) for i in wps: if i==w:continue if not (startTime >= i.endTime or endTime <= i.startTime): return jsonify({'status': False, 'info': u'周计划的时间范围(%s - %s)和“%s”的时间范围(%s - %s)冲突' % (startTime, endTime, i.title, i.startTime, i.endTime)}) plans = [] for index, t in enumerate(planTitle): if len(t) > 0: p = Plan() p.title = t p.level = planLevel[index] if isDone[index] == 'y': p.isDone = True else: p.isDone = False plans.append(p) w.title = title w.startTime = startTime w.endTime = endTime w.plans = plans w.monthlyPlan = m w.save() return jsonify({'status': True, 'info': u'周计划修改成功!'})