Skip to content

Commit 22fa541

Browse files
authored
Merge pull request #53 from SomdattaNag/contribute
Django Quiz Form Project
2 parents be3c448 + c1fa0ed commit 22fa541

File tree

20 files changed

+635
-0
lines changed

20 files changed

+635
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == '__main__':
22+
main()

django Quiz Form/myproject/myproject/__init__.py

Whitespace-only changes.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
ASGI config for myproject project.
3+
4+
It exposes the ASGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/howto/deployment/asgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.asgi import get_asgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
15+
16+
application = get_asgi_application()
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
"""
2+
Django settings for myproject project.
3+
4+
Generated by 'django-admin startproject' using Django 5.1.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/5.1/ref/settings/
11+
"""
12+
import os
13+
from pathlib import Path
14+
15+
# Build paths inside the project like this: BASE_DIR / 'subdir'.
16+
BASE_DIR = Path(__file__).resolve().parent.parent
17+
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/5.1/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 'django-insecure-iquacd0nr82qi+)5-(6u8k@+#uy+145x-#sq55r(l&6h1^62me'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'django.contrib.admin',
35+
'django.contrib.auth',
36+
'django.contrib.contenttypes',
37+
'django.contrib.sessions',
38+
'django.contrib.messages',
39+
'django.contrib.staticfiles',
40+
'quiz',
41+
]
42+
43+
MIDDLEWARE = [
44+
45+
46+
'django.middleware.security.SecurityMiddleware',
47+
'django.contrib.sessions.middleware.SessionMiddleware',
48+
'django.middleware.common.CommonMiddleware',
49+
'django.middleware.csrf.CsrfViewMiddleware',
50+
'django.contrib.auth.middleware.AuthenticationMiddleware',
51+
'django.contrib.messages.middleware.MessageMiddleware',
52+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
53+
]
54+
55+
ROOT_URLCONF = 'myproject.urls'
56+
57+
TEMPLATES = [
58+
{
59+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
60+
'DIRS': [os.path.join(BASE_DIR, 'templates')],
61+
'APP_DIRS': True,
62+
'OPTIONS': {
63+
'context_processors': [
64+
'django.template.context_processors.debug',
65+
'django.template.context_processors.request',
66+
'django.contrib.auth.context_processors.auth',
67+
'django.contrib.messages.context_processors.messages',
68+
],
69+
},
70+
},
71+
]
72+
73+
WSGI_APPLICATION = 'myproject.wsgi.application'
74+
75+
76+
# Database
77+
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
78+
79+
DATABASES = {
80+
'default': {
81+
'ENGINE': 'django.db.backends.sqlite3',
82+
'NAME': BASE_DIR / 'db.sqlite3',
83+
}
84+
}
85+
86+
87+
# Password validation
88+
# https://docs.djangoproject.com/en/5.1/ref/settings/#auth-password-validators
89+
90+
AUTH_PASSWORD_VALIDATORS = [
91+
{
92+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
93+
},
94+
{
95+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
96+
},
97+
{
98+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
99+
},
100+
{
101+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
102+
},
103+
]
104+
105+
106+
# Internationalization
107+
# https://docs.djangoproject.com/en/5.1/topics/i18n/
108+
109+
LANGUAGE_CODE = 'en-us'
110+
111+
TIME_ZONE = 'UTC'
112+
113+
USE_I18N = True
114+
115+
USE_TZ = True
116+
117+
118+
# Static files (CSS, JavaScript, Images)
119+
# https://docs.djangoproject.com/en/5.1/howto/static-files/
120+
121+
STATIC_URL = 'static/'
122+
123+
# Default primary key field type
124+
# https://docs.djangoproject.com/en/5.1/ref/settings/#default-auto-field
125+
126+
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
URL configuration for myproject project.
3+
4+
The `urlpatterns` list routes URLs to views. For more information please see:
5+
https://docs.djangoproject.com/en/5.1/topics/http/urls/
6+
Examples:
7+
Function views
8+
1. Add an import: from my_app import views
9+
2. Add a URL to urlpatterns: path('', views.home, name='home')
10+
Class-based views
11+
1. Add an import: from other_app.views import Home
12+
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13+
Including another URLconf
14+
1. Import the include() function: from django.urls import include, path
15+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16+
"""
17+
from django.contrib import admin
18+
from django.urls import path
19+
from quiz.views import quiz_view
20+
21+
22+
23+
urlpatterns = [
24+
path('admin/', admin.site.urls),
25+
path('', quiz_view, name='quiz'), # Use a single path for the quiz
26+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for myproject project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/5.1/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
15+
16+
application = get_wsgi_application()

django Quiz Form/myproject/quiz/__init__.py

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class QuizConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'quiz'
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from django import forms
2+
3+
class NameForm(forms.Form):
4+
name = forms.CharField(label='What is your name?', max_length=100)
5+
6+
class QuizForm(forms.Form):
7+
QUESTIONS = {
8+
1: {
9+
'label': "Who is known as the father of Computer?",
10+
'choices': [('a', 'Alan Turing'), ('b', 'Charles Babbage'), ('c', 'John von Neumann'), ('d', 'Ada Lovelace')]
11+
},
12+
2: {
13+
'label': "Who is the author of 'Pride and Prejudice'?",
14+
'choices': [('a', 'Emily Brontë'), ('b', 'Charles Dickens'), ('c', 'Jane Austen'), ('d', 'Mark Twain')]
15+
},
16+
3: {
17+
'label': "What character have both Robert Downey Jr. and Benedict Cumberbatch played?",
18+
'choices': [('a', 'Iron Man'), ('b', 'Sherlock Holmes'), ('c', 'Dr. Strange'), ('d', 'James Bond')]
19+
},
20+
4: {
21+
'label': "Which planet in the Milky Way is the hottest?",
22+
'choices': [('a', 'Venus'), ('b', 'Mars'), ('c', 'Saturn'), ('d', 'Jupiter')]
23+
},
24+
5: {
25+
'label': "What city is known as The Eternal City?",
26+
'choices': [('a', 'Athens'), ('b', 'Rome'), ('c', 'Paris'), ('d', 'Cairo')]
27+
},
28+
6: {
29+
'label': "Who discovered that the earth revolves around the sun?",
30+
'choices': [('a', 'Galileo Galilei'), ('b', 'Isaac Newton'), ('c', 'Nicolaus Copernicus'), ('d', 'Johannes Kepler')]
31+
},
32+
7: {
33+
'label': "What sports car company manufactures the 911?",
34+
'choices': [('a', 'Ferrari'), ('b', 'Lamborgini'), ('c', 'Porsche'), ('d', 'Buggati')]
35+
},
36+
8: {
37+
'label': "Which planet has the most moons?",
38+
'choices': [('a', 'Venus'), ('b', 'Mars'), ('c', 'Saturn'), ('d', 'Jupiter')]
39+
},
40+
9: {
41+
'label': "How many bones do we have in an ear?",
42+
'choices': [('a', '2'), ('b', '3'), ('c', '4'), ('d', '5')]
43+
},
44+
10: {
45+
'label': "What software company is headquartered in Redmond, Washington?",
46+
'choices': [('a', 'Apple'), ('b', 'Google'), ('c', 'Microsoft'), ('d', 'Amazon')]
47+
}
48+
}
49+
50+
def __init__(self, *args, current_question=None, **kwargs):
51+
super().__init__(*args, **kwargs)
52+
if current_question and current_question in self.QUESTIONS:
53+
question_data = self.QUESTIONS[current_question]
54+
self.fields[f'q{current_question}'] = forms.ChoiceField(
55+
label=question_data['label'],
56+
choices=question_data['choices'],
57+
widget=forms.RadioSelect
58+
)

0 commit comments

Comments
 (0)