def instructor(request): """ The instructor view is the view function for the instructor.html page. This function expects to be sent an 'instructor' query string with the name of the 'clicked-on' instructor. We query the instructor table for the instructor with that name and send that instructor as a context to the instructor.html template, and that html file is returned as a HTTPresponse page See https://docs.djangoproject.com/en/dev/topics/http/views/s """ # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, '/scheduler/instructor/') setcookie = False if status is False: return redirect_to_cas('/scheduler/instructor/') if cookie != "": setcookie = True ins = request.GET.get('instructor', None) if ins is not None: prof = Instructor.objects.get(name=ins) response = render(request, 'instructor.html', {'prof': prof, 'id': id}) if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response return render(request, 'instructor.html', {'id': id})
def inssearch(request): """ The insearch view is the view function for the insearch.html page. This view can take in a name query string but does not neccessarily expect it. If there is a valid name query string, we query the intructor table for all of the instructors whose name or email contains the query string. We then send that query set as a context to the 'inssearch.html' template file which is then returned as a HttpResponse See https://docs.djangoproject.com/en/dev/topics/http/views/ """ # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, '/scheduler/instructor/') setcookie = False if status is False: return redirect_to_cas('/scheduler/instructor/') if cookie != "": setcookie = True if request.method == 'GET': name = request.GET.get('name', None) if name is not None: profs = Instructor.objects.filter( Q(name__icontains=name) | Q(email__icontains=name)) response = render(request, 'inssearch.html', { 'profs': profs, 'id': id }) if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response return render(request, 'inssearch.html') else: return render(request, 'inssearch.html', {'id': id})
def mycourses(request): """ The mycourses view function is another view function for the add.html page. Unlike the other two, this function immediately finds all of the courses that the current user is enrolled in and sends that dictionary as a context to add.html See https://docs.djangoproject.com/en/dev/topics/http/views/ """ # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, '/scheduler/instructor/') setcookie = False if status is False: return redirect_to_cas('/scheduler/instructor/') if cookie != "": setcookie = True toSend = {} eventIDs = Enrollment.objects.filter(student_id=id).values_list('event_id', flat=True) classes = Instructs.objects.filter(meeting_id__in=eventIDs) for c in classes: toSend[c] = True response = render(request, 'add.html', { 'classes': toSend, 'id': id, 'form': SearchForm() }) if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response
def inssearch(request): """ The insearch view is the view function for the insearch.html page. This view can take in a name query string but does not neccessarily expect it. If there is a valid name query string, we query the intructor table for all of the instructors whose name or email contains the query string. We then send that query set as a context to the 'inssearch.html' template file which is then returned as a HttpResponse See https://docs.djangoproject.com/en/dev/topics/http/views/ """ # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, '/scheduler/instructor/') setcookie = False if status is False: return redirect_to_cas('/scheduler/instructor/') if cookie != "": setcookie = True if request.method == 'GET': name = request.GET.get('name', None) if name is not None: profs = Instructor.objects.filter( Q( name__icontains=name) | Q(email__icontains=name)) response = render(request, 'inssearch.html', {'profs': profs, 'id': id}) if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response return render(request, 'inssearch.html') else: return render(request, 'inssearch.html', {'id': id})
def mycourses(request): """ The mycourses view function is another view function for the add.html page. Unlike the other two, this function immediately finds all of the courses that the current user is enrolled in and sends that dictionary as a context to add.html See https://docs.djangoproject.com/en/dev/topics/http/views/ """ # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, '/scheduler/instructor/') setcookie = False if status is False: return redirect_to_cas('/scheduler/instructor/') if cookie != "": setcookie = True toSend = {} eventIDs = Enrollment.objects.filter(student_id=id).values_list('event_id', flat=True) classes = Instructs.objects.filter(meeting_id__in=eventIDs) for c in classes: toSend[c] = True response = render(request, 'add.html', {'classes': toSend, 'id': id, 'form': SearchForm()}) if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response
def searchtest(request): status, id, cookie = check_login(request, '/scheduler/instructor/') # setcookie = False if status is False: return redirect_to_cas('/scheduler/instructor/') # if cookie != "": # setcookie = True return render(request, 'live_search_test.html')
def schedule(request): """The view for schedule.html once the user has logged in database is queried for all the events associated with that user'self id. The function calculates the absolute position for the colored square for each event and the height for each square for display on the user's schedule. The function also assigns each event a different random color. Each event is put into a dictionary with the event as a key and an array corresponding to the top, height, and color of the square as the value. This dictionary is passed as a context to the schedule.html template which is returned to the webrowser as an HTTPresponse See https://docs.djangoproject.com/en/dev/topics/http/views/ """ # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, settings.LOCATION + '/scheduler/') setcookie = False if status is False: return redirect_to_cas(settings.LOCATION + '/scheduler/') if cookie != "": setcookie = True colors = [ '#FF0000', '#32E01B', '#003CFF', '#FF9D00', '#00B7FF', '#9D00FF', '#FF00EA', '#B5AA59', '#79BF6B', '#CFA27E' ] stu, created = Student.objects.get_or_create(case_id=id) toSend = {} if created is False: enrolls = Enrollment.objects.filter(student__case_id=id) for enroll in enrolls: event = Event.objects.get(id=enroll.event_id) top = event.start_time.hour - 6 top += event.start_time.minute / 60.0 top *= 75 top += 135 height = event.start_time.hour + (event.start_time.minute / 60.0) height = (event.end_time.hour + event.end_time.minute / 60.0) - height height *= 60 height *= 1.2 height += 3 randColor = random.randint(0, len(colors) - 1) color = colors[randColor] + '' del colors[randColor] toSend[event] = [top, height, color] response = render(request, 'schedule.html', {'events': toSend, 'id': id}) if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response
def share(request): # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, '/scheduler/instructor/') # setcookie = False if status is False: return redirect_to_cas('/scheduler/instructor/') # if cookie != "": # setcookie = True share_ids = Shares.objects.values_list('shareid', flat=True) rand = random.randint(1111111111, 9999999999) while rand in share_ids: rand = random.randint(1111111111, 9999999999)
def schedule(request): """The view for schedule.html once the user has logged in database is queried for all the events associated with that user'self id. The function calculates the absolute position for the colored square for each event and the height for each square for display on the user's schedule. The function also assigns each event a different random color. Each event is put into a dictionary with the event as a key and an array corresponding to the top, height, and color of the square as the value. This dictionary is passed as a context to the schedule.html template which is returned to the webrowser as an HTTPresponse See https://docs.djangoproject.com/en/dev/topics/http/views/ """ # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, settings.LOCATION + '/scheduler/') setcookie = False if status is False: return redirect_to_cas(settings.LOCATION + '/scheduler/') if cookie != "": setcookie = True colors = ['#FF0000', '#32E01B', '#003CFF', '#FF9D00', '#00B7FF', '#9D00FF', '#FF00EA', '#B5AA59', '#79BF6B', '#CFA27E'] stu, created = Student.objects.get_or_create(case_id=id) toSend = {} if created is False: enrolls = Enrollment.objects.filter(student__case_id=id) for enroll in enrolls: event = Event.objects.get(id=enroll.event_id) top = event.start_time.hour - 6 top += event.start_time.minute / 60.0 top *= 75 top += 135 height = event.start_time.hour + (event.start_time.minute / 60.0) height = ( event.end_time.hour + event.end_time.minute / 60.0) - height height *= 60 height *= 1.2 height += 3 randColor = random.randint(0, len(colors)-1) color = colors[randColor] + '' del colors[randColor] toSend[event] = [top, height, color] response = render(request, 'schedule.html', {'events': toSend, 'id': id}) if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response
def about(request): """ The about view function is the trivial view function that just returns the rendering of the about.html template file """ # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, '/scheduler/instructor/') # setcookie = False if status is False: return redirect_to_cas('/scheduler/instructor/') # if cookie != "": # setcookie = True return render(request, 'about.html')
def info(request): """ The info view is called whenever the user clicks on a meeting-time's name. The function is passed a request with a query string containing the desired course's department and course number. We perform a query search on the Instructs relation to find all classes that match the passed dept and number combination (or at least contain those strings). Then we perform the same search throught the enrollment table to find classes the user is already enrolled in as we did in the add view. This dictionary is passed as a context to the add.html template which is returned to the webrowser as an HTTPresponse See https://docs.djangoproject.com/en/dev/topics/http/views/ """ # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, '/scheduler/info/') setcookie = False if status is False: return redirect_to_cas('/scheduler/info/') if cookie != "": setcookie = True theCourse = request.GET.get('course', None) if theCourse is not None: # the course is passed in as dept~!~coursenumber arr = theCourse.split('~!~') classes = Instructs.objects.filter( meeting__meeting_class__dept__icontains=arr[0], meeting__meeting_class__class_number__icontains=arr[1], ) toSend = {} for c in classes: if Enrollment.objects.filter(student_id=id, event_id=c.meeting.id).exists(): toSend[c] = True else: toSend[c] = False response = render(request, 'info.html', {'classes': toSend, 'id': id}) if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response return render(request, 'info.html', {'id': id})
def inscourse(request): """ The inscourse view is a temporary view that redirects the user back to the add.html page. However, the query we have to perform is slightly different, thus neccessitating an entirely new view. Here we are passed an instructor name as part of the request. We query the Instructs table for all of the tuples whose instructor's name matched the name query string. We then perform the same filter from add where we check to see which of the courses from the first queryset the user is enrolled in. We create a dictionary of classes to booleans and pass that as a context to the add.html template and return as a HttpResponse See https://docs.djangoproject.com/en/dev/topics/http/views/ """ # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, '/scheduler/instructor/') setcookie = False if status is False: return redirect_to_cas('/scheduler/instructor/') if cookie != "": setcookie = True toSend = {} ins = request.GET.get('name', None) if ins is not None: classes = Instructs.objects.filter(instructor=ins) for c in classes: if Enrollment.objects.filter(student_id=id, event_id=c.meeting.id).exists(): toSend[c] = True else: toSend[c] = False response = render(request, 'add.html', { 'classes': toSend, 'id': id, 'form': SearchForm() }) if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response return render(request, 'add.html', {'id': id, 'form': SearchForm()})
def inscourse(request): """ The inscourse view is a temporary view that redirects the user back to the add.html page. However, the query we have to perform is slightly different, thus neccessitating an entirely new view. Here we are passed an instructor name as part of the request. We query the Instructs table for all of the tuples whose instructor's name matched the name query string. We then perform the same filter from add where we check to see which of the courses from the first queryset the user is enrolled in. We create a dictionary of classes to booleans and pass that as a context to the add.html template and return as a HttpResponse See https://docs.djangoproject.com/en/dev/topics/http/views/ """ # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, '/scheduler/instructor/') setcookie = False if status is False: return redirect_to_cas('/scheduler/instructor/') if cookie != "": setcookie = True toSend = {} ins = request.GET.get('name', None) if ins is not None: classes = Instructs.objects.filter(instructor=ins) for c in classes: if Enrollment.objects.filter(student_id=id, event_id=c.meeting.id).exists(): toSend[c] = True else: toSend[c] = False response = render(request, 'add.html', {'classes': toSend, 'id': id, 'form': SearchForm()}) if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response return render(request, 'add.html', {'id': id, 'form': SearchForm()})
def event_json(request): status, id, cookie = check_login(request, settings.LOCATION + '/scheduler/') setcookie = False if status is False: return redirect_to_cas(settings.LOCATION + '/scheduler/') if cookie != "": setcookie = True enrolls = Enrollment.objects.filter(student__case_id=id) response_data = [] for enroll in enrolls: event = Event.objects.get(id=enroll.event_id) start = request.GET.get('start', None) end = request.GET.get('end', None) # if start != None && end != None: start_date = dateutil.parser.parse(start) end_date = dateutil.parser.parse(end) if event.start_date > start_date.date(): date_to_start = event.start_date else: date_to_start = start_date.date() if event.end_date < end_date.date(): date_to_end = event.end_date else: date_to_end = end_date.date() for dt in rrule.rrule(rrule.DAILY, dtstart=date_to_start, until=date_to_end): event_data = {} event_data['id'] = enroll.event_id if event.meetingtime: event_data['title'] = event.meetingtime.meeting_class.dept \ + ' ' + str(event.meetingtime.meeting_class.class_number) else: event_data['title'] = event.customevent.event_name event_data['allDay'] = False if "Su" in event.recur_type and dt.weekday() == 6: event_data['start'] = str(dt.date().isoformat()) + 'T' + str( event.start_time.isoformat()) event_data['end'] = str(dt.date().isoformat()) + 'T' + str( event.end_time.isoformat()) elif "M" in event.recur_type and dt.weekday() == 0: event_data['start'] = str(dt.date().isoformat()) + 'T' + str( event.start_time.isoformat()) event_data['end'] = str(dt.date().isoformat()) + 'T' + str( event.end_time.isoformat()) elif "Tu" in event.recur_type and dt.weekday() == 1: event_data['start'] = str(dt.date().isoformat()) + 'T' + str( event.start_time.isoformat()) event_data['end'] = str(dt.date().isoformat()) + 'T' + str( event.end_time.isoformat()) elif "W" in event.recur_type and dt.weekday() == 2: event_data['start'] = str(dt.date().isoformat()) + 'T' + str( event.start_time.isoformat()) event_data['end'] = str(dt.date().isoformat()) + 'T' + str( event.end_time.isoformat()) elif "Th" in event.recur_type and dt.weekday() == 3: event_data['start'] = str(dt.date().isoformat()) + 'T' + str( event.start_time.isoformat()) event_data['end'] = str(dt.date().isoformat()) + 'T' + str( event.end_time.isoformat()) elif "F" in event.recur_type and dt.weekday() == 4: event_data['start'] = str(dt.date().isoformat()) + 'T' + str( event.start_time.isoformat()) event_data['end'] = str(dt.date().isoformat()) + 'T' + str( event.end_time.isoformat()) elif "Sa" in event.recur_type and dt.weekday() == 5: event_data['start'] = str(dt.date().isoformat()) + 'T' + str( event.start_time.isoformat()) event_data['end'] = str(dt.date().isoformat()) + 'T' + str( event.end_time.isoformat()) else: continue response_data.append(event_data) response = HttpResponse(json.dumps(response_data), content_type="application/json") if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response
def customevent(request): """ The customevent view function is the view for the custom.html field. If the event is passed a request with a POST method, ie the user hit a submit button, then the view all of the query strings and, if the strings are valid (see below), we create a new entry in the customevent table with the query strings set as the corresponding attributes. Then we create a new enrollment table entry linking the current user to the newly created custom event. Then we return a HttpResponseRedirect to the home page If this view is called without a POST request method, then we simply pass the custom.html template an empty instance of an EventForm (see below) and return the rendered custom.html page as a HttpResponse. See https://docs.djangoproject.com/en/dev/topics/http/views/ """ # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, '/scheduler/instructor/') setcookie = False if status is False: return redirect_to_cas('/scheduler/instructor/') if cookie != "": setcookie = True if request.method == "POST": form = EventForm(request.POST) if form.is_valid(): name = form.cleaned_data['event_title'] time = form.cleaned_data['times'] sdate = form.cleaned_data['start_date'] edate = form.cleaned_data['end_date'] try: loc = form.cleaned_data['location'] except: loc = "" startTimeArr, endTimeArr = parse_time(time) dayStr = '' if form.cleaned_data['su']: dayStr += 'Su' if form.cleaned_data['m']: dayStr += 'M' if form.cleaned_data['tu']: dayStr += 'Tu' if form.cleaned_data['w']: dayStr += 'W' if form.cleaned_data['th']: dayStr += 'Th' if form.cleaned_data['f']: dayStr += 'F' if form.cleaned_data['sa']: dayStr += 'Sa' if '' == dayStr: return render(request, 'custom.html', { 'id': id, 'form': form, 'dayErr': True }) # event = CustomEvent( # start_time=datetime.time(startTimeArr[0], startTimeArr[1]), # end_time=datetime.time(endTimeArr[0], endTimeArr[1]), # recur_type=days, event_name=name) event = CustomEvent( start_time=datetime.time(startTimeArr[0], startTimeArr[1]), end_time=datetime.time(endTimeArr[0], endTimeArr[1]), start_date=sdate, end_date=edate, recur_type=dayStr, event_name=name, location=loc, ) event.save() stu = Student.objects.get(case_id=id) enroll = Enrollment(student_id=stu.pk, event_id=event.id) enroll.save() return HttpResponseRedirect('/scheduler/') else: form = EventForm() response = render(request, 'custom.html', {'id': id, 'form': form}) if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response
def customevent(request): """ The customevent view function is the view for the custom.html field. If the event is passed a request with a POST method, ie the user hit a submit button, then the view all of the query strings and, if the strings are valid (see below), we create a new entry in the customevent table with the query strings set as the corresponding attributes. Then we create a new enrollment table entry linking the current user to the newly created custom event. Then we return a HttpResponseRedirect to the home page If this view is called without a POST request method, then we simply pass the custom.html template an empty instance of an EventForm (see below) and return the rendered custom.html page as a HttpResponse. See https://docs.djangoproject.com/en/dev/topics/http/views/ """ # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, '/scheduler/instructor/') setcookie = False if status is False: return redirect_to_cas('/scheduler/instructor/') if cookie != "": setcookie = True if request.method == "POST": form = EventForm(request.POST) if form.is_valid(): name = form.cleaned_data['event_title'] time = form.cleaned_data['times'] sdate = form.cleaned_data['start_date'] edate = form.cleaned_data['end_date'] try: loc = form.cleaned_data['location'] except: loc = "" startTimeArr, endTimeArr = parse_time(time) dayStr = '' if form.cleaned_data['su']: dayStr += 'Su' if form.cleaned_data['m']: dayStr += 'M' if form.cleaned_data['tu']: dayStr += 'Tu' if form.cleaned_data['w']: dayStr += 'W' if form.cleaned_data['th']: dayStr += 'Th' if form.cleaned_data['f']: dayStr += 'F' if form.cleaned_data['sa']: dayStr += 'Sa' if '' == dayStr: return render(request, 'custom.html', {'id': id, 'form': form, 'dayErr': True}) # event = CustomEvent( # start_time=datetime.time(startTimeArr[0], startTimeArr[1]), # end_time=datetime.time(endTimeArr[0], endTimeArr[1]), # recur_type=days, event_name=name) event = CustomEvent( start_time=datetime.time(startTimeArr[0], startTimeArr[1]), end_time=datetime.time(endTimeArr[0], endTimeArr[1]), start_date=sdate, end_date=edate, recur_type=dayStr, event_name=name, location=loc, ) event.save() stu = Student.objects.get(case_id=id) enroll = Enrollment(student_id=stu.pk, event_id=event.id) enroll.save() return HttpResponseRedirect('/scheduler/') else: form = EventForm() response = render(request, 'custom.html', {'id': id, 'form': form}) if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response
def add(request): """ The view for add.html. This view function is a little more complicated because it sometimes a 'Search' parameter as part of the passed request. It also uses python regexes to check the request against formats such as EECS 337 or EECS341, that way we can query on the proper event attributes. Finally, after finding the querySet for the passed search parameter, we create a dictionary with each event as a key. Then, we run through all of the results and check to see if the current user is enrolled in that event. If so we set the value for that event's key in our dict to the corresponding boolean value. This dictionary is passed as a context to the add.html template which is returned to the webrowser as an HTTPresponse See https://docs.djangoproject.com/en/dev/topics/http/views/ """ # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, '/scheduler/add/') setcookie = False if status is False: return redirect_to_cas('/scheduler/add/') if cookie != "": setcookie = True toSend = {} if request.method == 'GET': form = SearchForm(request.GET) # criterion = request.GET.get('Search', None) # TODO better regexes # patt=re.compile('(\w\w\w\w ((\w\w\w)|(\w\w\w\w)))|(\w\w\w\w\w\w\w)') patt = re.compile('(\w\w\w\w( )*(\d+|(\d+w)))') if form.is_valid(): criterion = form.cleaned_data['criterion'] if patt.match(criterion): str = string.replace(criterion, ' ', '') arr = [None]*2 arr[0] = str[0:3] arr[1] = str[4:] # arr = criterion.split(' ') classes = Instructs.objects.filter( meeting__meeting_class__dept__icontains=arr[0], meeting__meeting_class__class_number__icontains=arr[1]) else: classes = Instructs.objects.filter( Q( meeting__meeting_class__classname__icontains=criterion ) | Q( meeting__meeting_class__dept__icontains=criterion ) | Q( meeting__meeting_class__class_number__icontains=criterion )) # numb = len(Class.objects.all()) for c in classes: if Enrollment.objects.filter(student_id=id, event_id=c.meeting.id).exists(): toSend[c] = True else: toSend[c] = False else: form = SearchForm() response = render(request, 'add.html', {'classes': toSend, 'id': id, 'form': form}) if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response
def event_json(request): status, id, cookie = check_login( request, settings.LOCATION + '/scheduler/') setcookie = False if status is False: return redirect_to_cas(settings.LOCATION + '/scheduler/') if cookie != "": setcookie = True enrolls = Enrollment.objects.filter(student__case_id=id) response_data = [] for enroll in enrolls: event = Event.objects.get(id=enroll.event_id) start = request.GET.get('start', None) end = request.GET.get('end', None) # if start != None && end != None: start_date = dateutil.parser.parse(start) end_date = dateutil.parser.parse(end) if event.start_date > start_date.date(): date_to_start = event.start_date else: date_to_start = start_date.date() if event.end_date < end_date.date(): date_to_end = event.end_date else: date_to_end = end_date.date() for dt in rrule.rrule(rrule.DAILY, dtstart=date_to_start, until=date_to_end): event_data = {} event_data['id'] = enroll.event_id if event.meetingtime: event_data['title'] = event.meetingtime.meeting_class.dept \ + ' ' + str(event.meetingtime.meeting_class.class_number) else: event_data['title'] = event.customevent.event_name event_data['allDay'] = False if "Su" in event.recur_type and dt.weekday() == 6: event_data['start'] = str( dt.date().isoformat() ) + 'T' + str( event.start_time.isoformat() ) event_data['end'] = str( dt.date().isoformat() ) + 'T' + str( event.end_time.isoformat() ) elif "M" in event.recur_type and dt.weekday() == 0: event_data['start'] = str( dt.date().isoformat() ) + 'T' + str( event.start_time.isoformat() ) event_data['end'] = str( dt.date().isoformat() ) + 'T' + str( event.end_time.isoformat() ) elif "Tu" in event.recur_type and dt.weekday() == 1: event_data['start'] = str( dt.date().isoformat() ) + 'T' + str( event.start_time.isoformat() ) event_data['end'] = str( dt.date().isoformat() ) + 'T' + str( event.end_time.isoformat() ) elif "W" in event.recur_type and dt.weekday() == 2: event_data['start'] = str( dt.date().isoformat() ) + 'T' + str( event.start_time.isoformat() ) event_data['end'] = str( dt.date().isoformat() ) + 'T' + str( event.end_time.isoformat() ) elif "Th" in event.recur_type and dt.weekday() == 3: event_data['start'] = str( dt.date().isoformat() ) + 'T' + str( event.start_time.isoformat() ) event_data['end'] = str( dt.date().isoformat() ) + 'T' + str( event.end_time.isoformat() ) elif "F" in event.recur_type and dt.weekday() == 4: event_data['start'] = str( dt.date().isoformat() ) + 'T' + str( event.start_time.isoformat() ) event_data['end'] = str( dt.date().isoformat() ) + 'T' + str( event.end_time.isoformat() ) elif "Sa" in event.recur_type and dt.weekday() == 5: event_data['start'] = str( dt.date().isoformat() ) + 'T' + str( event.start_time.isoformat() ) event_data['end'] = str( dt.date().isoformat() ) + 'T' + str( event.end_time.isoformat() ) else: continue response_data.append(event_data) response = HttpResponse(json.dumps(response_data), content_type="application/json") if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response
def add(request): """ The view for add.html. This view function is a little more complicated because it sometimes a 'Search' parameter as part of the passed request. It also uses python regexes to check the request against formats such as EECS 337 or EECS341, that way we can query on the proper event attributes. Finally, after finding the querySet for the passed search parameter, we create a dictionary with each event as a key. Then, we run through all of the results and check to see if the current user is enrolled in that event. If so we set the value for that event's key in our dict to the corresponding boolean value. This dictionary is passed as a context to the add.html template which is returned to the webrowser as an HTTPresponse See https://docs.djangoproject.com/en/dev/topics/http/views/ """ # check to see if the user is logged in # if not make the user login status, id, cookie = check_login(request, '/scheduler/add/') setcookie = False if status is False: return redirect_to_cas('/scheduler/add/') if cookie != "": setcookie = True toSend = {} if request.method == 'GET': form = SearchForm(request.GET) # criterion = request.GET.get('Search', None) # TODO better regexes # patt=re.compile('(\w\w\w\w ((\w\w\w)|(\w\w\w\w)))|(\w\w\w\w\w\w\w)') patt = re.compile('(\w\w\w\w( )*(\d+|(\d+w)))') if form.is_valid(): criterion = form.cleaned_data['criterion'] if patt.match(criterion): str = string.replace(criterion, ' ', '') arr = [None] * 2 arr[0] = str[0:3] arr[1] = str[4:] # arr = criterion.split(' ') classes = Instructs.objects.filter( meeting__meeting_class__dept__icontains=arr[0], meeting__meeting_class__class_number__icontains=arr[1]) else: classes = Instructs.objects.filter( Q(meeting__meeting_class__classname__icontains=criterion) | Q(meeting__meeting_class__dept__icontains=criterion) | Q(meeting__meeting_class__class_number__icontains=criterion )) # numb = len(Class.objects.all()) for c in classes: if Enrollment.objects.filter(student_id=id, event_id=c.meeting.id).exists(): toSend[c] = True else: toSend[c] = False else: form = SearchForm() response = render(request, 'add.html', { 'classes': toSend, 'id': id, 'form': form }) if setcookie is True: response.__setitem__('Set-Cookie', cookie) return response