Fix display of students on course page
- Author
- Maarten Vangeneugden
- Date
- July 27, 2018, 12:42 a.m.
- Hash
- 46dd1497708d659163b75112f2529d92aac762d6
- Parent
- 80aa6c92497d9c88506eb3f591f5cce0f91be2fd
- Modified files
- courses/templates/courses/course.djhtml
- courses/views.py
courses/templates/courses/course.djhtml ¶
4 additions and 4 deletions.
View changes Hide changes
1 |
1 |
{% load static %} |
2 |
2 |
{% load i18n %} |
3 |
3 |
{% load humanize %} |
4 |
4 |
{% load joeni_org %} |
5 |
5 |
|
6 |
6 |
{% block title %} |
7 |
7 |
{{ course.name }} | {{ block.super }} |
8 |
8 |
{% endblock %} |
9 |
9 |
|
10 |
10 |
{% block main %} |
11 |
11 |
<h1>{{ course.name }}</h1> |
12 |
12 |
|
13 |
13 |
<h2 id="{% trans "announcements" %}">{% trans "Announcements" %}</h2> |
14 |
14 |
<div class="flex-container"> |
15 |
15 |
{% for announcement in announcements %} |
16 |
16 |
<div style="border-color: #{{ course.color }};" class="flex-item"> |
17 |
17 |
<h3 id="{{ announcement.title|slugify }}">{{ announcement.title }}</h3> |
18 |
18 |
<time datetime="{{ announcement.posted|date:'c' }}"> |
19 |
19 |
{% trans "Posted" %} {{ announcement.posted|naturaltime }} |
20 |
20 |
</time> |
21 |
21 |
<p>{{ announcement.text|org }}</p> |
22 |
22 |
</div> |
23 |
23 |
{% empty %} |
24 |
24 |
{% trans "No announcements have been made for this course." %} |
25 |
25 |
{% endfor %} |
26 |
26 |
</div> |
27 |
27 |
|
28 |
28 |
<h2 id="{% trans "assignments" %}">{% trans "Assignments" %}</h2> |
29 |
29 |
<div class="flex-container"> |
30 |
30 |
{% for assignment in assignments %} |
31 |
31 |
<div style="border-color: #{{ course.color }};" class="flex-item"> |
32 |
32 |
<h3 id="{{ assignment.title|slugify }}">{{ assignment.title }}</h3> |
33 |
33 |
<time datetime="{{ assignment.posted|date:'c' }}"> |
34 |
34 |
{% trans "Posted" %} {{ assignment.posted|date:"DATE_FORMAT" }} {# {{ assignment.posted|naturaltime }}#} |
35 |
35 |
</time> |
36 |
36 |
{% if assignment.information %} |
37 |
37 |
<p>{{ assignment.information|org }}</p> |
38 |
38 |
{% endif %} |
39 |
39 |
{#{% trans "Posted" %}: {{ assignment.posted|date:"DATE_FORMAT" }}#} |
40 |
40 |
{% if assignment.digital_task %} |
41 |
41 |
<h4>{% trans "Your uploads" %}</h4> |
42 |
42 |
{% for upload in uploads %} |
43 |
43 |
{% if upload.assignment == assignment %} |
44 |
44 |
{% trans "Uploaded:"%} {{ upload.upload_time|date:"SHORT_DATETIME_FORMAT" }}<br /> |
45 |
45 |
{% if upload.comment %} |
46 |
46 |
<p>{{ upload.comment }}</p> |
47 |
47 |
{% endif %} |
48 |
48 |
{% if upload.upload_time > assignment.deadline %} |
49 |
49 |
<strong>{% trans "This upload is overdue." %}</strong> |
50 |
50 |
{% endif %} |
51 |
51 |
{% endif %} |
52 |
52 |
{% empty %} |
53 |
53 |
{% with now as current_time %} |
54 |
54 |
{% if current_time > assignment.deadline %} |
55 |
55 |
<p> |
56 |
56 |
<strong> |
57 |
57 |
{% blocktrans %} |
58 |
58 |
You have failed to provide an upload for this |
59 |
59 |
assignment. Any future uploads will be automatically |
60 |
60 |
overdue. |
61 |
61 |
{% endblocktrans %} |
62 |
62 |
</strong> |
63 |
63 |
</p> |
64 |
64 |
{% else %} |
65 |
65 |
<p> |
66 |
66 |
{% blocktrans %} |
67 |
67 |
You haven't uploaded anything for this assignment |
68 |
68 |
yet. |
69 |
69 |
{% endblocktrans %} |
70 |
70 |
</p> |
71 |
71 |
{% endif %} |
72 |
72 |
{% endwith %} |
73 |
73 |
{% endfor %} |
74 |
74 |
<h5>{% trans "Upload a task" %}</h5> |
75 |
75 |
<form action="{% url "courses-course-index" course.slug_name %}" method="post"> |
76 |
76 |
{% csrf_token %} {# todo i don't think that's necessary here #} |
77 |
77 |
{% include "joeni/form.djhtml" with form=upload_form %} |
78 |
78 |
<input type="submit" value="{% trans "Submit" %}" /> |
79 |
79 |
</form> |
80 |
80 |
{% endif %} |
81 |
81 |
</div> |
82 |
82 |
{% endfor %} |
83 |
83 |
</div> |
84 |
84 |
<h1 id="{% trans "management" %}">{% trans "Course management" %}</h1> |
85 |
85 |
<style> |
86 |
86 |
a.btn { |
87 |
87 |
color: #{{ course.color }}; |
88 |
88 |
border-color: #{{ course.color }}; |
89 |
89 |
} |
90 |
90 |
a.btn:hover { |
91 |
91 |
color: white; |
92 |
92 |
background-color: #{{ course.color }}; |
93 |
93 |
} |
94 |
94 |
</style> |
95 |
95 |
<a class="btn" href="{% url "courses-eci" course_slug=course.slug_name %}"> |
96 |
96 |
{% trans "Edit course page" %} |
97 |
97 |
</a> |
98 |
98 |
<a class="btn" href="{% url "courses-results" course_slug=course.slug_name %}"> |
99 |
99 |
{% trans "Student results" %} |
100 |
100 |
</a> |
101 |
101 |
<h2 id="{% trans "students" %}">{% trans "Students" %}</h2> |
102 |
102 |
<table> |
103 |
103 |
<tr> |
104 |
104 |
<th>{% trans "Student name" %}</th> |
105 |
105 |
<th>{% trans "Student number" %}</th> |
106 |
106 |
<th>{% trans "First result" %}</th> |
107 |
107 |
<th>{% trans "Second result" %}</th> |
108 |
108 |
<th>{% trans "Decision" %}</th> |
109 |
109 |
</tr> |
110 |
110 |
{% for student in student_list %} |
111 |
111 |
<tr> |
112 |
112 |
<td>{{ student.student }}</td> |
113 |
113 |
<td>{{ student.student.number }}</td> |
114 |
114 |
<td>{{ course_result.first_score|default:"-" }}</td> |
115 |
- | <td>{{ course_result.second_score|default:"-" }}</td> |
116 |
- | <td>{% with result=course_result.result %} |
117 |
- | {% if result == "CRED" or result == "VRST" or result == "TLRD" or result == "ITLR"%} |
+ |
115 |
<td>{{ student.second_score|default:"-" }}</td> |
+ |
116 |
<td>{% with result=student.result %} |
+ |
117 |
{% if result == "CRED" or result == "VRST" or result == "TLRD" or result == "ITLR"%} |
118 |
118 |
<span style="color:green;"> |
119 |
119 |
{% elif result == "FAIL" %} |
120 |
120 |
<span style="color:red;"> |
121 |
121 |
{% elif result == "BDRG" %} |
122 |
122 |
<span style="background-color:red; color:white;"> |
123 |
123 |
{% elif result == "STOP" %} |
124 |
124 |
<span style="color:black;"> |
125 |
125 |
{% endif %} |
126 |
126 |
{{ course_result.get_result_display }}</span> |
127 |
- | {% endwith %}</td> |
+ |
127 |
{% endwith %}</td> |
128 |
128 |
</tr> |
129 |
129 |
{% endfor %} |
130 |
130 |
</table> |
131 |
131 |
{% endblock main %} |
132 |
132 |
courses/views.py ¶
2 additions and 2 deletions.
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 |
- | context['student_list'] = administration.models.CourseResult.objects.all() |
55 |
- | |
+ |
54 |
# FIXME I disabled the year filter for testing purposes. Enable in deployment. |
+ |
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 |
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 |