Skip to content

Commit b3f243f

Browse files
committed
added student details page
1 parent 54e5711 commit b3f243f

File tree

9 files changed

+68
-12
lines changed

9 files changed

+68
-12
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{% extends 'base.html' %}
2+
{% load static %}
3+
{% load quiz_extras %}
4+
5+
{% block content %}
6+
{% include 'classroom/students/_header.html' with active='students' %}
7+
8+
<div class="row">
9+
<div class="col-md-4">
10+
<img class="img-thumbnail" src="{{ student.user.email|gravatar_url:200 }}" width="200" height="200" alt="@{{ student.user.email}}">
11+
</div>
12+
<div class="col-md-8">
13+
<div class="card">
14+
<table class="table mb-0">
15+
16+
<tbody>
17+
<tr><td>Email</td><td>{{student.user.email}}</td></tr>
18+
<tr><td>Username</td><td>{{student.user.username}}</td></tr>
19+
<tr><td>Fullname</td><td>{{student.user.get_full_name}}</td></tr>
20+
<tr><td>POINTS</td><td>{{student.score}}</td></tr>
21+
</tbody>
22+
</table>
23+
</div>
24+
</div>
25+
</div><hr>
26+
<h3>Top Subjects</h3>
27+
{% for subject in subjects %}
28+
<span class="badge badge-primary" style="background-color:{{subject.quiz__subject__color}}">
29+
{{subject.quiz__subject__name}}
30+
</span> x {{subject.score}}
31+
{% endfor %}
32+
{% endblock %}

django_school/classroom/templates/classroom/students/student_list.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
{% for student in students %}
3030
<div class="col-sm-3">
3131
<div class="media">
32-
<a>
32+
<a href="{% url 'students:student_detail' student=student.user.id %}">
3333
<img class="mr-3" src="{{ student.user.username|gravatar_url:50 }}" alt="{{student.user.get_full_name}}">
3434
</a>
3535
<div class="media-body" style="font-size: 12px">
3636
<!-- <a href="#">{{user.get_full_name}}</a><br> -->
37-
{{student.user.username}}<br>
37+
<a href="{% url 'students:student_detail' student=student.user.id %}">{{student.user.username}}</a><br>
3838
<strong>{{student.score}}</strong><br>
3939
{{student.taken_quizzes.all|top_subject}}
4040
</div>

