Skip to content

Commit a1ed25a

Browse files
committed
added more quizzes and redirect to quiz result after quiz completion
1 parent f895eb1 commit a1ed25a

File tree

6 files changed

+76
-5
lines changed

6 files changed

+76
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
[![Django Version](https://img.shields.io/badge/django-3.0-brightgreen.svg)](https://djangoproject.com)
55
[![CircleCI](https://circleci.com/gh/suhailvs/django-schools.svg?style=svg)](https://circleci.com/gh/suhailvs/django-schools)
66

7+
## [demo](https://djangoschools.herokuapp.com/)
8+
79
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.
810

911
![Django School Screenshot](https://simpleisbetterthancomplex.com/media/2018/01/teacher-quiz.png)

django_school/classroom/fixtures/datas.json

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
{"model": "classroom.question", "pk": 11, "fields": {"quiz": 2, "text": "An advantage of burning coal for energy is"}},
1414
{"model": "classroom.question", "pk": 12, "fields": {"quiz": 2, "text": "An advantage of using natural gas as a form of energy is"}},
1515
{"model": "classroom.question", "pk": 13, "fields": {"quiz": 2, "text": "What do geothermal and solar energy have in common?"}},
16+
{"model": "classroom.question", "pk": 14, "fields": {"quiz": 3, "text": "What happens when url.py file is edited while the development server is still running?"}},
17+
{"model": "classroom.question", "pk": 15, "fields": {"quiz": 3, "text": "Which setting contains the parameter of main-urls file?"}},
18+
{"model": "classroom.question", "pk": 16, "fields": {"quiz": 3, "text": "What is the purpose of __init__.py in project directories?"}},
19+
{"model": "classroom.question", "pk": 17, "fields": {"quiz": 3, "text": "Which method is used instead of path() in urls.py to pass in regular expressions as routes?"}},
20+
{"model": "classroom.question", "pk": 18, "fields": {"quiz": 3, "text": "What does {{ forloop.counter }} inside a forloop tag prints?"}},
21+
{"model": "classroom.question", "pk": 19, "fields": {"quiz": 3, "text": "This template {# #} is used for?"}},
22+
{"model": "classroom.question", "pk": 20, "fields": {"quiz": 4, "text": "What does {% include %} does?"}},
23+
{"model": "classroom.question", "pk": 21, "fields": {"quiz": 4, "text": "What would \"Post.objects.filter(heading=\"Post 1\")\""}},
24+
{"model": "classroom.question", "pk": 22, "fields": {"quiz": 4, "text": "Suppose you want to count the number of books in Django with \"books = Book.objects.all()\". Which implementation would be fastest?"}},
25+
{"model": "classroom.question", "pk": 23, "fields": {"quiz": 5, "text": "What is the name of the file that Django provides for managing a newly-created project and its applications?"}},
26+
{"model": "classroom.question", "pk": 24, "fields": {"quiz": 5, "text": "What task do migrations automate?"}},
27+
{"model": "classroom.question", "pk": 25, "fields": {"quiz": 5, "text": "What kind of relation is defined between models Order and OrderItems by invoking ForeignKey(Order) in the class definition for model OrderItems?"}},
1628

1729
{"model": "classroom.answer", "pk": 1, "fields": {"question": 1, "text": "June 29 of 1919", "is_correct": true}},
1830
{"model": "classroom.answer", "pk": 2, "fields": {"question": 1, "text": "June 29 of 1920", "is_correct": false}},
@@ -30,7 +42,6 @@
3042
{"model": "classroom.answer", "pk": 14, "fields": {"question": 4, "text": "What was the name of the new government in Germany after World War 1?", "is_correct": true}},
3143
{"model": "classroom.answer", "pk": 15, "fields": {"question": 4, "text": "Were the Big Three happy about the outcome of the Treaty of Versailles?", "is_correct": false}},
3244
{"model": "classroom.answer", "pk": 16, "fields": {"question": 4, "text": "How much money did Germany have to pay as a reparation?", "is_correct": false}},
33-
3445
{"model": "classroom.answer", "pk": 17, "fields": {"question": 5, "text": "no greenhouse gases", "is_correct": true}},
3546
{"model": "classroom.answer", "pk": 18, "fields": {"question": 5, "text": "lots of pollution", "is_correct": false}},
3647
{"model": "classroom.answer", "pk": 19, "fields": {"question": 5, "text": "it is available even on cloudy days", "is_correct": false}},
@@ -58,11 +69,59 @@
5869
{"model": "classroom.answer", "pk": 41, "fields": {"question": 13, "text": "they both use sunlight to generate energy", "is_correct": false}},
5970
{"model": "classroom.answer", "pk": 42, "fields": {"question": 13, "text": "both are non-renewable energy sources", "is_correct": false}},
6071
{"model": "classroom.answer", "pk": 43, "fields": {"question": 13, "text": "neither produce greenhouse gass", "is_correct": true}},
72+
{"model": "classroom.answer", "pk": 44, "fields": {"question": 14, "text": "Development server terminates.", "is_correct": false}},
73+
{"model": "classroom.answer", "pk": 45, "fields": {"question": 14, "text": "The development server automatically restarts.", "is_correct": true}},
74+
{"model": "classroom.answer", "pk": 46, "fields": {"question": 14, "text": "The development server does nothing.", "is_correct": false}},
75+
{"model": "classroom.answer", "pk": 47, "fields": {"question": 14, "text": "The web page is automatically reloaded.", "is_correct": false}},
76+
{"model": "classroom.answer", "pk": 48, "fields": {"question": 15, "text": "ROOT_URLCONF", "is_correct": true}},
77+
{"model": "classroom.answer", "pk": 49, "fields": {"question": 15, "text": "MAIN_URLCONF", "is_correct": false}},
78+
{"model": "classroom.answer", "pk": 50, "fields": {"question": 15, "text": "STATIC_URL", "is_correct": false}},
79+
{"model": "classroom.answer", "pk": 51, "fields": {"question": 15, "text": "MEDIA_URL", "is_correct": false}},
80+
{"model": "classroom.answer", "pk": 52, "fields": {"question": 16, "text": "It allows Python to recognise the folder as package.", "is_correct": true}},
81+
{"model": "classroom.answer", "pk": 53, "fields": {"question": 16, "text": "It is useless and can be deleted.", "is_correct": false}},
82+
{"model": "classroom.answer", "pk": 54, "fields": {"question": 16, "text": "It is used to initialise any empty values.", "is_correct": false}},
83+
{"model": "classroom.answer", "pk": 55, "fields": {"question": 16, "text": "None of the above", "is_correct": false}},
84+
{"model": "classroom.answer", "pk": 56, "fields": {"question": 17, "text": "static()", "is_correct": false}},
85+
{"model": "classroom.answer", "pk": 57, "fields": {"question": 17, "text": "re_path()", "is_correct": true}},
86+
{"model": "classroom.answer", "pk": 58, "fields": {"question": 17, "text": "include()", "is_correct": false}},
87+
{"model": "classroom.answer", "pk": 59, "fields": {"question": 17, "text": "None of the above", "is_correct": false}},
88+
{"model": "classroom.answer", "pk": 60, "fields": {"question": 18, "text": "The current iteration of the loop (1-indexed)", "is_correct": true}},
89+
{"model": "classroom.answer", "pk": 61, "fields": {"question": 18, "text": "The current iteration of the loop (0-indexed)", "is_correct": false}},
90+
{"model": "classroom.answer", "pk": 62, "fields": {"question": 18, "text": "It will not print \"loop variable is not defined\"", "is_correct": false}},
91+
{"model": "classroom.answer", "pk": 63, "fields": {"question": 18, "text": "None of the above", "is_correct": false}},
92+
{"model": "classroom.answer", "pk": 64, "fields": {"question": 19, "text": "It is used for business logic.", "is_correct": false}},
93+
{"model": "classroom.answer", "pk": 65, "fields": {"question": 19, "text": "It is comment in template language.", "is_correct": true}},
94+
{"model": "classroom.answer", "pk": 66, "fields": {"question": 19, "text": "It will raise an exception.", "is_correct": false}},
95+
{"model": "classroom.answer", "pk": 67, "fields": {"question": 19, "text": "None of the above", "is_correct": false}},
96+
{"model": "classroom.answer", "pk": 68, "fields": {"question": 20, "text": "It will include another template.", "is_correct": true}},
97+
{"model": "classroom.answer", "pk": 69, "fields": {"question": 20, "text": "It will include content from another template having the same templates defined.", "is_correct": false}},
98+
{"model": "classroom.answer", "pk": 70, "fields": {"question": 20, "text": "It is the same as {% extend %}.", "is_correct": false}},
99+
{"model": "classroom.answer", "pk": 71, "fields": {"question": 20, "text": "None of the above", "is_correct": false}},
100+
{"model": "classroom.answer", "pk": 72, "fields": {"question": 21, "text": "It will print the first object which matched with heading \"Post 1\"", "is_correct": false}},
101+
{"model": "classroom.answer", "pk": 73, "fields": {"question": 21, "text": "It will print all objects", "is_correct": false}},
102+
{"model": "classroom.answer", "pk": 74, "fields": {"question": 21, "text": "It will print all the objects which match the heading \"Post 1\"", "is_correct": true}},
103+
{"model": "classroom.answer", "pk": 75, "fields": {"question": 22, "text": "Database level Implementation - books.count()", "is_correct": true}},
104+
{"model": "classroom.answer", "pk": 76, "fields": {"question": 22, "text": "Python Implementation - len(books)", "is_correct": false}},
105+
{"model": "classroom.answer", "pk": 77, "fields": {"question": 22, "text": "Template Language Implementation - {{ books | length }}", "is_correct": false}},
106+
{"model": "classroom.answer", "pk": 78, "fields": {"question": 22, "text": "None of the above", "is_correct": false}},
107+
{"model": "classroom.answer", "pk": 79, "fields": {"question": 23, "text": "django", "is_correct": false}},
108+
{"model": "classroom.answer", "pk": 80, "fields": {"question": 23, "text": "manage.py", "is_correct": true}},
109+
{"model": "classroom.answer", "pk": 81, "fields": {"question": 23, "text": "apachectl", "is_correct": false}},
110+
{"model": "classroom.answer", "pk": 82, "fields": {"question": 23, "text": "pip", "is_correct": false}},
111+
{"model": "classroom.answer", "pk": 83, "fields": {"question": 24, "text": "Structural changes to project database tables to reflect changes to data models", "is_correct": true}},
112+
{"model": "classroom.answer", "pk": 84, "fields": {"question": 24, "text": "Deployment of project data to production server", "is_correct": false}},
113+
{"model": "classroom.answer", "pk": 85, "fields": {"question": 24, "text": "Internationalization of site content to reflect local differences in local date and currency formatting conventions", "is_correct": false}},
114+
{"model": "classroom.answer", "pk": 86, "fields": {"question": 25, "text": "Many to one: Multiple OrderItems can have same Order", "is_correct": true}},
115+
{"model": "classroom.answer", "pk": 87, "fields": {"question": 25, "text": "One to one: Each OrderItems must have Unique Order", "is_correct": false}},
116+
{"model": "classroom.answer", "pk": 88, "fields": {"question": 25, "text": "One to many: Each OrderItems can have Multiple Order", "is_correct": false}},
61117

62118
{"model": "classroom.quiz", "pk": 1, "fields": {"owner": 1, "name": "World War 1", "subject": 5}},
63119
{"model": "classroom.quiz", "pk": 2, "fields": {"owner": 1, "name": "EnergySources", "subject": 4}},
120+
{"model": "classroom.quiz", "pk": 3, "fields": {"owner": 1, "name": "Django2", "subject": 2}},
121+
{"model": "classroom.quiz", "pk": 4, "fields": {"owner": 1, "name": "Django3", "subject": 2}},
122+
{"model": "classroom.quiz", "pk": 5, "fields": {"owner": 1, "name": "Django1", "subject": 2}},
64123

65-
{"model": "classroom.user", "pk": 1, "fields": {"password": "pbkdf2_sha256$180000$og6o8PzLsRNC$/Ay4/y7/plwM2t3MGrzUoGvTKCqRlrSYmCwrkL9VrVY=", "last_login": "2020-03-19T02:20:24.490Z", "is_superuser": false, "username": "teacher", "first_name": "Teacher", "last_name": "", "email": "", "is_staff": true, "is_active": true, "date_joined": "2020-03-19T02:20:24.014Z", "is_student": false, "is_teacher": true, "groups": [], "user_permissions": []}},
124+
{"model": "classroom.user", "pk": 1, "fields": {"password": "pbkdf2_sha256$180000$og6o8PzLsRNC$/Ay4/y7/plwM2t3MGrzUoGvTKCqRlrSYmCwrkL9VrVY=", "last_login": "2020-03-19T02:20:24.490Z", "is_superuser": true, "username": "teacher", "first_name": "Teacher", "last_name": "", "email": "", "is_staff": true, "is_active": true, "date_joined": "2020-03-19T02:20:24.014Z", "is_student": false, "is_teacher": true, "groups": [], "user_permissions": []}},
66125
{"model": "classroom.user", "pk": 2, "fields": {"password": "pbkdf2_sha256$180000$DBSRJ8mc0QUn$aCBAYWUqewnK+nJ1FqSBQpnvY33P/FpK2CAYyQuX1p0=", "last_login": "2020-03-19T02:19:48.856Z", "is_superuser": false, "username": "student", "first_name": "Student", "last_name": "", "email": "", "is_staff": false, "is_active": true, "date_joined": "2020-03-19T02:19:48.411Z", "is_student": true, "is_teacher": false, "groups": [], "user_permissions": []}},
67126

68127
{"model": "classroom.student", "pk": 2, "fields": {"score": 0, "interests": [2, 3, 4, 5]}}

django_school/classroom/templates/classroom/home.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ <h3>What's this about?</h3>
1414
based on their interests.
1515
</p>
1616
<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>
17-
<p class="mb-0">Vitor Freitas<br><a href="https://twitter.com/vitorfs/">@vitorfs</a></p>
17+
<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>
1818
{% endblock %}

django_school/classroom/views/students.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ def take_quiz(request, pk):
128128
messages.warning(request, 'Better luck next time! Your score for the quiz %s was %s.' % (quiz.name, percentage))
129129
else:
130130
messages.success(request, 'Congratulations! You completed the quiz %s with success! You scored %s points.' % (quiz.name, percentage))
131-
return redirect('students:quiz_list')
131+
# return redirect('students:quiz_list')
132+
return redirect('students:student_quiz_results', pk)
132133
else:
133134
form = TakeQuizForm(question=question)
134135

django_school/django_school/settings.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,15 @@
8787
'ENGINE': 'django.db.backends.sqlite3',
8888
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
8989
}
90+
# Heroku Database
91+
# 'default': {
92+
# 'ENGINE': 'django.db.backends.postgresql',
93+
# 'NAME': 'd5hknnaihi88bf',
94+
# 'USER': 'vpidynpvpkjahr',
95+
# 'PASSWORD': '3005007b069891de106545657b9cb998dcb3bcf974d2d4f1c57d6f2746c692af',
96+
# 'HOST': 'ec2-18-210-51-239.compute-1.amazonaws.com',
97+
# 'PORT': '5432',
98+
# }
9099
}
91100

92101

django_school/templates/base.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ <h1 class="logo">
6363
/
6464
<a href="https://simpleisbetterthancomplex.com/tutorial/2018/01/18/how-to-implement-multiple-user-types-with-django.html">Read more about this example</a>
6565
/
66-
<a href="https://github.com/sibtc/django-multiple-user-types-example">GitHub repository</a>
66+
<a href="https://github.com/suhailvs/django-schools/">GitHub repository</a>
6767
</footer>
6868
</div>
6969
</div>

0 commit comments

Comments
 (0)