Skip to content

Added student result page #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b3876ac
added fixtures: Initial datas -> some questions, a teacher(user: sume…
suhailvs Jun 21, 2018
b3aa568
this closes #5, logged in user can access login url
suhailvs May 14, 2019
0fc274b
added circleci
suhailvs Jul 3, 2019
3811fa3
updated requirements and added login redirect for authusers
suhailvs Jul 3, 2019
cac6306
added circleci badge
suhailvs Jul 3, 2019
19e2950
added student quiz result
suhailvs Jul 5, 2019
60e5a6e
added nth question in quiz
suhailvs Jul 10, 2019
4035035
updated Readme for virtualenv instructions
suhailvs Jul 10, 2019
76671c0
added login page tests
suhailvs Jul 11, 2019
4eaa73c
added reputation
suhailvs Oct 8, 2019
105f322
added energy sources quiz
suhailvs Mar 19, 2020
f895eb1
added django admin
suhailvs Apr 5, 2020
a1ed25a
added more quizzes and redirect to quiz result after quiz completion
suhailvs Apr 5, 2020
a96019c
added students list
suhailvs Apr 15, 2020
2417e74
added jquery datatable in quiz list
suhailvs Apr 18, 2020
f10fb04
added answer option button design
suhailvs Apr 19, 2020
3fb6a67
added top subject in student list
suhailvs Apr 19, 2020
96f9e3e
show all quizzess.
suhailvs Apr 19, 2020
387285c
moved student_subjects to quiz list
suhailvs Apr 19, 2020
ba83a56
quizlist datatable number of questions
suhailvs Apr 22, 2020
0de01ae
fixed redirect to login
suhailvs Apr 24, 2020
fb68ea9
added score(number of correct answers) in quiz result
suhailvs Jul 24, 2020
2e6ed35
Update README.md
suhailvs Aug 9, 2020
9b621db
added contact email
suhailvs Aug 9, 2020
c926f08
Copied from heroku branch: student detail page
suhailvs Dec 23, 2020
8a76ff8
[WIP] Mathjax : added math formulas in questions
suhailvs Dec 27, 2020
ea7d6e9
Merge branch 'mathjax'
suhailvs Dec 28, 2020
7688449
Update README.md
suhailvs Jan 15, 2021
14b32c2
student_list and quiz_list pages for guest users
suhailvs Jan 17, 2021
2dff43d
Merge branch 'master' of github.com:suhailvs/django-schools
suhailvs Jan 17, 2021
092f551
added student_detail page for guest users
suhailvs Jan 17, 2021
4ddd971
added nav tab in login and signup urls
suhailvs Jan 30, 2021
cadd752
signup direct to student signup page
suhailvs Mar 16, 2021
2b5e02b
added signup url in login page
suhailvs Mar 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
version: 2 # use CircleCI 2.0
jobs: # A basic unit of work in a run
build: # runs not using Workflows must have a `build` job as entry point
# directory where steps are run
working_directory: ~/circleci-demo-python-django
docker: # run the steps with Docker
# CircleCI Python images available at: https://hub.docker.com/r/circleci/python/
- image: circleci/python:3.6.4
environment: # environment variables for primary container
PIPENV_VENV_IN_PROJECT: true
DATABASE_URL: postgresql://root@localhost/circle_test?sslmode=disable
# CircleCI PostgreSQL images available at: https://hub.docker.com/r/circleci/postgres/
- image: circleci/postgres:9.6.2
environment: # environment variables for the Postgres container.
POSTGRES_USER: root
POSTGRES_DB: circle_test
steps: # steps that comprise the `build` job
- checkout # check out source code to working directory
- run: sudo chown -R circleci:circleci /usr/local/bin
- run: sudo chown -R circleci:circleci /usr/local/lib/python3.6/site-packages
- restore_cache:
# Read about caching dependencies: https://circleci.com/docs/2.0/caching/
key: deps9-{{ .Branch }}-{{ checksum "Pipfile.lock" }}
- run:
command: |
sudo pip install pipenv
pipenv install
- save_cache: # cache Python dependencies using checksum of Pipfile as the cache-key
key: deps9-{{ .Branch }}-{{ checksum "Pipfile.lock" }}
paths:
- ".venv"
- "/usr/local/bin"
- "/usr/local/lib/python3.6/site-packages"
- run:
command: |
pipenv run python django_school/manage.py test
- store_test_results: # Upload test results for display in Test Summary: https://circleci.com/docs/2.0/collect-test-data/
path: test-results
- store_artifacts: # Upload test summary for display in Artifacts: https://circleci.com/docs/2.0/artifacts/
path: test-results
destination: tr1
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
media/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
33 changes: 23 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Django School
# [Django School](https://djangoschools.herokuapp.com/)

[![Python Version](https://img.shields.io/badge/python-3.6-brightgreen.svg)](https://python.org)
[![Django Version](https://img.shields.io/badge/django-2.0-brightgreen.svg)](https://djangoproject.com)
[![Django Version](https://img.shields.io/badge/django-3.0-brightgreen.svg)](https://djangoproject.com)
[![CircleCI](https://circleci.com/gh/suhailvs/django-schools.svg?style=svg)](https://circleci.com/gh/suhailvs/django-schools)

## [demo](https://djangoschools.herokuapp.com/)

This is an example project to illustrate an implementation of multiple user types. In this Django app, teachers can create quizzes and students can sign up and take quizzes related to their interests.

Expand All @@ -14,28 +17,38 @@ Read the blog post [How to Implement Multiple User Types with Django](https://si
First, clone the repository to your local machine:

```bash
git clone https://github.com/sibtc/django-multiple-user-types-example.git
git clone https://github.com/suhailvs/django-schools
```

Install the requirements:
Create Virtual Env and Install the requirements:

```bash
cd django-schools
python3 -m venv env
source ./env/bin/activate
pip install -r requirements.txt
```

Create the database:
Create the database and run the development server:

```bash
cd django_school
python manage.py migrate
python manage.py loaddata datas.json
python manage.py runserver
```

Finally, run the development server:
The project will be available at http://127.0.0.1:8000, Login using::

```bash
python manage.py runserver
```
**Teacher**

+ username: `teacher`
+ password: `teacher`

**Student**

The project will be available at **127.0.0.1:8000**.
+ username: `student`
+ password: `student`


## License
Expand Down
12 changes: 12 additions & 0 deletions django_school/classroom/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.contrib import admin

# Register your models here.
from .models import User, Subject, Quiz, Question, Answer, Student, TakenQuiz

admin.site.register(User)
admin.site.register(Subject)
admin.site.register(Quiz)
admin.site.register(Question)
admin.site.register(Answer)
admin.site.register(Student)
admin.site.register(TakenQuiz)
128 changes: 128 additions & 0 deletions django_school/classroom/fixtures/datas.json

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions django_school/classroom/fixtures/quizzes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[{"model": "classroom.quiz", "pk": 2, "fields": {"owner": 1, "name": "KEAM 2017 paper 1", "subject": 3}},

{"model": "classroom.answer", "pk": 1, "fields": {"question": 1, "text": "$$\\ce{H2O + HCl <=> H3O+ + Cl-}$$", "is_correct": true}},
{"model": "classroom.answer", "pk": 2, "fields": {"question": 1, "text": "gdfs", "is_correct": false}},
{"model": "classroom.answer", "pk": 3, "fields": {"question": 2, "text": "(a) and (b)", "is_correct": true}},
{"model": "classroom.answer", "pk": 4, "fields": {"question": 2, "text": "(a) and (c)", "is_correct": false}},
{"model": "classroom.answer", "pk": 5, "fields": {"question": 2, "text": "(a), (b) and (c)", "is_correct": false}},
{"model": "classroom.answer", "pk": 6, "fields": {"question": 2, "text": "all", "is_correct": false}},
{"model": "classroom.answer", "pk": 7, "fields": {"question": 3, "text": "combination reaction.", "is_correct": false}},
{"model": "classroom.answer", "pk": 8, "fields": {"question": 3, "text": "double displacement reaction.", "is_correct": false}},
{"model": "classroom.answer", "pk": 9, "fields": {"question": 3, "text": "decomposition reaction.", "is_correct": false}},
{"model": "classroom.answer", "pk": 10, "fields": {"question": 3, "text": "displacement reaction.", "is_correct": true}},
{"model": "classroom.answer", "pk": 11, "fields": {"question": 4, "text": "Hydrogen gas and iron chloride are produced.", "is_correct": true}},
{"model": "classroom.answer", "pk": 12, "fields": {"question": 4, "text": "Chlorine gas and iron hydroxide are produced.", "is_correct": false}},
{"model": "classroom.answer", "pk": 13, "fields": {"question": 4, "text": "No reaction takes place.", "is_correct": false}},
{"model": "classroom.answer", "pk": 14, "fields": {"question": 4, "text": "Iron salt and water are produce", "is_correct": false}},

{"model": "classroom.answer", "pk": 15, "fields": {"question": 5, "text": "45", "is_correct": false}},
{"model": "classroom.answer", "pk": 16, "fields": {"question": 5, "text": "45\\(\\pi\\)", "is_correct": true}},
{"model": "classroom.answer", "pk": 17, "fields": {"question": 5, "text": "250\\(\\pi\\)", "is_correct": false}},
{"model": "classroom.answer", "pk": 18, "fields": {"question": 5, "text": "250", "is_correct": false}},
{"model": "classroom.answer", "pk": 19, "fields": {"question": 5, "text": "450", "is_correct": false}},
{"model": "classroom.answer", "pk": 20, "fields": {"question": 6, "text": "can be decreased by increasing the number of readings and averaging them", "is_correct": true}},
{"model": "classroom.answer", "pk": 21, "fields": {"question": 6, "text": "can be decreased by changing the person who takes the reading", "is_correct": false}},
{"model": "classroom.answer", "pk": 22, "fields": {"question": 6, "text": "can be decreased by using new instrument", "is_correct": false}},
{"model": "classroom.answer", "pk": 23, "fields": {"question": 6, "text": "can be decreased by using a different method in taking the reading", "is_correct": false}},
{"model": "classroom.answer", "pk": 24, "fields": {"question": 6, "text": "can never be decreased", "is_correct": false}},
{"model": "classroom.answer", "pk": 25, "fields": {"question": 7, "text": "4.99 s", "is_correct": true}},
{"model": "classroom.answer", "pk": 26, "fields": {"question": 7, "text": "5.0 s", "is_correct": false}},
{"model": "classroom.answer", "pk": 27, "fields": {"question": 7, "text": "5.00 s", "is_correct": false}},
{"model": "classroom.answer", "pk": 28, "fields": {"question": 7, "text": "4.9 s", "is_correct": false}},
{"model": "classroom.answer", "pk": 29, "fields": {"question": 7, "text": "5.1 s", "is_correct": false}},
{"model": "classroom.answer", "pk": 30, "fields": {"question": 8, "text": "\\(40 km/h^2\\)", "is_correct": true}},
{"model": "classroom.answer", "pk": 31, "fields": {"question": 8, "text": "\\(80 km/h^2\\)", "is_correct": false}},
{"model": "classroom.answer", "pk": 32, "fields": {"question": 8, "text": "\\(100 km/h^2\\)", "is_correct": false}},
{"model": "classroom.answer", "pk": 33, "fields": {"question": 8, "text": "\\(120 km/h^2\\)", "is_correct": false}},
{"model": "classroom.answer", "pk": 34, "fields": {"question": 8, "text": "\\(160 km/h^2\\)", "is_correct": false}}

]
8 changes: 8 additions & 0 deletions django_school/classroom/functional_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# pip install selenium
# https://askubuntu.com/questions/870530/how-to-install-geckodriver-in-ubuntu

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://localhost:8000')

assert 'Django' in browser.title
29 changes: 29 additions & 0 deletions django_school/classroom/migrations/0003_auto_20191008_0704.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 2.2.3 on 2019-10-08 07:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('classroom', '0002_create_initial_subjects'),
]

operations = [
migrations.AddField(
model_name='student',
name='score',
field=models.IntegerField(default=0),
),
migrations.AddField(
model_name='takenquiz',
name='percentage',
field=models.FloatField(default=0),
preserve_default=False,
),
migrations.AlterField(
model_name='takenquiz',
name='score',
field=models.IntegerField(),
),
]
18 changes: 18 additions & 0 deletions django_school/classroom/migrations/0004_auto_20200418_1555.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.0.4 on 2020-04-18 15:55

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('classroom', '0003_auto_20191008_0704'),
]

operations = [
migrations.AlterField(
model_name='question',
name='text',
field=models.TextField(verbose_name='Question'),
),
]
8 changes: 6 additions & 2 deletions django_school/classroom/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def __str__(self):

class Question(models.Model):
quiz = models.ForeignKey(Quiz, on_delete=models.CASCADE, related_name='questions')
text = models.CharField('Question', max_length=255)
text = models.TextField('Question')

def __str__(self):
return self.text
Expand All @@ -52,6 +52,9 @@ class Student(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
quizzes = models.ManyToManyField(Quiz, through='TakenQuiz')
interests = models.ManyToManyField(Subject, related_name='interested_students')

# User reputation score.
score = models.IntegerField(default=0)

def get_unanswered_questions(self, quiz):
answered_questions = self.quiz_answers \
Expand All @@ -67,7 +70,8 @@ def __str__(self):
class TakenQuiz(models.Model):
student = models.ForeignKey(Student, on_delete=models.CASCADE, related_name='taken_quizzes')
quiz = models.ForeignKey(Quiz, on_delete=models.CASCADE, related_name='taken_quizzes')
score = models.FloatField()
score = models.IntegerField()
percentage = models.FloatField()
date = models.DateTimeField(auto_now_add=True)


Expand Down
15 changes: 15 additions & 0 deletions django_school/classroom/templates/classroom/_guest_header.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<ul class="nav nav-tabs mb-3">

<li class="nav-item">
<a class="nav-link{% if active == 'quizzes' %} active{% endif %}" href="{% url 'home' %}">Quizzes</a>
</li>
<li class="nav-item">
<a class="nav-link{% if active == 'students' %} active{% endif %}" href="{% url 'students:student_list' %}">Students</a>
</li>
<li class="nav-item">
<a class="nav-link{% if active == 'about' %} active{% endif %}" href="{% url 'about' %}">About</a>
</li>
</ul>



Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{% extends 'base.html' %}

{% block content %}
{% include 'classroom/_guest_header.html' with active='about' %}
<h2>Welcome to the Django Schools! <span class="icon-emo-happy"></span></h2>
<p class="lead">
If you already have an account, go ahead and <a href="{% url 'login' %}">log in</a>. If you are new to Django Schools, get started
by creating a <a href="{% url 'student_signup' %}">student account</a> or a <a href="{% url 'teacher_signup' %}">teacher account</a>.
by creating a <a href="{% url 'signup' %}">student account</a> or a <a href="{% url 'teacher_signup' %}">teacher account</a>.
</p>
<hr>
<h3>What's this about?</h3>
Expand All @@ -14,5 +15,5 @@ <h3>What's this about?</h3>
based on their interests.
</p>
<p>Want to run this code locally? <a href="https://github.com/sibtc/django-multiple-user-types-example/blob/master/README.md">Read detailed instructions on how to run this project</a>.</p>
<p class="mb-0">Vitor Freitas<br><a href="https://twitter.com/vitorfs/">@vitorfs</a></p>
<p class="mb-0">Vitor Freitas <a href="https://twitter.com/vitorfs/">@vitorfs</a>, Suhail VS <a href="https://twitter.com/suhailvs/">@suhailvs</a></p>
{% endblock %}
48 changes: 48 additions & 0 deletions django_school/classroom/templates/classroom/quiz_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{% extends 'base.html' %}
{% load static %}

{% block css %}
<link rel="stylesheet" type="text/css" href="{% static 'datatables/dataTables.bootstrap4.min.css' %}">
{% endblock %}

{% block content %}
{% include 'classroom/_guest_header.html' with active='quizzes' %}

<table class="table table-bordered mb-0" id="tb_quizlist" >
<thead>
<tr>
<th>Quiz</th>
<th class="d-none d-sm-table-cell">Subject</th>
<th class="d-none d-sm-table-cell">Questions</th>
<th></th>
</tr>
</thead>
<tbody>
{% for quiz in quizzes %}
<tr{% if quiz.subject.id in student_subjects %} style="background: #fdf7e3"{%endif%}>
<td class="align-middle">{{ quiz.name }}</td>
<td class="align-middle d-none d-sm-table-cell">{{ quiz.subject.get_html_badge }}</td>
<td class="align-middle d-none d-sm-table-cell">{{ quiz.questions_count }}</td>
<td class="text-right" data-orderable="false">
<a href="{% url 'students:take_quiz' quiz.pk %}" class="btn btn-primary">Start quiz</a>
</td>
</tr>
{% empty %}
<tr>
<td class="bg-light text-center font-italic" colspan="4">No quiz matching your interests right now.</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

{% block js %}
<script src="{% static 'js/jquery-3.3.1.min.js' %}"></script>
<script src="{% static 'datatables/jquery.dataTables.min.js' %}"></script>
<script src="{% static 'datatables/dataTables.bootstrap4.min.js' %}"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#tb_quizlist').DataTable({"order": [[ 2, "desc" ]]});
});
</script>
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<h2>Quizzes</h2>
<p class="text-muted">
Subjects:{% for subject in user.student.interests.all %} {{ subject.get_html_badge }}{% endfor %}
<a href="{% url 'students:student_interests' %}"><small>(update interests)</small></a>
</p>


<ul class="nav nav-tabs mb-3">
<li class="nav-item">
Expand All @@ -11,4 +8,7 @@ <h2>Quizzes</h2>
<li class="nav-item">
<a class="nav-link{% if active == 'taken' %} active{% endif %}" href="{% url 'students:taken_quiz_list' %}">Taken</a>
</li>
<li class="nav-item">
<a class="nav-link{% if active == 'students' %} active{% endif %}" href="{% url 'students:student_list' %}">Students</a>
</li>
</ul>
Loading