django_school/classroom/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
path('students/', include(([
99
path('', students.QuizListView.as_view(), name='quiz_list'),
1010
path('s/', students.StudentList.as_view(), name='student_list'),
11+
path('s/<int:student>/', students.StudentDetail.as_view(), name='student_detail'),
1112
path('interests/', students.StudentInterestsView.as_view(), name='student_interests'),
1213
path('taken/', students.TakenQuizListView.as_view(), name='taken_quiz_list'),
1314
path('quiz/<int:pk>/', students.take_quiz, name='take_quiz'),

django_school/classroom/views/classroom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def home(request):
1212
return redirect('teachers:quiz_change_list')
1313
else:
1414
return redirect('students:quiz_list')
15-
return render(request, 'classroom/home.html')
15+
return redirect('login') # render(request, 'classroom/home.html')
1616

1717

1818
def save_github_user(backend, user, response, *args, **kwargs):

django_school/classroom/views/students.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_context_data(self, **kwargs):
2929

3030
def form_valid(self, form):
3131
user = form.save()
32-
login(self.request, user)
32+
login(self.request, user, backend='django.contrib.auth.backends.ModelBackend')
3333
return redirect('students:quiz_list')
3434

3535

@@ -170,4 +170,15 @@ def get_queryset(self):
170170
queryset = queryset.filter(user__username__icontains = query)
171171
return queryset
172172

173-
173+
@method_decorator([login_required, student_required], name='dispatch')
174+
class StudentDetail(View):
175+
"""Show Details of a Student"""
176+
def get(self, request, **kwargs):
177+
student = Student.objects.get(user_id = kwargs['student'])
178+
subjects = student.taken_quizzes.all() \
179+
.values('quiz__subject__name','quiz__subject__color') \
180+
.annotate(score = Sum('score')) \
181+
.order_by('-score')
182+
183+
return render(request,'classroom/students/student_detail.html',
184+
{'student': student, 'subjects':subjects})

django_school/classroom/views/teachers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def get_context_data(self, **kwargs):
2929

3030
def form_valid(self, form):
3131
user = form.save()
32-
login(self.request, user)
32+
login(self.request, user, backend='django.contrib.auth.backends.ModelBackend')
3333
return redirect('teachers:quiz_change_list')
3434

3535

django_school/django_school/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
urlpatterns = [
77
path('admin/', admin.site.urls),
88
path('', include('classroom.urls')),
9-
# path('accounts/login/', auth_views.LoginView.as_view(redirect_authenticated_user=True), name='login'),
9+
path('accounts/login/', auth_views.LoginView.as_view(redirect_authenticated_user=True), name='login'),
1010
path('accounts/', include('django.contrib.auth.urls')),
1111
path('accounts/signup/', classroom.SignUpView.as_view(), name='signup'),
1212
path('accounts/signup/student/', students.StudentSignUpView.as_view(), name='student_signup'),

django_school/templates/base.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{% endblock %}
1919
</head>
2020
<body>
21-
<!-- <a href="https://github.com/sibtc/django-multiple-user-types-example"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a> -->
21+
<a href="https://github.com/suhailvs/django-schools"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
2222
<div class="container my-4">
2323
<div class="row justify-content-center">
2424
<div class="col-md-10 col-sm-12">
@@ -39,7 +39,14 @@ <h1 class="logo">
3939
</div>
4040
<div class="col-6 text-right">
4141
{% if user.is_authenticated %}
42-
<p class="pt-3"><strong>{{ user.username }}{% if user.is_student %} - {{user.student.score}}{% endif %}</strong> | <a href="{% url 'logout' %}">Log out</a>.</p>
42+
<p class="pt-3">
43+
{% if user.is_student %}
44+
<strong><a href="{% url 'students:student_detail' student=user.id %}">{{ user.username }}</a> - {{user.student.score}}</strong>
45+
{% else %}
46+
<strong>{{ user.username }}</strong>
47+
{% endif %}
48+
| <a href="{% url 'logout' %}">Log out</a>
49+
</p>
4350
{% else %}
4451
<a href="{% url 'login' %}" class="btn btn-light" role="button">Log in</a>
4552
<a href="{% url 'signup' %}" class="btn btn-primary" role="button">Sign up</a>

django_school/templates/registration/login.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@ <h2>Log in</h2>
2323
{{ form.password|as_crispy_field }}
2424
<button type="submit" class="btn btn-primary">Log in</button>
2525
</form>
26-
<br>
27-
<p><strong>-- OR --</strong></p>
28-
<a href="{% url 'social:begin' 'github' %}">Login with GitHub</a><br>
26+
<hr>
27+
<p class="text-center"><strong>-- OR --</strong></p>
28+
<a href="{% url 'social:begin' 'github' %}" class="btn btn-block" style="color: #fff;
29+
background-color: #444;">
30+
<svg width="25" height="25" viewBox="0 0 1024 1024" fill="none" xmlns="http://www.w3.org/2000/svg">
31+
<path fill-rule="evenodd" clip-rule="evenodd" d="M8 0C3.58 0 0 3.58 0 8C0 11.54 2.29 14.53 5.47 15.59C5.87 15.66 6.02 15.42 6.02 15.21C6.02 15.02 6.01 14.39 6.01 13.72C4 14.09 3.48 13.23 3.32 12.78C3.23 12.55 2.84 11.84 2.5 11.65C2.22 11.5 1.82 11.13 2.49 11.12C3.12 11.11 3.57 11.7 3.72 11.94C4.44 13.15 5.59 12.81 6.05 12.6C6.12 12.08 6.33 11.73 6.56 11.53C4.78 11.33 2.92 10.64 2.92 7.58C2.92 6.71 3.23 5.99 3.74 5.43C3.66 5.23 3.38 4.41 3.82 3.31C3.82 3.31 4.49 3.1 6.02 4.13C6.66 3.95 7.34 3.86 8.02 3.86C8.7 3.86 9.38 3.95 10.02 4.13C11.55 3.09 12.22 3.31 12.22 3.31C12.66 4.41 12.38 5.23 12.3 5.43C12.81 5.99 13.12 6.7 13.12 7.58C13.12 10.65 11.25 11.33 9.47 11.53C9.76 11.78 10.01 12.26 10.01 13.01C10.01 14.08 10 14.94 10 15.21C10 15.42 10.15 15.67 10.55 15.59C13.71 14.53 16 11.53 16 8C16 3.58 12.42 0 8 0Z" transform="scale(64)" fill="#1B1F23"/>
32+
</svg> Login with GitHub(Student)
33+
</a>
2934
</div>
3035
</div>
3136
{% endblock %}

0 commit comments

Comments
 (0)