ankpan18 commited on
Commit
13c805c
·
0 Parent(s):

first commit (login & signup page)

Browse files
.gitignore ADDED
@@ -0,0 +1,137 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Django #
2
+ *.log
3
+ *.pot
4
+ *.pyc
5
+ __pycache__
6
+ db.sqlite3
7
+ media
8
+
9
+ # Backup files #
10
+ *.bak
11
+
12
+ # If you are using PyCharm #
13
+ # User-specific stuff
14
+ .idea/**/workspace.xml
15
+ .idea/**/tasks.xml
16
+ .idea/**/usage.statistics.xml
17
+ .idea/**/dictionaries
18
+ .idea/**/shelf
19
+
20
+ # AWS User-specific
21
+ .idea/**/aws.xml
22
+
23
+ # Generated files
24
+ .idea/**/contentModel.xml
25
+
26
+ # Sensitive or high-churn files
27
+ .idea/**/dataSources/
28
+ .idea/**/dataSources.ids
29
+ .idea/**/dataSources.local.xml
30
+ .idea/**/sqlDataSources.xml
31
+ .idea/**/dynamic.xml
32
+ .idea/**/uiDesigner.xml
33
+ .idea/**/dbnavigator.xml
34
+
35
+ # Gradle
36
+ .idea/**/gradle.xml
37
+ .idea/**/libraries
38
+
39
+ # File-based project format
40
+ *.iws
41
+
42
+ # IntelliJ
43
+ out/
44
+
45
+ # JIRA plugin
46
+ atlassian-ide-plugin.xml
47
+
48
+ # Python #
49
+ *.py[cod]
50
+ *$py.class
51
+
52
+ # Distribution / packaging
53
+ .Python build/
54
+ develop-eggs/
55
+ dist/
56
+ downloads/
57
+ eggs/
58
+ .eggs/
59
+ lib/
60
+ lib64/
61
+ parts/
62
+ sdist/
63
+ var/
64
+ wheels/
65
+ *.egg-info/
66
+ .installed.cfg
67
+ *.egg
68
+ *.manifest
69
+ *.spec
70
+
71
+ # Installer logs
72
+ pip-log.txt
73
+ pip-delete-this-directory.txt
74
+
75
+ # Unit test / coverage reports
76
+ htmlcov/
77
+ .tox/
78
+ .coverage
79
+ .coverage.*
80
+ .cache
81
+ .pytest_cache/
82
+ nosetests.xml
83
+ coverage.xml
84
+ *.cover
85
+ .hypothesis/
86
+
87
+ # Jupyter Notebook
88
+ .ipynb_checkpoints
89
+
90
+ # pyenv
91
+ .python-version
92
+
93
+ # celery
94
+ celerybeat-schedule.*
95
+
96
+ # SageMath parsed files
97
+ *.sage.py
98
+
99
+ # Environments
100
+ .env
101
+ .venv
102
+ env/
103
+ venv/
104
+ ENV/
105
+ env.bak/
106
+ venv.bak/
107
+
108
+ # mkdocs documentation
109
+ /site
110
+
111
+ # mypy
112
+ .mypy_cache/
113
+
114
+ # Sublime Text #
115
+ *.tmlanguage.cache
116
+ *.tmPreferences.cache
117
+ *.stTheme.cache
118
+ *.sublime-workspace
119
+ *.sublime-project
120
+
121
+ # sftp configuration file
122
+ sftp-config.json
123
+
124
+ # Package control specific files Package
125
+ Control.last-run
126
+ Control.ca-list
127
+ Control.ca-bundle
128
+ Control.system-ca-bundle
129
+ GitHub.sublime-settings
130
+
131
+ # Visual Studio Code #
132
+ .vscode/*
133
+ !.vscode/settings.json
134
+ !.vscode/tasks.json
135
+ !.vscode/launch.json
136
+ !.vscode/extensions.json
137
+ .history
manage.py ADDED
@@ -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', 'templator.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()
other/__init__.py ADDED
File without changes
other/admin.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.contrib import admin
2
+
3
+ # Register your models here.
other/apps.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class OtherConfig(AppConfig):
5
+ default_auto_field = 'django.db.models.BigAutoField'
6
+ name = 'other'
other/migrations/__init__.py ADDED
File without changes
other/models.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.db import models
2
+
3
+ # Create your models here.
other/tests.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.test import TestCase
2
+
3
+ # Create your tests here.
other/urls.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from django.urls import path
2
+ from . import views
3
+
4
+ urlpatterns = [
5
+ path("",views.index,name="index"),
6
+ ]
other/views.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from django.shortcuts import render
2
+ from django.http import HttpResponse
3
+
4
+ # Create your views here.
5
+ def index(request):
6
+ return HttpResponse("other response")
polls/__init__.py ADDED
File without changes
polls/admin.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.contrib import admin
2
+ from .models import Question,Choice
3
+
4
+
5
+ class ChoiceInline(admin.TabularInline):
6
+ # fields=['question_text','pub_date']
7
+ model=Choice
8
+ extra=2
9
+
10
+ class QuestionAdmin(admin.ModelAdmin):
11
+ # fields=['question_text','pub_date']
12
+
13
+ fieldsets=[("question",{"fields":['question_text']}),
14
+ ("Date information",{"fields":['pub_date']})]
15
+
16
+ inlines = [ChoiceInline]
17
+
18
+
19
+ # Register your models here.
20
+ admin.site.register(Question,QuestionAdmin)
21
+ admin.site.register(Choice)
polls/apps.py ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ from django.apps import AppConfig
2
+
3
+
4
+ class PollsConfig(AppConfig):
5
+ default_auto_field = 'django.db.models.BigAutoField'
6
+ name = 'polls'
polls/migrations/0001_initial.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Generated by Django 4.2.3 on 2023-07-18 00:56
2
+
3
+ from django.db import migrations, models
4
+ import django.db.models.deletion
5
+
6
+
7
+ class Migration(migrations.Migration):
8
+
9
+ initial = True
10
+
11
+ dependencies = [
12
+ ]
13
+
14
+ operations = [
15
+ migrations.CreateModel(
16
+ name='Question',
17
+ fields=[
18
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19
+ ('question_text', models.CharField(max_length=300)),
20
+ ('pub_date', models.DateTimeField(verbose_name='date published')),
21
+ ],
22
+ ),
23
+ migrations.CreateModel(
24
+ name='Choice',
25
+ fields=[
26
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
27
+ ('choice_text', models.CharField(max_length=200)),
28
+ ('votes', models.IntegerField(default=0)),
29
+ ('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.question')),
30
+ ],
31
+ ),
32
+ ]
polls/migrations/__init__.py ADDED
File without changes
polls/models.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.db import models
2
+ import datetime
3
+ from django.utils import timezone
4
+
5
+ # Create your models here.
6
+ class Question(models.Model):
7
+
8
+ question_text = models.CharField(max_length=300)
9
+ pub_date = models.DateTimeField("date published",default=datetime.datetime.now)
10
+
11
+ def __str__(self):
12
+ return self.question_text
13
+
14
+ @property
15
+ def total_votes(self):
16
+ return self.choice_set.aggregate(models.Sum('votes'))['votes__sum']
17
+ def was_recently_pub(self):
18
+ return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
19
+
20
+
21
+ class Choice(models.Model):
22
+
23
+ question = models.ForeignKey(Question, on_delete=models.CASCADE)
24
+ choice_text = models.CharField(max_length=200)
25
+ votes = models.IntegerField(default=0)
26
+
27
+ def __str__(self):
28
+ return self.question.question_text+"-"*5+self.choice_text
polls/static/polls/detail.css ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ .question{
3
+ background-color: rgb(133, 127, 255);
4
+ color: white;
5
+ padding: 4px;
6
+ margin:20px 4px;
7
+ /* width:140px; */
8
+
9
+ border-radius: 10px;
10
+ position:relative;
11
+ }
12
+ .question>.question_text{
13
+ font: caption;
14
+ margin: 0px;
15
+ padding: 0px;
16
+ margin-bottom: 14px;
17
+ }
18
+
19
+
20
+ .option{
21
+ background-color: white;
22
+ margin-bottom: 9px;
23
+ border-radius: 10px;
24
+ height:30px;
25
+ color:black;
26
+ }
27
+ .option.active{
28
+ background-color: rgb(255 0 111) ;
29
+ color:rgb(255, 255, 255);
30
+ }
31
+
32
+ .option:hover{
33
+ cursor: pointer;
34
+ }
35
+
36
+ #vote_btn{
37
+ border:none;
38
+ outline: none;
39
+ padding: 5px 20px;
40
+ border-radius: 10px;
41
+ }
42
+
43
+ #vote_btn:hover{
44
+ cursor: pointer;
45
+ }
polls/static/polls/detail.js ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function getCookie(name) {
2
+ let cookieValue = null;
3
+
4
+ if (document.cookie && document.cookie !== '') {
5
+ const cookies = document.cookie.split(';');
6
+ for (let i = 0; i < cookies.length; i++) {
7
+ const cookie = cookies[i].trim();
8
+
9
+ // Does this cookie string begin with the name we want?
10
+ if (cookie.substring(0, name.length + 1) === (name + '=')) {
11
+ cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
12
+
13
+ break;
14
+ }
15
+ }
16
+ }
17
+
18
+ return cookieValue;
19
+ }
20
+ const csrftoken = getCookie('csrftoken');
21
+
22
+ console.log("I'm here");
23
+
24
+ function choose_option(option){
25
+ // clear active from others
26
+ document.querySelectorAll(".option.active").forEach(el=>{
27
+ el.classList.remove("active");
28
+ })
29
+ // add active to current option
30
+ option.classList.add("active");
31
+ }
32
+
33
+
34
+ function vote(){
35
+ el=document.querySelector(".option.active");
36
+ if (el==null) return;
37
+ console.log(el.dataset.id);
38
+ fetch(vote_url,{
39
+ method:"POST",
40
+
41
+ headers:{
42
+ 'X-CSRFToken': csrftoken
43
+ },
44
+ body:JSON.stringify({"choice":el.dataset.id})
45
+ }).then(res=>res.json()).then(res=>{
46
+ console.log(res);
47
+ if (!res.hasOwnProperty("error_message")){
48
+ window.location.href = res["redirect"];
49
+ }
50
+ })
51
+ }
polls/static/polls/google_logo.png ADDED
polls/static/polls/index.css ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .questions{
2
+ display: flex;
3
+ flex-wrap: wrap;
4
+ }
5
+ .question{
6
+ background-color: rgb(133, 127, 255);
7
+ color: white;
8
+ padding: 4px;
9
+ margin:20px 4px;
10
+ width:140px;
11
+ height: 150px;
12
+ border-radius: 10px;
13
+ position:relative;
14
+ }
15
+ .question>.question_text{
16
+ font: caption;
17
+ margin: 0px;
18
+ padding: 0px;
19
+ margin-bottom: 14px;
20
+ }
21
+ .question:hover{
22
+ cursor: pointer;
23
+ }
24
+
25
+ .total_count{
26
+ font:-webkit-control;
27
+ color: black;
28
+ position:absolute;
29
+ bottom: 5px;
30
+ right: 5px;
31
+ padding: 0;
32
+ margin: 0;
33
+ }
polls/static/polls/login.css ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ :root{
2
+ --button-height:40px;
3
+ --button-radius:6px;
4
+ }
5
+
6
+ *{
7
+ font-family: 'Poppins';
8
+ }
9
+ #title{
10
+ margin:0;
11
+ padding:0;
12
+ margin-top: 50px;
13
+ }
14
+ body{
15
+ background-color: #e7e8eb;
16
+ }
17
+ .main-container{
18
+ display: flex;
19
+ flex-direction: column;
20
+ align-items: center;
21
+ }
22
+
23
+ .form-container{
24
+
25
+ width: 350px;
26
+
27
+ margin-top:70px;
28
+ background-color: #FFFFFF;
29
+ border-radius: var(--button-radius);
30
+
31
+
32
+ display: flex;
33
+ flex-direction: column;
34
+ align-items: center;
35
+
36
+ padding: 30px;
37
+ box-sizing: border-box;
38
+
39
+ margin-bottom:20px;
40
+ }
41
+
42
+
43
+
44
+ #google_btn{
45
+ background-color: D9D9D9;
46
+ width:100%;
47
+ height: var(--button-height);
48
+ border-radius: var(--button-radius);
49
+ background-color: white;
50
+ border: #dbdce1 solid 2px;
51
+ display: flex;
52
+ flex-direction: row;
53
+ align-items: center;
54
+ justify-content: center;
55
+ transition: background-color 200ms ease;
56
+ }
57
+
58
+ #google_btn:hover{
59
+ cursor: pointer;
60
+ background-color: #dbdce1;
61
+
62
+ }
63
+
64
+ #google_btn>img{
65
+ height: 20px;
66
+ margin-right:10px;
67
+ }
68
+
69
+ #text{
70
+ color: #87888b;
71
+ margin-top: 20px;
72
+ }
73
+
74
+ form{
75
+ width: 100%;
76
+ }
77
+
78
+ .field{
79
+ width: 100%;
80
+ margin-top: 20px;
81
+ }
82
+
83
+ .field>label{
84
+ font-weight: bold;
85
+ }
86
+ .field>.box{
87
+
88
+ background-color: D9D9D9;
89
+ width:100%;
90
+ height: var(--button-height);
91
+ border-radius: var(--button-radius);
92
+ background-color: white;
93
+ border: #00000040 solid 2px;
94
+ }
95
+
96
+
97
+ #submit_btn{
98
+
99
+ margin:0;
100
+ padding:0;
101
+ margin-top:40px;
102
+
103
+ background-color: blue;
104
+ color:white;
105
+
106
+ width:100%;
107
+ height: var(--button-height);
108
+ border-radius: var(--button-radius);
109
+
110
+ border: none;
111
+ outline: none;
112
+ transition: background-color 200ms ease;
113
+
114
+ }
115
+ #submit_btn:hover{
116
+ cursor: pointer;
117
+
118
+ background-color: rgb(0, 0, 211);
119
+ }
120
+
121
+
122
+ .link{
123
+ color:blue;
124
+ /* text-decoration:wavy underline; */
125
+ text-decoration:none;
126
+ }
polls/static/polls/signup.css ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ :root{
2
+ --button-height:40px;
3
+ --button-radius:6px;
4
+ }
5
+
6
+ *{
7
+ font-family: 'Poppins';
8
+ }
9
+ #title{
10
+ margin:0;
11
+ padding:0;
12
+ margin-top: 50px;
13
+ }
14
+ body{
15
+ background-color: #e7e8eb;
16
+ }
17
+ .main-container{
18
+ display: flex;
19
+ flex-direction: column;
20
+ align-items: center;
21
+ }
22
+
23
+ .form-container{
24
+
25
+ width: 350px;
26
+
27
+ margin-top:70px;
28
+ background-color: #FFFFFF;
29
+ border-radius: var(--button-radius);
30
+
31
+
32
+ display: flex;
33
+ flex-direction: column;
34
+ align-items: center;
35
+
36
+ padding: 30px;
37
+ box-sizing: border-box;
38
+
39
+ margin-bottom:20px;
40
+ }
41
+
42
+
43
+
44
+ #google_btn{
45
+ background-color: D9D9D9;
46
+ width:100%;
47
+ height: var(--button-height);
48
+ border-radius: var(--button-radius);
49
+ background-color: white;
50
+ border: #dbdce1 solid 2px;
51
+ display: flex;
52
+ flex-direction: row;
53
+ align-items: center;
54
+ justify-content: center;
55
+ transition: background-color 200ms ease;
56
+ }
57
+
58
+ #google_btn:hover{
59
+ cursor: pointer;
60
+ background-color: #dbdce1;
61
+
62
+ }
63
+
64
+ #google_btn>img{
65
+ height: 20px;
66
+ margin-right:10px;
67
+ }
68
+
69
+ #text{
70
+ color: #87888b;
71
+ margin-top: 20px;
72
+ }
73
+
74
+ form{
75
+ width: 100%;
76
+ }
77
+
78
+ .field{
79
+ width: 100%;
80
+ margin-top: 20px;
81
+ }
82
+
83
+ .field>label{
84
+ font-weight: bold;
85
+ }
86
+ .field>.box{
87
+
88
+ background-color: D9D9D9;
89
+ width:100%;
90
+ height: var(--button-height);
91
+ border-radius: var(--button-radius);
92
+ background-color: white;
93
+ border: #00000040 solid 2px;
94
+ }
95
+
96
+
97
+ #submit_btn{
98
+
99
+ margin:0;
100
+ padding:0;
101
+ margin-top:40px;
102
+
103
+ background-color: blue;
104
+ color:white;
105
+
106
+ width:100%;
107
+ height: var(--button-height);
108
+ border-radius: var(--button-radius);
109
+
110
+ border: none;
111
+ outline: none;
112
+ transition: background-color 200ms ease;
113
+
114
+ }
115
+ #submit_btn:hover{
116
+ cursor: pointer;
117
+
118
+ background-color: rgb(0, 0, 211);
119
+ }
120
+
121
+
122
+ .link{
123
+ color:blue;
124
+ /* text-decoration:wavy underline; */
125
+ text-decoration:none;
126
+ }
polls/templates/polls/detail.html ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ <html>
3
+ <head>
4
+ {% load static %}
5
+ <link type="text/css" rel="stylesheet" href="{% static 'polls/detail.css' %}">
6
+ </head>
7
+ <body>
8
+
9
+ <div class="question">
10
+ <p class="question_text">{{ question.question_text }}</p>
11
+ <div class="options">
12
+ {% for choice in question.choice_set.all %}
13
+ <div class="option" onclick="choose_option(this);" data-id="{{ choice.id }}">{{ choice.choice_text }}</div>
14
+ {% endfor %}
15
+ </div>
16
+ <input id="vote_btn" onclick="vote();" type="button" value="Vote">
17
+ </div>
18
+
19
+ <script>
20
+ var vote_url="{% url 'polls:vote' question.id %}";
21
+ </script>
22
+ <script src="{% static 'polls/detail.js' %}"></script>
23
+ </body>
24
+ </html>
25
+
26
+ <!-- <form method="POST" action="{% url 'polls:vote' question.id %}">
27
+ {% csrf_token %}
28
+ <fieldset>
29
+ <legend>
30
+ <h1>{{ question.question_text }}</h1>
31
+ {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}
32
+ {% for choice in question.choice_set.all %}
33
+ <input type="radio" name="choice" value="{{ choice.id }}" >
34
+ <label>{{ choice.choice_text }}</label><br>
35
+ {% endfor %}
36
+ </legend>
37
+ </fieldset>
38
+ <input type="submit" value="Vote">
39
+ </form>
40
+ -->
41
+
42
+ <!--
43
+ <div class="question">
44
+ <p>Question</p>
45
+ <div class="options">
46
+ <div class="option">option A</div>
47
+ <div class="option">option B</div>
48
+ <div class="option">option C</div>
49
+ </div>
50
+ </div> -->
polls/templates/polls/index.html ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html>
2
+ <head>
3
+ {% load static %}
4
+ <link type="text/css" rel="stylesheet" href="{% static 'polls/index.css' %}">
5
+ </head>
6
+ <body>
7
+ <h1>Polling App</h1>
8
+
9
+ {% if latest_questions_list %}
10
+
11
+ <div class="questions" >
12
+ {% for question in latest_questions_list %}
13
+
14
+ <div class="question" onclick="window.location.href = `{% url 'polls:detail' question.id %}`;">
15
+ <p class="question_text">{{ question }}</p>
16
+ <p class="total_count">Votes:{{ question.total_votes }}</p>
17
+ </div>
18
+ {% endfor %}
19
+ </div>
20
+
21
+
22
+ {% else %}
23
+ <p>No questions yet</p>
24
+ {% endif %}
25
+
26
+ </body>
27
+ </html>
polls/templates/polls/login.html ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html>
2
+ <head>
3
+ {% load static %}
4
+ <link rel="stylesheet" type="text/css" href="{% static 'polls/login.css' %}">
5
+ <link href='https://fonts.googleapis.com/css?family=Poppins' rel='stylesheet'>
6
+ <title>Login page</title>
7
+ </head>
8
+ <body>
9
+ <div class="main-container">
10
+ <h1 id="title">Poll App</h1>
11
+ <span>use <strong>Poll app</strong> for making polling convenient</span>
12
+
13
+
14
+ <div class="form-container">
15
+ <div class="box" id="google_btn">
16
+ <img src="{% static 'polls/google_logo.png' %}" >
17
+ <span>Log in with Google</span>
18
+ </div>
19
+
20
+ <span id="text">or using email</span>
21
+
22
+ <form onsubmit="validate(event)">
23
+
24
+ <div class="field">
25
+ <label>Your email Address</label>
26
+ <input name="email" type="text" class="box" required>
27
+ </div>
28
+ <div class="field">
29
+ <label>Password</label>
30
+ <input name="password" id="password" type="password" class="box" required>
31
+ </div>
32
+
33
+ <input type="submit" value="Log in" id="submit_btn">
34
+ </form>
35
+ <a class="link" href="#">Forget Password?</a>
36
+
37
+
38
+ </div>
39
+
40
+ <span>New to Poll App?
41
+ <a class="link" href="{% url 'polls:signup' %}">Sign up now</a>
42
+ </span>
43
+
44
+ </div>
45
+ <script>
46
+
47
+ confirm_password.addEventListener("keyup",()=>{
48
+ confirm_password.style.outline="none";
49
+ if(password.value!==confirm_password.value){
50
+ confirm_password.style.border="red solid 3px";
51
+ }
52
+ else{
53
+ confirm_password.style.border="#75ff00 solid 3px";
54
+ }
55
+ });
56
+ function validate(ev){
57
+ if(password.value!==confirm_password.value){
58
+ ev.preventDefault();
59
+ }
60
+ }
61
+ </script>
62
+ </body>
63
+ </html>
polls/templates/polls/result.html ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <h1>{{ question.question_text }}</h1>
2
+ <ul>
3
+ {% for choice in question.choice_set.all %}
4
+ <li>
5
+ {{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}
6
+ </li>
7
+ {% endfor %}
8
+ </ul>
9
+
10
+ <a href="{% url 'polls:detail' question.id %}">Vote again?</a>
polls/templates/polls/signup.html ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <html>
2
+ <head>
3
+ {% load static %}
4
+ <link rel="stylesheet" type="text/css" href="{% static 'polls/signup.css' %}">
5
+ <link href='https://fonts.googleapis.com/css?family=Poppins' rel='stylesheet'>
6
+ <title>Signup page</title>
7
+ </head>
8
+ <body>
9
+ <div class="main-container">
10
+ <h1 id="title">Poll App</h1>
11
+ <span>use <strong>Poll app</strong> for making polling convenient</span>
12
+
13
+
14
+ <div class="form-container">
15
+ <div class="box" id="google_btn">
16
+ <img src="{% static 'polls/google_logo.png' %}" >
17
+ <span>Sign up with Google</span>
18
+ </div>
19
+
20
+ <span id="text">or using email</span>
21
+
22
+ <form onsubmit="validate(event)">
23
+ <div class="field">
24
+ <label>Your Name</label>
25
+ <input name="name" type="text" class="box" required>
26
+ </div>
27
+ <div class="field">
28
+ <label>Your email Address</label>
29
+ <input name="email" type="text" class="box" required>
30
+ </div>
31
+ <div class="field">
32
+ <label>Password</label>
33
+ <input name="password" id="password" type="password" class="box" required>
34
+ </div>
35
+ <div class="field">
36
+ <label>Confirm Password</label>
37
+ <input type="password" id="confirm_password" class="box" required>
38
+ </div>
39
+
40
+ <input type="submit" value="Sign Up" id="submit_btn">
41
+ </form>
42
+
43
+
44
+
45
+ </div>
46
+
47
+ <span>Already have an account?
48
+ <a class="link" href="{% url 'polls:login' %}">Log in</a>
49
+ </span>
50
+
51
+ </div>
52
+ <script>
53
+
54
+ confirm_password.addEventListener("keyup",()=>{
55
+ confirm_password.style.outline="none";
56
+ if(password.value!==confirm_password.value){
57
+ confirm_password.style.border="red solid 3px";
58
+ }
59
+ else{
60
+ confirm_password.style.border="#75ff00 solid 3px";
61
+ }
62
+ });
63
+ function validate(ev){
64
+ if(password.value!==confirm_password.value){
65
+ ev.preventDefault();
66
+ }
67
+ }
68
+ </script>
69
+ </body>
70
+ </html>
polls/tests.py ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ from django.test import TestCase
2
+
3
+ # Create your tests here.
polls/urls.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.urls import path
2
+ from . import views
3
+
4
+
5
+ app_name="polls" # for namespace
6
+ urlpatterns = [
7
+ path("",views.index,name="index"),
8
+ path("signup/",views.signup,name="signup"),
9
+ path("login/",views.login,name="login"),
10
+ path("details/<int:question_id>/",views.detail,name="detail"),
11
+ path("vote/<int:question_id>/",views.vote,name="vote"),
12
+ path("result/<int:question_id>/",views.result,name="result"),
13
+ ]
polls/views.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from django.shortcuts import render,get_object_or_404
2
+ from django.http import HttpResponse,Http404,HttpResponseRedirect,JsonResponse
3
+ from django.urls import reverse
4
+ import json
5
+ from .models import Question,Choice
6
+
7
+ # Create your views here.
8
+ def index(request):
9
+ latest_questions_list = Question.objects.order_by("-pub_date")[:5]
10
+ context={"latest_questions_list":latest_questions_list}
11
+ return render(request,"polls/index.html",context)
12
+
13
+ def detail(request,question_id):
14
+ try:
15
+ question=Question.objects.get(pk=question_id)
16
+ except Question.DoesNotExist:
17
+ raise Http404("Question Does Not Exists")
18
+
19
+ return render(request,"polls/detail.html",{"question":question})
20
+
21
+ def vote(request,question_id):
22
+
23
+ question=get_object_or_404(Question,pk=question_id)
24
+
25
+
26
+ try:
27
+ json_data=json.loads(request.body)
28
+ print(json_data)
29
+ selected_choice = question.choice_set.get(pk=json_data["choice"])
30
+ except(KeyError,Choice.DoesNotExist):
31
+ # redirect back to details page with error message
32
+ return JsonResponse({
33
+
34
+ "error_message":"You didn't select a Choice."
35
+ })
36
+
37
+ else:
38
+ selected_choice.votes += 1
39
+ selected_choice.save()
40
+ # return HttpResponseRedirect(reverse("polls:result",args=(question_id,)))
41
+ return JsonResponse({
42
+ "redirect":reverse("polls:result",args=(question_id,)),
43
+
44
+ })
45
+
46
+
47
+ def result(request,question_id):
48
+ question=get_object_or_404(Question,pk=question_id)
49
+ return render(request,"polls/result.html",{"question":question})
50
+
51
+ def signup(request):
52
+ return render(request,"polls/signup.html",{})
53
+
54
+ def login(request):
55
+ return render(request,"polls/login.html",{})
templator/__init__.py ADDED
File without changes
templator/asgi.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ ASGI config for templator 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/4.2/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', 'templator.settings')
15
+
16
+ application = get_asgi_application()
templator/settings.py ADDED
@@ -0,0 +1,125 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Django settings for templator project.
3
+
4
+ Generated by 'django-admin startproject' using Django 4.2.3.
5
+
6
+ For more information on this file, see
7
+ https://docs.djangoproject.com/en/4.2/topics/settings/
8
+
9
+ For the full list of settings and their values, see
10
+ https://docs.djangoproject.com/en/4.2/ref/settings/
11
+ """
12
+
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/4.2/howto/deployment/checklist/
21
+
22
+ # SECURITY WARNING: keep the secret key used in production secret!
23
+ SECRET_KEY = 'django-insecure-*=rt2ef(vgm1eo5vf7-da_zyvpi+6!70y@ort!j05z5_3lwta9'
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
+ 'polls'
41
+ ]
42
+
43
+ MIDDLEWARE = [
44
+ 'django.middleware.security.SecurityMiddleware',
45
+ 'django.contrib.sessions.middleware.SessionMiddleware',
46
+ 'django.middleware.common.CommonMiddleware',
47
+ 'django.middleware.csrf.CsrfViewMiddleware',
48
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
49
+ 'django.contrib.messages.middleware.MessageMiddleware',
50
+ 'django.middleware.clickjacking.XFrameOptionsMiddleware',
51
+ ]
52
+
53
+ ROOT_URLCONF = 'templator.urls'
54
+
55
+ TEMPLATES = [
56
+ {
57
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
58
+ 'DIRS': [],
59
+ 'APP_DIRS': True,
60
+ 'OPTIONS': {
61
+ 'context_processors': [
62
+ 'django.template.context_processors.debug',
63
+ 'django.template.context_processors.request',
64
+ 'django.contrib.auth.context_processors.auth',
65
+ 'django.contrib.messages.context_processors.messages',
66
+ ],
67
+ },
68
+ },
69
+ ]
70
+
71
+ WSGI_APPLICATION = 'templator.wsgi.application'
72
+
73
+
74
+ # Database
75
+ # https://docs.djangoproject.com/en/4.2/ref/settings/#databases
76
+
77
+ DATABASES = {
78
+ 'default': {
79
+ 'ENGINE': 'django.db.backends.sqlite3',
80
+ 'NAME': BASE_DIR / 'db.sqlite3',
81
+ }
82
+ }
83
+
84
+
85
+ # Password validation
86
+ # https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
87
+
88
+ AUTH_PASSWORD_VALIDATORS = [
89
+ {
90
+ 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
91
+ },
92
+ {
93
+ 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
94
+ },
95
+ {
96
+ 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
97
+ },
98
+ {
99
+ 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
100
+ },
101
+ ]
102
+
103
+
104
+ # Internationalization
105
+ # https://docs.djangoproject.com/en/4.2/topics/i18n/
106
+
107
+ LANGUAGE_CODE = 'en-us'
108
+
109
+ # TIME_ZONE = 'UTC'
110
+ TIME_ZONE = 'Asia/Kolkata'
111
+
112
+ USE_I18N = True
113
+
114
+ USE_TZ = True
115
+
116
+
117
+ # Static files (CSS, JavaScript, Images)
118
+ # https://docs.djangoproject.com/en/4.2/howto/static-files/
119
+
120
+ STATIC_URL = 'static/'
121
+
122
+ # Default primary key field type
123
+ # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
124
+
125
+ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
templator/urls.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ URL configuration for templator project.
3
+
4
+ The `urlpatterns` list routes URLs to views. For more information please see:
5
+ https://docs.djangoproject.com/en/4.2/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, include
19
+
20
+ urlpatterns = [
21
+ path('admin/', admin.site.urls),
22
+ path('polls/',include('polls.urls')),
23
+ path('other/',include('other.urls')),
24
+ ]
templator/wsgi.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ WSGI config for templator 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/4.2/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', 'templator.settings')
15
+
16
+ application = get_wsgi_application()