def club_schedule(request, id): club = Club.objects.get(id=id) path = reverse("club_page", kwargs={"id":club.id}) schedule_form = ScheduleForm(request.POST or None, prefix='schedule') if request.method == 'POST': if schedule_form.is_valid(): schedule_text = schedule_form.cleaned_data['text'] schedule_duedate = schedule_form.cleaned_data['duedate'] new_form = Schedule() new_form.user = request.user new_form.club = club new_form.text = schedule_text new_form.duedate = schedule_duedate new_form.choice = 'club' new_form.save() response_data = {} response_data['response'] = True new_data = json.dumps(response_data) return HttpResponse(new_data, content_type='application/json') else: data = {} data['response'] = False new_data = json.dumps(data) return HttpResponse(new_data, content_type='application/json')
def add_schedule(request): play = request.POST['play'] studio = request.POST['studio'] show_time = request.POST['show_time'] ticket_money = request.POST['money'] str_showtime = show_time.replace( 'T', ' ') # 把时间2019-05-05T13:30格式化为2019-05-05 13:30 datetime_showtime = datetime.datetime.strptime( str_showtime, "%Y-%m-%d %H:%M") # 把字符串转化为datetime时间,因为下面要进行加法计算 play_obj = get_object_or_404(Play, id=play) datetime_endtime = datetime_showtime + datetime.timedelta( minutes=play_obj.length) end_time = datetime_endtime.strftime( "%Y-%m-%dT%H:%M") # datetime时间转化为字符串时间 studio_obj = get_object_or_404(Studio, id=studio) ticket_counts = studio_obj.seat_rows * studio_obj.seat_cols ticket_all_counts = studio_obj.seat_rows * studio_obj.seat_cols # print(play, studio, show_time, ticket_money, ticket_counts, '---------------') schedule = Schedule(play=play_obj, studio=studio_obj, show_time=show_time, end_time=end_time, ticket_counts=ticket_counts, ticket_money=float(ticket_money), ticket_all_counts=ticket_all_counts) schedule.save() return redirect(reverse('schedule_list'))
def add_schedule(request): if request.POST: time_frame = request.POST.get('time_frame') description = request.POST.get('description') priority = request.POST.get('priority') is_done = request.POST.get('is_done') user_id = request.POST.get('user_id') print(user_id) print(is_done) try: sch_obj = Schedule(time_frame=time_frame, description=description, priority=priority, is_done=is_done, user_id=user_id) sch_obj.save() return render(request, 'schedule/add.html', {'message': '时间表添加成功'}) except: print('fail to add') return render(request, 'schedule/add.html', {'message': '时间表添加失败'}) else: return render(request, 'schedule/add.html')
def add_schedule(request): ''' 新增上线计划 ''' servers = Server.objects.order_by('saltid') softforms = SoftForm.objects.order_by('soft_type') apppackages = AppPackage.objects.order_by('package_name') actiongroupss = ActionGroup.objects.order_by('name') testcases = Testcase.objects.order_by('name') if request.POST: schedule_id = request.POST.get('schedule_id', None) # 上线计划单号。唯一标识 service_name = request.POST.get('service_name', None) # 服务名称。唯一标识 department = request.POST.get('department', None) # 上线部署部门 department_dep = request.POST.get('department_dep', None) # 研发部门 contact = request.POST.get('contact', None) # 联系人 contact_info = request.POST.get('contact_info', None) # 联系信息 auto_rollback = request.POST.get('auto_rollback', None) # 自动回滚标识。 0:自动回滚;1:不自动回滚; server_ids = request.POST.getlist('server_ids', None) # 服务器组 softform_ids = request.POST.getlist('softform_ids', None) # 基础应用模板组 apppackage_ids = request.POST.getlist('apppackage_ids', None) # 应用服务组 actiongroup_ids = request.POST.getlist('actiongroup_ids', None) # 操作流程 testcase_ids = request.POST.getlist('testcase_ids', None) # 测试用例组 schedule = Schedule.objects.filter(schedule_id__exact = schedule_id) if schedule: return HttpResponse(simplejson.dumps({"statusCode": 302, "navTabId": request.POST.get('navTabId', 'scheduleindex'), "callbackType": request.POST.get('callbackType', None), "message": u'此上线计划已存在,不能添加', "info": u'此上线计划已存在,不能添加', "result": u'此上线计划已存在,不能添加'}), mimetype='application/json') schedule = Schedule(schedule_id = schedule_id, service_name=service_name, user_name = request.user.username, department = department, department_dep = department_dep, contact = contact, contact_info = contact_info, auto_rollback = auto_rollback, executive_state = 1) schedule.save() if server_ids != None and len(server_ids) != 0: for server_id in server_ids: server = Server.objects.get(id__exact = server_id) schedule.server_group.add(server) if softform_ids != None and len(softform_ids) != 0: for softform_id in softform_ids: softform = SoftForm.objects.get(id__exact = softform_id) schedule.softform_group.add(softform) if apppackage_ids != None and len(apppackage_ids) != 0: for apppackage_id in apppackage_ids: apppackage = AppPackage.objects.get(id__exact = apppackage_id) schedule.apppackage_group.add(apppackage) if actiongroup_ids != None and len(actiongroup_ids) != 0: for actiongroup_id in actiongroup_ids: actiongroup = ActionGroup.objects.get(id__exact = actiongroup_id) schedule.actiongroups.add(actiongroup) if testcase_ids != None and len(testcase_ids) != 0: for testcase_id in testcase_ids: testcase = Testcase.objects.get(id__exact = testcase_id) schedule.testcase_group.add(testcase) Log(username = request.user.username, content = u"上线计划" + schedule_id + u"添加成功").save() return HttpResponse(simplejson.dumps({"statusCode": 200, "navTabId": request.POST.get('navTabId', 'scheduleindex'), "callbackType": request.POST.get('callbackType', 'closeCurrent'), "message": u'上线计划' + schedule_id + u'添加成功'}), mimetype='application/json') return render_to_response('schedule/add.html', {'servers': servers, 'softforms': softforms, 'apppackages': apppackages, 'actiongroupss': actiongroupss, 'testcases': testcases})
def schedule(request): if request.method == 'GET': if (Schedule.objects.last() is None) or (Schedule.objects.last().date != datetime.date.today()): form_1 = ScheduleForm(initial=get_default_json(1)) form_2 = ScheduleForm(initial=get_default_json(2)) form_3 = ScheduleForm(initial=get_default_json(3)) form_4 = ScheduleForm(initial=get_default_json(4)) form_5 = ScheduleForm(initial=get_default_json(5)) form_6 = ScheduleForm(initial=get_default_json(6)) form_7 = ScheduleForm(initial=get_default_json(7)) form_8 = ScheduleForm(initial=get_default_json(8)) form_9 = ScheduleForm(initial=get_default_json(9)) form_10 = ScheduleForm(initial=get_default_json(10)) form_11 = ScheduleForm(initial=get_default_json(11)) form_12 = ScheduleForm(initial=get_default_json(12)) form_13 = ScheduleForm(initial=get_default_json(13)) form_14 = ScheduleForm(initial=get_default_json(14)) form_15 = ScheduleForm(initial=get_default_json(15)) form_16 = ScheduleForm(initial=get_default_json(16)) form_17 = ScheduleForm(initial=get_default_json(17)) form_18 = ScheduleForm(initial=get_default_json(18)) form_19 = ScheduleForm(initial=get_default_json(19)) form_20 = ScheduleForm(initial=get_default_json(20)) form_21 = ScheduleForm(initial=get_default_json(21)) form_22 = ScheduleForm(initial=get_default_json(22)) form_23 = ScheduleForm(initial=get_default_json(23)) form_24 = ScheduleForm(initial=get_default_json(24)) form_25 = ScheduleForm(initial=get_default_json(25)) form_26 = ScheduleForm(initial=get_default_json(26)) form_27 = ScheduleForm(initial=get_default_json(27)) form_28 = ScheduleForm(initial=get_default_json(28)) form_29 = ScheduleForm(initial=get_default_json(29)) form_30 = ScheduleForm(initial=get_default_json(30)) form_31 = ScheduleForm(initial=get_default_json(31)) form_32 = ScheduleForm(initial=get_default_json(32)) form_33 = ScheduleForm(initial=get_default_json(33)) form_34 = ScheduleForm(initial=get_default_json(34)) form_35 = ScheduleForm(initial=get_default_json(35)) form_36 = ScheduleForm(initial=get_default_json(36)) form_37 = ScheduleForm(initial=get_default_json(37)) form_38 = ScheduleForm(initial=get_default_json(38)) form_39 = ScheduleForm(initial=get_default_json(39)) form_40 = ScheduleForm(initial=get_default_json(40)) form_41 = ScheduleForm(initial=get_default_json(41)) form_42 = ScheduleForm(initial=get_default_json(42)) form_43 = ScheduleForm(initial=get_default_json(43)) form_44 = ScheduleForm(initial=get_default_json(44)) form_45 = ScheduleForm(initial=get_default_json(45)) form_46 = ScheduleForm(initial=get_default_json(46)) form_47 = ScheduleForm(initial=get_default_json(47)) form_48 = ScheduleForm(initial=get_default_json(48)) else: schedule_object = Schedule.objects.all().order_by('-date')[:1][0] objects = [schedule_object.slot_1, schedule_object.slot_2, schedule_object.slot_3, schedule_object.slot_4, schedule_object.slot_5, schedule_object.slot_6, schedule_object.slot_7, schedule_object.slot_8, schedule_object.slot_9, schedule_object.slot_10, schedule_object.slot_11, schedule_object.slot_12, schedule_object.slot_13, schedule_object.slot_14, schedule_object.slot_15, schedule_object.slot_16, schedule_object.slot_17, schedule_object.slot_18, schedule_object.slot_19, schedule_object.slot_20, schedule_object.slot_21, schedule_object.slot_22, schedule_object.slot_23, schedule_object.slot_24, schedule_object.slot_25, schedule_object.slot_26, schedule_object.slot_27, schedule_object.slot_28, schedule_object.slot_29, schedule_object.slot_30, schedule_object.slot_31, schedule_object.slot_32, schedule_object.slot_33, schedule_object.slot_34, schedule_object.slot_35, schedule_object.slot_36, schedule_object.slot_37, schedule_object.slot_38, schedule_object.slot_39, schedule_object.slot_40, schedule_object.slot_41, schedule_object.slot_42, schedule_object.slot_43, schedule_object.slot_44, schedule_object.slot_45, schedule_object.slot_46, schedule_object.slot_47, schedule_object.slot_48, ] form_1 = ScheduleForm(initial=objects[0]) form_2 = ScheduleForm(initial=objects[1]) form_3 = ScheduleForm(initial=objects[2]) form_4 = ScheduleForm(initial=objects[3]) form_5 = ScheduleForm(initial=objects[4]) form_6 = ScheduleForm(initial=objects[5]) form_7 = ScheduleForm(initial=objects[6]) form_8 = ScheduleForm(initial=objects[7]) form_9 = ScheduleForm(initial=objects[8]) form_10 = ScheduleForm(initial=objects[9]) form_11 = ScheduleForm(initial=objects[10]) form_12 = ScheduleForm(initial=objects[11]) form_13 = ScheduleForm(initial=objects[12]) form_14 = ScheduleForm(initial=objects[13]) form_15 = ScheduleForm(initial=objects[14]) form_16 = ScheduleForm(initial=objects[15]) form_17 = ScheduleForm(initial=objects[16]) form_18 = ScheduleForm(initial=objects[17]) form_19 = ScheduleForm(initial=objects[18]) form_20 = ScheduleForm(initial=objects[19]) form_21 = ScheduleForm(initial=objects[20]) form_22 = ScheduleForm(initial=objects[21]) form_23 = ScheduleForm(initial=objects[22]) form_24 = ScheduleForm(initial=objects[23]) form_25 = ScheduleForm(initial=objects[24]) form_26 = ScheduleForm(initial=objects[25]) form_27 = ScheduleForm(initial=objects[26]) form_28 = ScheduleForm(initial=objects[27]) form_29 = ScheduleForm(initial=objects[28]) form_30 = ScheduleForm(initial=objects[29]) form_31 = ScheduleForm(initial=objects[30]) form_32 = ScheduleForm(initial=objects[31]) form_33 = ScheduleForm(initial=objects[32]) form_34 = ScheduleForm(initial=objects[33]) form_35 = ScheduleForm(initial=objects[34]) form_36 = ScheduleForm(initial=objects[35]) form_37 = ScheduleForm(initial=objects[36]) form_38 = ScheduleForm(initial=objects[37]) form_39 = ScheduleForm(initial=objects[38]) form_40 = ScheduleForm(initial=objects[39]) form_41 = ScheduleForm(initial=objects[40]) form_42 = ScheduleForm(initial=objects[41]) form_43 = ScheduleForm(initial=objects[42]) form_44 = ScheduleForm(initial=objects[43]) form_45 = ScheduleForm(initial=objects[44]) form_46 = ScheduleForm(initial=objects[45]) form_47 = ScheduleForm(initial=objects[46]) form_48 = ScheduleForm(initial=objects[47]) context = { 'date': datetime.date.today(), 'form_dict': {'form_1' : form_1, 'form_2' : form_2, 'form_3' : form_3, 'form_4' : form_4, 'form_5' : form_5, 'form_6' : form_6, 'form_7' : form_7, 'form_8' : form_8, 'form_9' : form_9, 'form_10': form_10, 'form_11': form_11, 'form_12': form_12, 'form_13': form_13, 'form_14': form_14, 'form_15': form_15, 'form_16': form_16, 'form_17': form_17, 'form_18': form_18, 'form_19': form_19, 'form_20': form_20, 'form_21': form_21, 'form_22': form_22, 'form_23': form_23, 'form_24': form_24, 'form_25': form_25, 'form_26': form_26, 'form_27': form_27, 'form_28': form_28, 'form_29': form_29, 'form_30': form_30, 'form_31': form_31, 'form_32': form_32, 'form_33': form_33, 'form_34': form_34, 'form_35': form_35, 'form_36': form_36, 'form_37': form_37, 'form_38': form_38, 'form_39': form_39, 'form_40': form_40, 'form_41': form_41, 'form_42': form_42, 'form_43': form_43, 'form_44': form_44, 'form_45': form_45, 'form_46': form_46, 'form_47': form_47, 'form_48': form_48, }} return render(request, 'schedule.html', context=context) elif request.method == 'POST': if 'notify' in request.POST: encoder = { 1: date.month * date.day * 217, 2: date.month * date.day * 94, 3: date.month * date.day * 33, 4: date.month * date.day * 65, 5: date.month * date.day * 210, 6: date.month * date.day * 38, 7: date.month * date.day * 51, 8: date.month * date.day * 176, 9: date.month * date.day * 154, 10: date.month * date.day * 77, 11: date.month * date.day * 66, 12: date.month * date.day * 114, 13: date.month * date.day * 177, 14: date.month * date.day * 111, 15: date.month * date.day * 86, 16: date.month * date.day * 74, 17: date.month * date.day * 104, 18: date.month * date.day * 186, 19: date.month * date.day * 78, 20: date.month * date.day * 37, 21: date.month * date.day * 222, 22: date.month * date.day * 12, 23: date.month * date.day * 75, 24: date.month * date.day * 55, 25: date.month * date.day * 46, 26: date.month * date.day * 57, 27: date.month * date.day * 95, 28: date.month * date.day * 60, 29: date.month * date.day * 59, 30: date.month * date.day * 63, 31: date.month * date.day * 99, 32: date.month * date.day * 170, 33: date.month * date.day * 44, 34: date.month * date.day * 32, 35: date.month * date.day * 61, 36: date.month * date.day * 151, 37: date.month * date.day * 189, 38: date.month * date.day * 147, 39: date.month * date.day * 80, 40: date.month * date.day * 234, 41: date.month * date.day * 85, 42: date.month * date.day * 35, 43: date.month * date.day * 43, 44: date.month * date.day * 202, 45: date.month * date.day * 81, 46: date.month * date.day * 93, 47: date.month * date.day * 228, 48: date.month * date.day * 24, } schedule_object = Schedule.objects.all().order_by('-date')[:1][0] json_dicts = [schedule_object.slot_1, schedule_object.slot_2, schedule_object.slot_3, schedule_object.slot_4, schedule_object.slot_5, schedule_object.slot_6, schedule_object.slot_7, schedule_object.slot_8, schedule_object.slot_9, schedule_object.slot_10, schedule_object.slot_11, schedule_object.slot_12, schedule_object.slot_13, schedule_object.slot_14, schedule_object.slot_15, schedule_object.slot_16, schedule_object.slot_17, schedule_object.slot_18, schedule_object.slot_19, schedule_object.slot_20, schedule_object.slot_21, schedule_object.slot_22, schedule_object.slot_23, schedule_object.slot_24, schedule_object.slot_25, schedule_object.slot_26, schedule_object.slot_27, schedule_object.slot_28, schedule_object.slot_29, schedule_object.slot_30, schedule_object.slot_31, schedule_object.slot_32, schedule_object.slot_33, schedule_object.slot_34, schedule_object.slot_35, schedule_object.slot_36, schedule_object.slot_37, schedule_object.slot_38, schedule_object.slot_39, schedule_object.slot_40, schedule_object.slot_41, schedule_object.slot_42, schedule_object.slot_43, schedule_object.slot_44, schedule_object.slot_45, schedule_object.slot_46, schedule_object.slot_47, schedule_object.slot_48, ] slot = int(request.POST['form_indicator'][1:]) # Slice it because it begins with '_' name = request.POST['name'] modality = request.POST['modality'] phone = request.POST['phone'] email = request.POST['email'] # Change the indicator to a semi-random number, the 48-set of which change every day, so that no one can meddle slot_encoded = encoder[slot] # Use regex to limit spaces to 1, split the resulting string on whitespaces, then capitalize each segment name = ' '.join([x.capitalize() for x in re.sub('\s{2,}', ' ', name).split(' ')]) # Keep 'there' lower-case when no name is provided in the form. if name == 'There': name = 'there' slot_json = json_dicts[slot - 1] slot_json['status'] = 'Sent' schedule_object.save() def send_email(): email_body = """\ <html> <head></head> <body style="border-radius: 20px; padding: 1rem; color: black; font-size: 1.1rem; background-color: #d5e9fb"> <h2>Hello {0},</h2> <h3>We are now ready for you!</h3> </br> <p>Please use the button below to indicate that you are on your way. Thank you!</p> </br> <a href="appointmentalert.herokuapp.com/{1}/confirm"><input type="button" style="border-radius: 9px; padding: 1rem; margin: 1rem 0; color: white; background-color: #1F45FC;" value="Confirm Appointment"></a> </br> </body> </html> """.format(name, slot_encoded) email_message = EmailMessage('Ready for your appointment!', email_body, from_email='NBRHC Alerts <*****@*****.**>', to=[email]) # It wants a tuple or a list email_message.content_subtype = "html" # this is the crucial part email_message.send() def send_text(): to = '+1' + phone client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN) response = client.messages.create( body='\nHello {0},\n\nWe are now ready for you!\n\nPlease use the link below to indicate that you are on your way.\n\nappointmentalert.herokuapp.com/{1}/confirm\n\nThank you!'.format(name, slot_encoded), to=to, from_=settings.TWILIO_PHONE_NUMBER) if modality == 'Email': send_email() elif modality == 'Phone': send_text() elif modality == 'Phone & Email': send_email() send_text() else: if Schedule.objects.last() is None: schedule_object = Schedule() set_default_slots = True elif Schedule.objects.last().date == datetime.date.today(): schedule_object = Schedule.objects.all().order_by('-date')[:1][0] set_default_slots = False else: schedule_object = Schedule() set_default_slots = True json_dicts = [schedule_object.slot_1, schedule_object.slot_2, schedule_object.slot_3, schedule_object.slot_4, schedule_object.slot_5, schedule_object.slot_6, schedule_object.slot_7, schedule_object.slot_8, schedule_object.slot_9, schedule_object.slot_10, schedule_object.slot_11, schedule_object.slot_12, schedule_object.slot_13, schedule_object.slot_14, schedule_object.slot_15, schedule_object.slot_16, schedule_object.slot_17, schedule_object.slot_18, schedule_object.slot_19, schedule_object.slot_20, schedule_object.slot_21, schedule_object.slot_22, schedule_object.slot_23, schedule_object.slot_24, schedule_object.slot_25, schedule_object.slot_26, schedule_object.slot_27, schedule_object.slot_28, schedule_object.slot_29, schedule_object.slot_30, schedule_object.slot_31, schedule_object.slot_32, schedule_object.slot_33, schedule_object.slot_34, schedule_object.slot_35, schedule_object.slot_36, schedule_object.slot_37, schedule_object.slot_38, schedule_object.slot_39, schedule_object.slot_40, schedule_object.slot_41, schedule_object.slot_42, schedule_object.slot_43, schedule_object.slot_44, schedule_object.slot_45, schedule_object.slot_46, schedule_object.slot_47, schedule_object.slot_48, ] # Run this code if a new object has been created if set_default_slots == True: slot_counter = 0 for slot_json in json_dicts: slot_json['slot'] = slots[slot_counter] slot_counter+=1 # Get the specific slot to update based on the POST request slot_json = json_dicts[int(request.POST['form_indicator'][1:]) - 1] slot_json['slot'] = request.POST['slot'] slot_json['name'] = request.POST['name'].capitalize() slot_json['modality'] = request.POST['modality'] slot_json['phone'] = request.POST['phone'] slot_json['email'] = request.POST['email'] slot_json['status'] = request.POST['status'] schedule_object.save() return HttpResponse()
def start_button(request): schedule = Schedule() schedule.start = timezone.now() schedule.finish = None schedule.worker = User.objects.get(username__exact=request.user.username) schedule.save()