def saveSections(self, groups, course): Section.objects.filter(course=course).delete() for groupnum, group in enumerate(groups): for sectInfo in group: section = Section() section.course = course section.sectionnum = sectInfo['num'] section.group = groupnum section.save() if sectInfo['instructor'] != None: for prof in sectInfo['instructor'].split('/'): section.professors.add(self.saveProfessor(sectInfo['instructor'])) section.save() for meeting in sectInfo['times']: for day in meeting[1]: time = MeetingTime() time.section = section time.type = meeting[0] time.day = day (start, end) = self.timeinfo_to_times(meeting[2], meeting[3], meeting[4]) time.start = start time.end = end time.room = self.saveRoom(meeting[5] if len(meeting) > 5 else "TBA") time.save()
def change(request, slot_id): slot = get_object_or_404(KeyVal, pk=slot_id) signup_dictionary = get_list_or_404( KeyVal, container=get_object_or_404(Dictionary_Booth, career_booth=slot.container.career_booth)) user = request.user if slot.value != None: messages.error(request, ("Sorry! Someone already signed up for this slot.")) return HttpResponseRedirect(request.META.get('HTTP_REFERER')) if not available(request, slot_id): messages.error(request, ( "Sorry! It looks like you have a scheduling conflict with another booth. Please note that there must be at least a minute buffer between interviews." )) return HttpResponseRedirect(request.META.get('HTTP_REFERER')) for time in signup_dictionary: if time.value == user: time.value = None slot.value = user time.save() slot.save() messages.success( request, ('You have successfully signed up for this time slot!')) return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
def post(self, request, *args, **kwargs): form = self.form_class(request.POST) if form.is_valid(): form.save() time_added = datetime.timedelta(days = 7) if Time.objects.last(): self.time_object.time = self.time_object.time + time_added else: time = Time.objects.create() time.time = time.time + time_added time.save() time_object = Time.objects.last() if self.time_object: time_calculated = (self.time_object.time - timezone.now()).total_seconds() else: time_calculated = (Time.objects.last().time - timezone.now()).total_seconds() form = self.form_class() now = timezone.now() return render(request, self.template_name, {'form': form, 'messages':self.query,'now':now, 'time_calculated':time_calculated})
def admin(): global password, adminpassword, WIFI_login, WIFI_password, floor_number_old, floor_number, userstatus floor_number_old = floor_number f = open('user.txt') status = f.readline() print(status) status = status[:-1] name = f.readline() print(name) name = name[:-1] second_name = f.readline() print(second_name) second_name = second_name[:-1] login = f.readline() print(login) login = login[:-1] adminpassword = f.readline() print(adminpassword) adminpassword = adminpassword[:-1] f.close() f = open('userstatus.txt') userstatus = f.readline() userstatus = userstatus[:-1] print("----->" + userstatus + "<-----") f.close() if userstatus == 'True': if request.method == 'POST': WIFI_login = request.form['WIFI_login'] print(WIFI_login) WIFI_password = request.form['WIFI_password'] print(WIFI_password) time = request.files['time'] if time and allowed_file(time.filename): time.save(os.path.join("static/time/", "time.htm")) about = request.files['about'] if about and allowed_file(about.filename): about.save(os.path.join("static/", "about.htm")) floor_number = request.form['floor_number'] print(floor_number) # print(password == adminpassword) new_file = open('adminconfig.txt', 'w') new_file.write('%s\n' % WIFI_login) new_file.write('%s\n' % WIFI_password) new_file.close() floor_status = [ 'disabled', 'disabled', 'disabled', 'disabled', 'disabled', 'disabled', 'disabled', 'disabled', 'disabled' ] for i in range(int(floor_number)): floor_status[i] = ' ' print(floor_status) new_file = open('map.txt', 'w') new_file.write('%s\n' % floor_number) for i in range(9): new_file.write('%s\n' % floor_status[i]) for i in range(9): if i < int(floor_number_old): new_file.write( '%s\n' % request.form['floor_' + str(i + 1) + '_name']) else: new_file.write('Недоступно\n') new_file.close() for i in range(int(floor_number_old)): map = request.files['floor_' + str(i + 1)] if map and allowed_file(map.filename): map.save( os.path.join("static/map/", "map" + str(i + 1) + ".png")) return render_template("/admininterface.html", name=name, second_name=second_name, status=status, password_error=False, WIFI_login=WIFI_login, WIFI_password=WIFI_password, floor_number=floor_number, floor_a_status=floor_1_status, floor_b_status=floor_2_status, floor_c_status=floor_3_status, floor_d_status=floor_4_status, floor_e_status=floor_5_status, floor_f_status=floor_6_status, floor_g_status=floor_7_status, floor_h_status=floor_8_status, floor_i_status=floor_9_status, floor_a_name=floor_1_name, floor_b_name=floor_2_name, floor_c_name=floor_3_name, floor_d_name=floor_4_name, floor_e_name=floor_5_name, floor_f_name=floor_6_name, floor_g_name=floor_7_name, floor_h_name=floor_8_name, floor_i_name=floor_9_name) else: return render_template("/admininterface.html", name=name, second_name=second_name, status=status, password_error=False, WIFI_login=WIFI_login, WIFI_password=WIFI_password, floor_number=floor_number, floor_a_status=floor_1_status, floor_b_status=floor_2_status, floor_c_status=floor_3_status, floor_d_status=floor_4_status, floor_e_status=floor_5_status, floor_f_status=floor_6_status, floor_g_status=floor_7_status, floor_h_status=floor_8_status, floor_i_status=floor_9_status, floor_a_name=floor_1_name, floor_b_name=floor_2_name, floor_c_name=floor_3_name, floor_d_name=floor_4_name, floor_e_name=floor_5_name, floor_f_name=floor_6_name, floor_g_name=floor_7_name, floor_h_name=floor_8_name, floor_i_name=floor_9_name) else: if request.method == 'POST': In_password = request.form['password'] In_login = request.form['login'] if In_password == adminpassword and In_login == login: f = open('userstatus.txt', 'w') f.write('True\n') f.close() return render_template("/admininterface.html", name=name, second_name=second_name, status=status, password_error=False, WIFI_login=WIFI_login, WIFI_password=WIFI_password, floor_number=floor_number, floor_a_status=floor_1_status, floor_b_status=floor_2_status, floor_c_status=floor_3_status, floor_d_status=floor_4_status, floor_e_status=floor_5_status, floor_f_status=floor_6_status, floor_g_status=floor_7_status, floor_h_status=floor_8_status, floor_i_status=floor_9_status, floor_a_name=floor_1_name, floor_b_name=floor_2_name, floor_c_name=floor_3_name, floor_d_name=floor_4_name, floor_e_name=floor_5_name, floor_f_name=floor_6_name, floor_g_name=floor_7_name, floor_h_name=floor_8_name, floor_i_name=floor_9_name) else: return render_template("/adminlogin.html", name=name, second_name=second_name, status=status, password_error=False, WIFI_login=WIFI_login, WIFI_password=WIFI_password, floor_number=floor_number, floor_a_status=floor_1_status, floor_b_status=floor_2_status, floor_c_status=floor_3_status, floor_d_status=floor_4_status, floor_e_status=floor_5_status, floor_f_status=floor_6_status, floor_g_status=floor_7_status, floor_h_status=floor_8_status, floor_i_status=floor_9_status, floor_a_name=floor_1_name, floor_b_name=floor_2_name, floor_c_name=floor_3_name, floor_d_name=floor_4_name, floor_e_name=floor_5_name, floor_f_name=floor_6_name, floor_g_name=floor_7_name, floor_h_name=floor_8_name, floor_i_name=floor_9_name) return "error!"
# Add some days to the aforementioned event day = Day(date=datetime.datetime(year=2011, month=11, day=11, hour=20, minute=00), talks=12, event=event) day.put() guardians = Guardian.all().fetch(99999999) samplesize = int(len(guardians)/3) guardians = random.sample(guardians, samplesize) for guardian in guardians: time = TimePreference() time.event = event time.guardian = guardian time.preference = random.randint(0, 2) time.save() days = event.days.fetch(999) random.shuffle(days) for i, day in enumerate(days): day_pref = DayPreference() day_pref.guardian = guardian day_pref.day = day day_pref.rank = i day_pref.save() for child in guardian.children: subjects = Combination.all().filter('class_id', child.class_id).fetch(999) selection = random.sample(subjects, int(random.triangular(0, 4, 0))) for choice in selection: request = Request() request.event = event request.guardian = guardian