Remove calls to Pingping module
The pingping module has been put in a seperate branch, but the calls still existed in the master branch. These have been removed and/or commented until the branches are merged.
- Author
- Maarten 'Vngngdn' Vangeneugden
- Date
- March 8, 2018, 12:36 p.m.
- Hash
- e8d8d64afbfabd54c7e5f996902ee59fc4245f9c
- Parent
- c4000e6b0bd9ab87a54f5bfe85b0e261c0028630
- Modified file
- administration/views.py
administration/views.py ¶
10 additions and 11 deletions.
View changes Hide changes
1 |
1 |
from collections import OrderedDict |
2 |
2 |
from django.http import HttpResponseRedirect |
3 |
3 |
import datetime |
4 |
4 |
from django.urls import reverse # Why? |
5 |
5 |
from django.utils.translation import gettext as _ |
6 |
6 |
from .models import * |
7 |
7 |
from .forms import UserDataForm |
8 |
8 |
from .new_roster import create_roster_rows |
9 |
9 |
from .pingping import update_balance |
10 |
- | import administration |
11 |
10 |
from django.contrib.auth.decorators import login_required |
12 |
11 |
from django.contrib.auth import authenticate |
13 |
12 |
|
14 |
13 |
@login_required |
15 |
14 |
def roster(request, begin=None, end=None): |
16 |
15 |
"""Collects and renders the data that has to be displayed in the roster. |
17 |
16 |
|
18 |
17 |
The begin and end date can be specified. Only roster points in that range |
19 |
18 |
will be included in the response. If no begin and end are specified, it will |
20 |
19 |
take the current week as begin and end point. If it's |
21 |
20 |
weekend, it will take next week.""" |
22 |
21 |
|
23 |
22 |
# TODO Handle given begin and end |
24 |
23 |
context = dict() |
25 |
24 |
context = {'money' : update_balance(None)} |
26 |
- | template = "administration/roster.djhtml" |
+ |
25 |
template = "administration/roster.djhtml" |
27 |
26 |
|
28 |
27 |
if begin is None or end is None: |
29 |
28 |
today = datetime.date.today() |
30 |
29 |
if today.isoweekday() in {6,7}: # Weekend |
31 |
30 |
begin = today + datetime.timedelta(days=8-today.isoweekday()) |
32 |
31 |
end = today + datetime.timedelta(days=13-today.isoweekday()) |
33 |
32 |
else: # Same week |
34 |
33 |
begin = today - datetime.timedelta(days=today.weekday()) |
35 |
34 |
end = today + datetime.timedelta(days=5-today.isoweekday()) |
36 |
35 |
else: # Changing regexes to date objects |
37 |
36 |
b = begin.split("-") |
38 |
37 |
e = end.split("-") |
39 |
38 |
begin = datetime.datetime(int(b[2]),int(b[1]),int(b[0])) |
40 |
39 |
end = datetime.datetime(int(e[2]),int(e[1]),int(e[0])) |
41 |
40 |
|
42 |
41 |
context['begin'] = begin |
43 |
42 |
context['end'] = end |
44 |
43 |
|
45 |
44 |
context['prev_begin'] = (begin - datetime.timedelta(days=7)).strftime("%d-%m-%Y") |
46 |
45 |
context['prev_end'] = (begin - datetime.timedelta(days=2)).strftime("%d-%m-%Y") |
47 |
46 |
context['next_begin'] = (end + datetime.timedelta(days=2)).strftime("%d-%m-%Y") |
48 |
47 |
context['next_end'] = (end + datetime.timedelta(days=7)).strftime("%d-%m-%Y") |
49 |
48 |
|
50 |
49 |
days = [begin] |
51 |
50 |
while (end-days[-1]).days != 0: |
52 |
51 |
# Human translation: Keep adding days until the last day in the array of |
53 |
52 |
# days is the same day as the last day the user wants to see the roster for. |
54 |
53 |
days.append(days[-1] + datetime.timedelta(days=1)) |
55 |
54 |
context['days'] = days |
56 |
55 |
|
57 |
56 |
# Collecting events |
58 |
57 |
course_events = CourseEvent.objects.filter(begin_time__gte=begin).filter(end_time__lte=end).order_by("begin_time") |
59 |
58 |
#university_events = UniversityEvent.objects.filter(begin_time__gte=begin).filter(end_time__lte=end) |
60 |
59 |
#study_events = StudyEvent.objects.filter(begin_time__gte=begin).filter(end_time__lte=end) |
61 |
60 |
#events = Event.objects.filter(begin_time__gte=begin).filter(end_time__lte=end) |
62 |
61 |
conflicts, table_code = create_roster_rows(course_events) |
63 |
62 |
|
64 |
63 |
context['time_blocks'] = table_code |
65 |
64 |
context['conflicts'] = conflicts |
66 |
65 |
#print(time_blocks) |
67 |
66 |
return render(request, template, context) |
68 |
67 |
# TODO Finish! |
69 |
68 |
|
70 |
69 |
def index(request): |
71 |
70 |
template = "administration/index.djhtml" |
72 |
71 |
context = {'money': update_balance(None)} |
73 |
- | return render(request, template, context) |
+ |
72 |
return render(request, template, context) |
74 |
73 |
|
75 |
74 |
pass |
76 |
75 |
|
77 |
76 |
def pre_registration(request): |
78 |
77 |
user_data_form = UserDataForm() |
79 |
78 |
template = "administration/pre_registration.djhtml" |
80 |
79 |
context = dict() |
81 |
80 |
|
82 |
81 |
if request.method == 'POST': |
83 |
82 |
user_data_form = UserDataForm(request.POST) |
84 |
83 |
context['user_data_form'] = user_data_form |
85 |
84 |
if user_data_form.is_valid(): |
86 |
85 |
user_data_form.save() |
87 |
86 |
context['messsage'] = _("Your registration has been completed. You will receive an e-mail shortly.") |
88 |
87 |
else: |
89 |
88 |
context['messsage'] = _("The data you supplied had errors. Please review your submission.") |
90 |
89 |
else: |
91 |
90 |
context['user_data_form'] = UserDataForm(instance = user_data_form) |
92 |
91 |
|
93 |
92 |
return render(request, template, context) |
94 |
93 |
pass |
95 |
94 |
|
96 |
95 |
@login_required |
97 |
96 |
def settings(request): |
98 |
97 |
user_data = UserData.objects.get(user=request.user) |
99 |
98 |
user_data_form = UserDataForm(instance = user_data) |
100 |
99 |
template = "administration/settings.djhtml" |
101 |
100 |
context = {'money' : update_balance(None)} |
102 |
- | |
+ |
101 |
|
103 |
102 |
if request.method == 'POST': |
104 |
103 |
user_data_form = UserDataForm(request.POST, instance = user_data) |
105 |
104 |
context['user_data_form'] = user_data_form |
106 |
105 |
if user_data_form.is_valid(): |
107 |
106 |
user_data_form.save() |
108 |
107 |
context['messsage'] = _("Your settings were successfully updated.") |
109 |
108 |
else: |
110 |
109 |
context['messsage'] = _("The data you supplied had errors. Please review your submission.") |
111 |
110 |
else: |
112 |
111 |
context['user_data_form'] = UserDataForm(instance = user_data) |
113 |
112 |
|
114 |
113 |
return render(request, template, context) |
115 |
114 |
|
116 |
115 |
@login_required |
117 |
116 |
def bulletin_board(request): |
118 |
117 |
context = dict() |
119 |
118 |
context = {'money' : update_balance(None)} |
120 |
- | context['exam_commission_decisions'] = ExamCommissionDecision.objects.filter(user=request.user) |
+ |
119 |
context['exam_commission_decisions'] = ExamCommissionDecision.objects.filter(user=request.user) |
121 |
120 |
context['education_department_messages'] = EducationDepartmentMessages.objects.all() |
122 |
121 |
for item in context['education_department_messages']: |
123 |
122 |
print(item.text) |
124 |
123 |
template = "administration/bulletin_board.djhtml" |
125 |
124 |
return render(request, template, context) |
126 |
125 |
|
127 |
126 |
def jobs(request): |
128 |
127 |
context = dict() |
129 |
128 |
context = {'money' : update_balance(None)} |
130 |
- | template = "administration/jobs.djhtml" |
+ |
129 |
template = "administration/jobs.djhtml" |
131 |
130 |
#@context['decisions'] = ExamCommissionDecision.objects.filter(user=request.user) |
132 |
131 |
return render(request, template, context) |
133 |
132 |
|
134 |
133 |
|
135 |
134 |
@login_required |
136 |
135 |
def curriculum(request): |
137 |
136 |
context = dict() |
138 |
137 |
context = {'money' : update_balance(None)} |
139 |
- | template = "administration/curriculum.djhtml" |
+ |
138 |
template = "administration/curriculum.djhtml" |
140 |
139 |
context['curricula'] = Curriculum.objects.filter(student=request.user) |
141 |
140 |
context['cource_results'] = CourseResult.objects.filter(student=request.user) |
142 |
141 |
return render(request, template, context) |
143 |
142 |
|
144 |
143 |
def result(request): |
145 |
144 |
return render(request, template, context) |
146 |
145 |
|
147 |
146 |
@login_required |
148 |
147 |
def results(request): |
149 |
148 |
results = CourseResult.objects.filter(student=request.user) |
150 |
149 |
template = "administration/results.djhtml" |
151 |
150 |
# TODO |
152 |
151 |
return render(request, template, context) |
153 |
152 |
|
154 |
153 |
def forms(request): |
155 |
154 |
context = dict() |
156 |
155 |
context = {'money' : update_balance(None)} |
157 |
- | template = "administration/forms.djhtml" |
+ |
156 |
template = "administration/forms.djhtml" |
158 |
157 |
return render(request, template, context) |
159 |
158 |
|
160 |
159 |
def user(request, slug_name): |
161 |
160 |
pass |
162 |
161 |
|
163 |
162 |
def rooms(request): |
164 |
163 |
context = dict() |
165 |
164 |
context = {'money' : update_balance(None)} |
166 |
- | context['rooms'] = Room.objects.all() |
+ |
165 |
context['rooms'] = Room.objects.all() |
167 |
166 |
context['room_reservations'] = RoomReservation.objects.all() |
168 |
167 |
context['course_events'] = CourseEvent.objects.all() |
169 |
168 |
context['blocks'] = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'] |
170 |
169 |
|
171 |
170 |
|
172 |
171 |
|
173 |
172 |
template = "administration/rooms.djhtml" |
174 |
173 |
return render(request, template, context) |
175 |
174 |
|
176 |
175 |
def room_detail(request, room): |
177 |
176 |
template = "administration/room_detail.djhtml" |
178 |
177 |
context = dict() |
179 |
178 |
context = {'money' : update_balance(None)} |
180 |
- | room = Room.objects.get(name=room) |
+ |
179 |
room = Room.objects.get(name=room) |
181 |
180 |
context['room'] = room |
182 |
181 |
context['reservations'] = RoomReservation.objects.filter(room=room).filter(begin_time__gte=datetime.datetime.now()) |
183 |
182 |
context['course_events'] = CourseEvent.objects.filter(room=room).filter(begin_time__gte=datetime.datetime.now()) |
184 |
183 |
# Building the room occupancy of today: |
185 |
184 |
today = datetime.date.today() |
186 |
185 |
if today.isoweekday() in {6,7}: # Weekend |
187 |
186 |
today = today + datetime.timedelta(days=8-today.isoweekday()) |
188 |
187 |
|
189 |
188 |
context['days'] = [today] |
190 |
189 |
|
191 |
190 |
# Collecting events |
192 |
191 |
course_events = CourseEvent.objects.filter(room=room).filter(begin_time__date=today) |
193 |
192 |
print(course_events) |
194 |
193 |
#university_events = UniversityEvent.objects.filter(begin_time__gte=begin).filter(end_time__lte=end) |
195 |
194 |
#study_events = StudyEvent.objects.filter(begin_time__gte=begin).filter(end_time__lte=end) |
196 |
195 |
#events = Event.objects.filter(begin_time__gte=begin).filter(end_time__lte=end) |
197 |
196 |
|
198 |
197 |
conflicts, table_code = create_roster_rows(course_events) |
199 |
198 |
context['time_blocks'] = table_code |
200 |
199 |
context['conflicts'] = conflicts |
201 |
200 |
print(context['time_blocks']) |
202 |
201 |
return render(request, template, context) |
203 |
202 |
|
204 |
203 |
def login(request): |
205 |
204 |
context = dict() |
206 |
205 |
context = {'money' : update_balance(None)} |
207 |
- | if request.method == "POST": |
+ |
206 |
if request.method == "POST": |
208 |
207 |
name = request.POST['name'] |
209 |
208 |
passphrase = request.POST['pass'] |
210 |
209 |
user = authenticate(username=name, password=passphrase) |
211 |
210 |
if user is not None: # The user was successfully authenticated |
212 |
211 |
print("YA") |
213 |
212 |
return HttpResponseRedirect(request.POST['next']) |
214 |
213 |
else: # User credentials were wrong |
215 |
214 |
context['next'] = request.POST['next'] |
216 |
215 |
context['message'] = _("The given credentials were not correct.") |
217 |
216 |
else: |
218 |
217 |
context['next'] = request.GET.get('next', None) |
219 |
218 |
if context['next'] is None: |
220 |
219 |
context['next'] = reverse('administration-index') |
221 |
220 |
|
222 |
221 |
template = 'administration/login.djhtml' |
223 |
222 |
|
224 |
223 |
return render(request, template, context) |
225 |
224 |