Sort courses in <nav> header
- Author
- Maarten Vangeneugden
- Date
- Aug. 24, 2018, 1:03 a.m.
- Hash
- 88a21fef869b31c588f1122dd9db8ba7daa1e7cb
- Parent
- 5cab554537278cad91d9d2b04cf9413883d4769d
- Modified files
- courses/views.py
- joeni/templates/joeni/header.djhtml
courses/views.py ¶
1 addition and 1 deletion.
View changes Hide changes
1 |
1 |
import datetime |
2 |
2 |
from django.urls import reverse # Why? |
3 |
3 |
from django.utils.translation import gettext as _ |
4 |
4 |
from .models import * |
5 |
5 |
from .forms import * |
6 |
6 |
import administration |
7 |
7 |
from django.contrib.auth.decorators import login_required |
8 |
8 |
from joeni.constants import current_academic_year |
9 |
9 |
|
10 |
10 |
@login_required |
11 |
11 |
def index(request): |
12 |
12 |
""" Starting page regarding the courses. This serves two specific groups: |
13 |
13 |
- Students: Displays all courses that this student has in his/her curriculum |
14 |
14 |
for this academic year. Requires the curriculum to be accepted. |
15 |
15 |
- Staff: Displays all courses in which the staff member is part of the |
16 |
16 |
educating team, or is otherwise related to the course. |
17 |
17 |
Users who are not logged in will be sent to the login page. |
18 |
18 |
""" |
19 |
19 |
template = "courses/index.djhtml" |
20 |
20 |
courses = request.user.user_data.current_courses() |
21 |
21 |
|
22 |
22 |
context = { |
23 |
23 |
'courses': courses, |
24 |
24 |
} |
25 |
25 |
|
26 |
26 |
return render(request, template, context) |
27 |
27 |
|
28 |
28 |
@login_required |
29 |
29 |
def course(request, course_slug): |
30 |
30 |
template = "courses/course.djhtml" |
31 |
31 |
course = Course.objects.get(slug_name=course_slug) |
32 |
32 |
|
33 |
33 |
# Check if user can see this page |
34 |
34 |
if request.user.user_data.is_student: |
35 |
35 |
if course not in request.user.user_data.current_courses(): |
36 |
36 |
""" I'm currently just redirecting to the index page, but maybe it's |
37 |
37 |
just as good to make an announcement that this course cannot be |
38 |
38 |
used by this user. """ |
39 |
39 |
return index(request) |
40 |
40 |
|
41 |
41 |
context = { |
42 |
42 |
'course': course, |
43 |
43 |
'main_color': course.color, |
44 |
44 |
'announcements': Announcement.objects.filter(course=course), |
45 |
45 |
'assignments': Assignment.objects.filter(course=course), |
46 |
46 |
'course-items': CourseItem.objects.filter(course=course), |
47 |
47 |
'study-groups': StudyGroup.objects.filter(course=course), |
48 |
48 |
'uploads': Upload.objects.filter(course=course).filter(student=request.user) |
49 |
49 |
} |
50 |
50 |
if request.user.user_data.is_student: |
51 |
51 |
context['upload_form'] = UploadForm() |
52 |
52 |
#else: |
53 |
53 |
context['student_list'] = administration.models.CourseResult.objects.filter(course_programme__course=course)#.filter(year=current_academic_year()), |
54 |
54 |
# FIXME I disabled the year filter for testing purposes. Enable in deployment. |
55 |
55 |
|
56 |
56 |
return render(request, template, context) |
57 |
57 |
|
58 |
58 |
# TODO: Find a way to see if it's possible to require some permissions and to |
59 |
59 |
# put them in a decorator |
60 |
60 |
#@permission_required |
61 |
61 |
@login_required |
62 |
62 |
def new_item(request, course_slug): |
63 |
63 |
template = "courses/new_item.djhtml" |
64 |
64 |
course = Course.objects.get(slug_name=course_slug) |
65 |
65 |
|
66 |
66 |
if request.user.user_data.is_student or request.user not in course.course_team: |
67 |
67 |
# Students can't add new items. Redirect to index |
68 |
68 |
# Also redirect people who are not part of the course team |
69 |
69 |
redirect('courses-index') |
70 |
70 |
# Now able to assume user is allowed to add items to this course |
71 |
71 |
|
72 |
72 |
context = { |
73 |
73 |
'course': course, |
74 |
74 |
'announcements': Announcement.objects.filter(course=course), |
75 |
75 |
'assignments': Assignment.objects.filter(course=course), |
76 |
76 |
'course-items': CourseItem.objects.filter(course=course), |
77 |
77 |
'study-groups': StudyGroup.objects.filter(course=course), |
78 |
78 |
'uploads': Upload.objects.filter(course=course) |
79 |
79 |
} |
80 |
80 |
return render(request, template, context) |
81 |
81 |
|
82 |
82 |
def upload(request): |
83 |
83 |
return render(request, template, context) |
84 |
84 |
|
85 |
85 |
#@create_context # TODO |
86 |
86 |
@login_required |
87 |
87 |
def course_results(request, course_slug): |
88 |
88 |
template = "courses/course_results.djhtml" |
89 |
89 |
context = dict() |
90 |
90 |
course_ = Course.objects.get(slug_name=course_slug) |
91 |
91 |
return render(request, template, context) |
92 |
92 |
|
93 |
93 |
@login_required |
94 |
94 |
def edit_course_items(request, course_slug): |
95 |
95 |
# TODO Only allow people on the course team to this page! |
96 |
96 |
template = "courses/edit_course_items.djhtml" |
97 |
97 |
context = dict() |
98 |
98 |
course_ = Course.objects.get(slug_name=course_slug) |
99 |
99 |
if request.method == 'POST': |
100 |
100 |
assignments = AssignmentFormSet(request.POST, prefix='assignments') |
101 |
101 |
announcements = AnnouncementFormSet(request.POST, prefix='announcements') |
102 |
102 |
course_items = CourseItemFormSet(request.POST, request.FILES, prefix='course_items') |
103 |
- | #course_results = CourseResultFormSet(request.POST, prefix='course_results') |
+ |
103 |
#course_results = CourseResultFormSet(request.POST, prefix='course_results') |
104 |
104 |
if assignments.is_valid() and announcements.is_valid() and course_items.is_valid(): #and course_results.is_valid(): |
105 |
105 |
assignments.save(commit=False) |
106 |
106 |
announcements.save(commit=False) |
107 |
107 |
course_items.save(commit=False) |
108 |
108 |
#course_results.save(commit=False) |
109 |
109 |
for new_assignment in assignments.new_objects: |
110 |
110 |
new_assignment.course = course_ |
111 |
111 |
for new_announcement in announcements.new_objects: |
112 |
112 |
new_announcement.course = course_ |
113 |
113 |
for new_course_item in course_items.new_objects: |
114 |
114 |
new_coutse_item.course = course_ |
115 |
115 |
#for new_course_result in course_results.new_objects: |
116 |
116 |
#new_coutse_result.course = course_ |
117 |
117 |
assignments.save() |
118 |
118 |
announcements.save() |
119 |
119 |
course_items.save() |
120 |
120 |
#course_results.save() |
121 |
121 |
return course(request, course_slug) |
122 |
122 |
else: |
123 |
123 |
assignments = AssignmentFormSet( |
124 |
124 |
queryset=Assignment.objects.filter(course=course_), |
125 |
125 |
prefix="assignments", |
126 |
126 |
) |
127 |
127 |
announcements = AnnouncementFormSet( |
128 |
128 |
queryset=Announcement.objects.filter(course=course_), |
129 |
129 |
prefix="announcements", |
130 |
130 |
) |
131 |
131 |
course_items = CourseItemFormSet( |
132 |
132 |
queryset=CourseItem.objects.filter(course=course_), |
133 |
133 |
prefix="course_items", |
134 |
134 |
) |
135 |
135 |
#course_results = CourseResultFormSet( |
136 |
136 |
#queryset=administration.models.CourseResult.objects.filter(course_programme__course=course_).filter(year=current_academic_year()), |
137 |
137 |
#prefix="course_results", |
138 |
138 |
#) |
139 |
139 |
|
140 |
140 |
context['course'] = course_ |
141 |
141 |
context['assignments'] = assignments |
142 |
142 |
context['announcements'] = announcements |
143 |
143 |
context['course_items'] = course_items |
144 |
144 |
#context['course_results'] = course_results |
145 |
145 |
return render(request, template, context) |
146 |
146 |
|
147 |
147 |
|
148 |
148 |
|
149 |
149 |
@login_required |
150 |
150 |
def groups(request): |
151 |
151 |
pass |
152 |
152 |
|
153 |
153 |
def fiche(request, course_slug): |
154 |
154 |
"""Displays the fiche for the given course. Includes information about all |
155 |
155 |
course programs.""" |
156 |
156 |
template = "courses/fiche.djhtml" |
157 |
157 |
context = dict() |
158 |
158 |
course = Course.objects.get(slug_name=course_slug) |
159 |
159 |
joeni/templates/joeni/header.djhtml ¶
1 addition and 1 deletion.
View changes Hide changes
1 |
1 |
{% load static %} |
2 |
2 |
{% get_media_prefix as media %} |
3 |
3 |
<img src="{% static "logos/uhasselt/simple_white.svg" %}" alt="◀ Joeni /▶" /> |
4 |
4 |
<nav> |
5 |
5 |
<ul> |
6 |
6 |
<!--<li><a href="{% url 'agora-index' %}">Agora</a>--> |
7 |
7 |
<li><del>Agora</del></li> |
8 |
8 |
<ul> |
9 |
9 |
</ul> |
10 |
10 |
</li> |
11 |
11 |
|
12 |
12 |
<li><a href="{% url 'administration-index' %}">{% trans "Administration" %}</a> |
13 |
13 |
<ul> |
14 |
14 |
<li><a href="{% url 'administration-settings' %}">{% trans "Personal settings" %}</a></li> |
15 |
15 |
<li><a href="{% url 'administration-curriculum' %}">{% trans "Curricula" %}</a></li> |
16 |
16 |
<li><a href="{% url 'administration-buses' %}">{% trans "Buses" %}</a></li> |
17 |
17 |
<li><a href="{% url 'administration-forms' %}">{% trans "Forms" %}</a></li> |
18 |
18 |
<li><a href="{% url 'administration-rooms' %}">{% trans "Rooms" %}</a></li> |
19 |
19 |
<li><a href="{% url 'administration-jobs' %}">{% trans "Jobs" %}</a></li> |
20 |
20 |
<li><a href="{% url 'administration-roster' %}">{% trans "Personal Roster" %}</a></li> |
21 |
21 |
<li><a href="{% url 'administration-bulletin-board' %}">{% trans "Bulletin board" %}</a></li> |
22 |
22 |
</ul> |
23 |
23 |
</li> |
24 |
24 |
|
25 |
25 |
<li><a href="{% url 'courses-index' %}">{% trans "Courses" %}</a> |
26 |
26 |
<ul> |
27 |
27 |
{% for course in user.user_data.current_courses %} |
28 |
- | <li><a href="{% url 'courses-course-index' course.slug_name %}">{{ course.name }}</a></li> |
+ |
28 |
<li><a href="{% url 'courses-course-index' course.slug_name %}">{{ course.name }}</a></li> |
29 |
29 |
{% endfor %} |
30 |
30 |
</ul> |
31 |
31 |
</li> |
32 |
32 |
</ul> |
33 |
33 |
</nav> |
34 |
34 |
{# PingPing: €{{ money }} #} |
35 |
35 |