Anuj-Panthri commited on
Commit
833b984
·
1 Parent(s): 1e35cf5

added colors themes for questions

Browse files
accounts/admin.py CHANGED
@@ -1,4 +1,3 @@
1
- from typing import Any, Dict, List, Optional, Tuple
2
  from django.contrib import admin
3
  from django.http.request import HttpRequest
4
  from .models import User
 
 
1
  from django.contrib import admin
2
  from django.http.request import HttpRequest
3
  from .models import User
accounts/migrations/0001_initial.py CHANGED
@@ -1,6 +1,7 @@
1
- # Generated by Django 4.2.3 on 2023-07-25 02:23
2
 
3
  from django.db import migrations, models
 
4
 
5
 
6
  class Migration(migrations.Migration):
@@ -19,9 +20,10 @@ class Migration(migrations.Migration):
19
  ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
20
  ('email', models.EmailField(max_length=255, primary_key=True, serialize=False, unique=True, verbose_name='Email Address')),
21
  ('username', models.CharField(max_length=150, verbose_name='Name')),
 
22
  ('is_staff', models.BooleanField(default=False)),
23
  ('is_superuser', models.BooleanField(default=False)),
24
- ('is_active', models.BooleanField(default=False)),
25
  ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
26
  ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
27
  ],
 
1
+ # Generated by Django 4.2.4 on 2023-08-07 18:11
2
 
3
  from django.db import migrations, models
4
+ import django.utils.timezone
5
 
6
 
7
  class Migration(migrations.Migration):
 
20
  ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
21
  ('email', models.EmailField(max_length=255, primary_key=True, serialize=False, unique=True, verbose_name='Email Address')),
22
  ('username', models.CharField(max_length=150, verbose_name='Name')),
23
+ ('joining_date', models.DateTimeField(default=django.utils.timezone.now, verbose_name='Joining Date')),
24
  ('is_staff', models.BooleanField(default=False)),
25
  ('is_superuser', models.BooleanField(default=False)),
26
+ ('is_active', models.BooleanField(default=True)),
27
  ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')),
28
  ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')),
29
  ],
accounts/migrations/0002_alter_user_is_active.py DELETED
@@ -1,18 +0,0 @@
1
- # Generated by Django 4.2.3 on 2023-07-25 16:10
2
-
3
- from django.db import migrations, models
4
-
5
-
6
- class Migration(migrations.Migration):
7
-
8
- dependencies = [
9
- ('accounts', '0001_initial'),
10
- ]
11
-
12
- operations = [
13
- migrations.AlterField(
14
- model_name='user',
15
- name='is_active',
16
- field=models.BooleanField(default=True),
17
- ),
18
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
accounts/migrations/0003_user_joining_date.py DELETED
@@ -1,19 +0,0 @@
1
- # Generated by Django 4.2.3 on 2023-07-27 01:18
2
-
3
- from django.db import migrations, models
4
- import django.utils.timezone
5
-
6
-
7
- class Migration(migrations.Migration):
8
-
9
- dependencies = [
10
- ('accounts', '0002_alter_user_is_active'),
11
- ]
12
-
13
- operations = [
14
- migrations.AddField(
15
- model_name='user',
16
- name='joining_date',
17
- field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='Joining Date'),
18
- ),
19
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
data.json ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "model": "accounts.user",
4
+ "pk": "panthrianuj@gmail.com",
5
+ "fields": {
6
+ "password": "pbkdf2_sha256$600000$Yw9EwWF4CHNA3mjGejYHi1$6EDbuZDZdZnzuBJfn7reD15pmn008ybao3c3osr7x6g=",
7
+ "last_login": "2023-08-06T15:43:13.536Z",
8
+ "username": "Anuj",
9
+ "joining_date": "2023-08-02T17:10:02.894Z",
10
+ "is_staff": true,
11
+ "is_superuser": true,
12
+ "is_active": true,
13
+ "groups": [],
14
+ "user_permissions": []
15
+ }
16
+ },
17
+ {
18
+ "model": "polls.question",
19
+ "pk": 2,
20
+ "fields": {
21
+ "author": "panthrianuj@gmail.com",
22
+ "question_text": "Best Laptop",
23
+ "pub_date": "2023-08-06T14:45:39.901Z",
24
+ "theme_color": null
25
+ }
26
+ },
27
+ {
28
+ "model": "polls.question",
29
+ "pk": 3,
30
+ "fields": {
31
+ "author": "panthrianuj@gmail.com",
32
+ "question_text": "new poll",
33
+ "pub_date": "2023-08-07T17:33:47.846Z",
34
+ "theme_color": null
35
+ }
36
+ },
37
+ {
38
+ "model": "polls.choice",
39
+ "pk": 3,
40
+ "fields": {
41
+ "question": 2,
42
+ "choice_text": "Lenovo"
43
+ }
44
+ },
45
+ {
46
+ "model": "polls.choice",
47
+ "pk": 4,
48
+ "fields": {
49
+ "question": 2,
50
+ "choice_text": "HP"
51
+ }
52
+ },
53
+ {
54
+ "model": "polls.choice",
55
+ "pk": 5,
56
+ "fields": {
57
+ "question": 3,
58
+ "choice_text": "A"
59
+ }
60
+ },
61
+ {
62
+ "model": "polls.choice",
63
+ "pk": 6,
64
+ "fields": {
65
+ "question": 3,
66
+ "choice_text": "B"
67
+ }
68
+ }
69
+ ]
db.sqlite3 CHANGED
Binary files a/db.sqlite3 and b/db.sqlite3 differ
 
polls/admin.py CHANGED
@@ -1,6 +1,6 @@
1
  from django.contrib import admin
2
- from .models import Question,Choice,Vote
3
-
4
 
5
  class ChoiceInline(admin.TabularInline):
6
  fields = ['choice_text']
@@ -18,7 +18,7 @@ class QuestionAdmin(admin.ModelAdmin):
18
 
19
 
20
  fieldsets = [("question",{"fields":['question_text']}),
21
- ("Meta data",{"fields":['pub_date','author']})]
22
 
23
  model = Question
24
 
@@ -26,7 +26,19 @@ class QuestionAdmin(admin.ModelAdmin):
26
  return {"author": request.user}
27
 
28
 
 
 
 
 
 
 
 
 
 
 
 
29
  # Register your models here.
30
  admin.site.register(Question,QuestionAdmin)
31
  admin.site.register(Choice)
32
- admin.site.register(Vote)
 
 
1
  from django.contrib import admin
2
+ from .models import Question,Choice,Vote,ThemeColor
3
+ from .forms import ThemeColorForm
4
 
5
  class ChoiceInline(admin.TabularInline):
6
  fields = ['choice_text']
 
18
 
19
 
20
  fieldsets = [("question",{"fields":['question_text']}),
21
+ ("Meta data",{"fields":['pub_date','author','theme_color']})]
22
 
23
  model = Question
24
 
 
26
  return {"author": request.user}
27
 
28
 
29
+ class ThemeColorAdmin(admin.ModelAdmin):
30
+ # model = ThemeColor
31
+ form = ThemeColorForm
32
+ list_display=("title","primary_color","secondary_color")
33
+
34
+ fieldsets=[("Title",{"fields":["title"]}),
35
+ ("Colors",{"fields":["primary_color","secondary_color"]}),
36
+ ]
37
+
38
+
39
+
40
  # Register your models here.
41
  admin.site.register(Question,QuestionAdmin)
42
  admin.site.register(Choice)
43
+ admin.site.register(Vote)
44
+ admin.site.register(ThemeColor,ThemeColorAdmin)
polls/forms.py CHANGED
@@ -1,7 +1,7 @@
1
  from django import forms
2
  from django.contrib.auth import get_user_model
3
  from accounts.forms import UserAdminCreationForm,UserAdminUpdateForm
4
- from .models import Question
5
 
6
  User=get_user_model()
7
 
@@ -20,4 +20,11 @@ class QuestionForm(forms.ModelForm):
20
  model=Question
21
  fields=('question_text','pub_date','author')
22
 
23
-
 
 
 
 
 
 
 
 
1
  from django import forms
2
  from django.contrib.auth import get_user_model
3
  from accounts.forms import UserAdminCreationForm,UserAdminUpdateForm
4
+ from .models import Question,ThemeColor
5
 
6
  User=get_user_model()
7
 
 
20
  model=Question
21
  fields=('question_text','pub_date','author')
22
 
23
+
24
+ class ThemeColorForm(forms.ModelForm):
25
+ class Meta:
26
+ model = ThemeColor
27
+ fields=('primary_color','secondary_color')
28
+
29
+ primary_color = forms.CharField(widget=forms.widgets.TextInput(attrs={"type":"color","value":"#ffffff"}))
30
+ secondary_color = forms.CharField(widget=forms.widgets.TextInput(attrs={"type":"color"}))
polls/migrations/0001_initial.py CHANGED
@@ -1,6 +1,7 @@
1
- # Generated by Django 4.2.3 on 2023-07-24 17:19
2
 
3
  import datetime
 
4
  from django.db import migrations, models
5
  import django.db.models.deletion
6
 
@@ -10,24 +11,46 @@ class Migration(migrations.Migration):
10
  initial = True
11
 
12
  dependencies = [
 
13
  ]
14
 
15
  operations = [
16
  migrations.CreateModel(
17
- name='Question',
18
  fields=[
19
  ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
20
- ('question_text', models.CharField(max_length=300)),
21
- ('pub_date', models.DateTimeField(default=datetime.datetime.now, verbose_name='date published')),
22
  ],
23
  ),
24
  migrations.CreateModel(
25
- name='Choice',
 
 
 
 
 
 
 
 
26
  fields=[
27
  ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
28
- ('choice_text', models.CharField(max_length=200)),
29
- ('votes', models.IntegerField(default=0)),
30
- ('question', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.question')),
 
 
 
 
 
 
 
 
 
31
  ],
32
  ),
 
 
 
 
 
33
  ]
 
1
+ # Generated by Django 4.2.4 on 2023-08-07 18:11
2
 
3
  import datetime
4
+ from django.conf import settings
5
  from django.db import migrations, models
6
  import django.db.models.deletion
7
 
 
11
  initial = True
12
 
13
  dependencies = [
14
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
15
  ]
16
 
17
  operations = [
18
  migrations.CreateModel(
19
+ name='Choice',
20
  fields=[
21
  ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
22
+ ('choice_text', models.CharField(max_length=200)),
 
23
  ],
24
  ),
25
  migrations.CreateModel(
26
+ name='ThemeColor',
27
+ fields=[
28
+ ('title', models.CharField(max_length=200, primary_key=True, serialize=False)),
29
+ ('primary_color', models.CharField(max_length=7)),
30
+ ('secondary_color', models.CharField(max_length=7)),
31
+ ],
32
+ ),
33
+ migrations.CreateModel(
34
+ name='Vote',
35
  fields=[
36
  ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
37
+ ('choice', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='vote_set', to='polls.choice')),
38
+ ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
39
+ ],
40
+ ),
41
+ migrations.CreateModel(
42
+ name='Question',
43
+ fields=[
44
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
45
+ ('question_text', models.CharField(max_length=300)),
46
+ ('pub_date', models.DateTimeField(default=datetime.datetime.now, verbose_name='date published')),
47
+ ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
48
+ ('theme_color', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='polls.themecolor')),
49
  ],
50
  ),
51
+ migrations.AddField(
52
+ model_name='choice',
53
+ name='question',
54
+ field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='choice_set', to='polls.question'),
55
+ ),
56
  ]
polls/migrations/0002_question_author.py DELETED
@@ -1,22 +0,0 @@
1
- # Generated by Django 4.2.3 on 2023-07-27 01:27
2
-
3
- from django.conf import settings
4
- from django.db import migrations, models
5
- import django.db.models.deletion
6
-
7
-
8
- class Migration(migrations.Migration):
9
-
10
- dependencies = [
11
- migrations.swappable_dependency(settings.AUTH_USER_MODEL),
12
- ('polls', '0001_initial'),
13
- ]
14
-
15
- operations = [
16
- migrations.AddField(
17
- model_name='question',
18
- name='author',
19
- field=models.ForeignKey(default='panthrianuj@gmail.com', on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
20
- preserve_default=False,
21
- ),
22
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
polls/migrations/0003_remove_choice_votes_votes.py DELETED
@@ -1,28 +0,0 @@
1
- # Generated by Django 4.2.3 on 2023-07-28 06:29
2
-
3
- from django.conf import settings
4
- from django.db import migrations, models
5
- import django.db.models.deletion
6
-
7
-
8
- class Migration(migrations.Migration):
9
-
10
- dependencies = [
11
- migrations.swappable_dependency(settings.AUTH_USER_MODEL),
12
- ('polls', '0002_question_author'),
13
- ]
14
-
15
- operations = [
16
- migrations.RemoveField(
17
- model_name='choice',
18
- name='votes',
19
- ),
20
- migrations.CreateModel(
21
- name='Votes',
22
- fields=[
23
- ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
24
- ('choice', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='polls.choice')),
25
- ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
26
- ],
27
- ),
28
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
polls/migrations/0004_rename_votes_vote.py DELETED
@@ -1,19 +0,0 @@
1
- # Generated by Django 4.2.3 on 2023-07-28 06:32
2
-
3
- from django.conf import settings
4
- from django.db import migrations
5
-
6
-
7
- class Migration(migrations.Migration):
8
-
9
- dependencies = [
10
- migrations.swappable_dependency(settings.AUTH_USER_MODEL),
11
- ('polls', '0003_remove_choice_votes_votes'),
12
- ]
13
-
14
- operations = [
15
- migrations.RenameModel(
16
- old_name='Votes',
17
- new_name='Vote',
18
- ),
19
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
polls/models.py CHANGED
@@ -5,11 +5,25 @@ from django.contrib.auth import get_user_model
5
 
6
  User=get_user_model()
7
  # Create your models here.
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  class Question(models.Model):
9
 
10
  author = models.ForeignKey(User,on_delete=models.CASCADE)
11
  question_text = models.CharField(max_length=300)
12
  pub_date = models.DateTimeField("date published",default=datetime.datetime.now)
 
13
 
14
  def __str__(self):
15
  return self.question_text
 
5
 
6
  User=get_user_model()
7
  # Create your models here.
8
+
9
+ class ThemeColor(models.Model):
10
+
11
+ title = models.CharField(max_length=200,primary_key=True)
12
+ primary_color = models.CharField(max_length=7)
13
+ secondary_color = models.CharField(max_length=7)
14
+
15
+ def __str__(self):
16
+ return self.pk
17
+
18
+
19
+
20
+
21
  class Question(models.Model):
22
 
23
  author = models.ForeignKey(User,on_delete=models.CASCADE)
24
  question_text = models.CharField(max_length=300)
25
  pub_date = models.DateTimeField("date published",default=datetime.datetime.now)
26
+ theme_color = models.ForeignKey(ThemeColor,on_delete=models.SET_NULL,blank=True,null=True)
27
 
28
  def __str__(self):
29
  return self.question_text
polls/static/polls/create.css CHANGED
@@ -1,3 +1,8 @@
 
 
 
 
 
1
  /*********************sub header***************************/
2
  #sub_header{
3
  font-weight:100;
@@ -15,18 +20,18 @@
15
 
16
  }
17
 
18
- .question_container{
19
  width:500px;
20
 
21
  color:#ffffff;
22
- background-color: #5B66C6;
23
 
24
  border-radius: 7px;
25
  box-shadow: 0px 20px 52px 0px #0000004b;
26
  overflow: hidden;
27
  margin-top:40px;
28
  }
29
- .question_container:last-child{
30
  margin-bottom:40px;
31
  }
32
 
@@ -54,8 +59,8 @@
54
  .question_header>#question_text{
55
  height: 20px;
56
  width: 60%;
57
- color:white;
58
- background-color: #5B66C6;
59
  border:none;
60
  outline: none;
61
  border-bottom:white solid 2px;
@@ -65,7 +70,7 @@
65
  resize: none;
66
  }
67
  .question_header>#question_text::placeholder{
68
- color:#dddbdb;
69
  }
70
 
71
  .question_header>.right_section{
@@ -80,7 +85,7 @@
80
 
81
  }
82
 
83
- .question_container>.form_container{
84
  box-sizing: border-box;
85
  padding: 10px 20px;
86
  width: 100%;
@@ -103,7 +108,7 @@
103
  margin: 10px 0;
104
  padding: 10px 20px;
105
 
106
- background-color: #5b66c670;
107
 
108
  border-radius: 3px;
109
 
@@ -139,7 +144,7 @@
139
  border:none;
140
  outline: none;
141
 
142
- background-color: #5B66C6;
143
  color: white;
144
  padding: 10px 30px;
145
  border-radius: 8px;
@@ -151,10 +156,42 @@
151
 
152
 
153
  #add_option{
154
- color:#5B66C6;
155
 
156
  }
157
  #add_option:hover{
158
- text-decoration:#5B66C6 underline solid 2px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  cursor: pointer;
 
 
 
 
 
 
 
 
160
  }
 
1
+ :root{
2
+ --primary-color:#5B66C6;
3
+ --secondary-color:#5b66c670;
4
+ }
5
+
6
  /*********************sub header***************************/
7
  #sub_header{
8
  font-weight:100;
 
20
 
21
  }
22
 
23
+ #question_container{
24
  width:500px;
25
 
26
  color:#ffffff;
27
+ background-color: var(--primary-color);
28
 
29
  border-radius: 7px;
30
  box-shadow: 0px 20px 52px 0px #0000004b;
31
  overflow: hidden;
32
  margin-top:40px;
33
  }
34
+ #question_container:last-child{
35
  margin-bottom:40px;
36
  }
37
 
 
59
  .question_header>#question_text{
60
  height: 20px;
61
  width: 60%;
62
+ color:inherit;
63
+ background-color: inherit;
64
  border:none;
65
  outline: none;
66
  border-bottom:white solid 2px;
 
70
  resize: none;
71
  }
72
  .question_header>#question_text::placeholder{
73
+ color:#ffffff;
74
  }
75
 
76
  .question_header>.right_section{
 
85
 
86
  }
87
 
88
+ #question_container>.form_container{
89
  box-sizing: border-box;
90
  padding: 10px 20px;
91
  width: 100%;
 
108
  margin: 10px 0;
109
  padding: 10px 20px;
110
 
111
+ background-color:var(--secondary-color);
112
 
113
  border-radius: 3px;
114
 
 
144
  border:none;
145
  outline: none;
146
 
147
+ background-color: var(--primary-color);
148
  color: white;
149
  padding: 10px 30px;
150
  border-radius: 8px;
 
156
 
157
 
158
  #add_option{
159
+ color:var(--primary-color);
160
 
161
  }
162
  #add_option:hover{
163
+ text-decoration:var(--primary-color) underline solid 2px;
164
+ cursor: pointer;
165
+ }
166
+
167
+
168
+ .themes_container{
169
+ border: 2px solid black;
170
+ width: fit-content;
171
+ }
172
+ .themes{
173
+ display: flex;
174
+ flex-direction: row;
175
+ border-top: 2px solid black;
176
+ }
177
+
178
+ .theme{
179
+ height: 50px;
180
+ aspect-ratio: 1;
181
+ background-color: blueviolet;
182
+ margin: 2px 5px;
183
+ color:white;
184
+ border-radius: 50%;
185
+ position:relative;
186
+ }
187
+ .theme:hover{
188
  cursor: pointer;
189
+ transform: scale(1.1);
190
+ }
191
+
192
+ .theme span{
193
+ position: absolute;
194
+ left:50%;
195
+ top:50%;
196
+ transform: translate(-50%,-50%);
197
  }
polls/static/polls/create.js CHANGED
@@ -119,7 +119,7 @@ function validate(){
119
  return true;
120
  }
121
 
122
-
123
 
124
  function create_question(){
125
  if(!validate()) return;
@@ -144,6 +144,9 @@ function create_question(){
144
 
145
  data_to_send["question_text"]=question_text.value;
146
  data_to_send["choice_text_list"]=choice_text_list;
 
 
 
147
 
148
  fetch("",{
149
  method:"POST",
@@ -161,4 +164,26 @@ function create_question(){
161
  }
162
 
163
  create_choice();
164
- create_choice();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  return true;
120
  }
121
 
122
+ var theme=null;
123
 
124
  function create_question(){
125
  if(!validate()) return;
 
144
 
145
  data_to_send["question_text"]=question_text.value;
146
  data_to_send["choice_text_list"]=choice_text_list;
147
+ if (theme!=null)
148
+ data_to_send['theme_color']=theme;
149
+
150
 
151
  fetch("",{
152
  method:"POST",
 
164
  }
165
 
166
  create_choice();
167
+ create_choice();
168
+
169
+ function rgbtohex(value){
170
+ value=value.split("(")[1].split(")")[0];
171
+ value=value.split(",");
172
+ value = value.map(function(x){ //For each array element
173
+ x = parseInt(x).toString(16); //Convert to a base16 string
174
+ return (x.length==1) ? "0"+x : x; //Add zero if we get only one character
175
+ });
176
+ value="#"+value.join("");
177
+
178
+ return value;
179
+ }
180
+ function changetheme(elem){
181
+ // set question to theme color
182
+ // console.log(rgbtohex(elem.style.backgroundColor));
183
+ // console.log(rgbtohex(elem.style.color));
184
+ // question_container.style.color=rgbtohex(elem.style.color);
185
+ document.documentElement.style.setProperty("--primary-color",rgbtohex(elem.style.backgroundColor));
186
+ document.documentElement.style.setProperty("--secondary-color",rgbtohex(elem.style.color));
187
+ theme=elem.dataset.id;
188
+ // set form theme value
189
+ }
polls/static/polls/index.css CHANGED
@@ -101,7 +101,7 @@
101
  .question_header>.question_text{
102
  width: 60%;
103
  color:white;
104
- background-color: var(--primary-color);
105
  border:none;
106
  outline: none;
107
 
 
101
  .question_header>.question_text{
102
  width: 60%;
103
  color:white;
104
+ background-color: transparent;
105
  border:none;
106
  outline: none;
107
 
polls/static/polls/index.js CHANGED
@@ -91,11 +91,45 @@ function Vote(elem){
91
  }
92
 
93
  document.querySelectorAll(".choices.result>.choice").forEach(choice=>{
94
- console.log(choice.dataset.percent);
95
  show_result(choice);
96
  });
97
 
98
  function show_result(choice){
99
- choice.style.background= `linear-gradient(90deg, var(--percentage-color) ${choice.dataset.percent}%, var(--secondary-color) 0%)`;
 
 
 
 
100
  choice.innerHTML+=choice.dataset.percent+"%";
101
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  }
92
 
93
  document.querySelectorAll(".choices.result>.choice").forEach(choice=>{
94
+ // console.log(choice.dataset.percent);
95
  show_result(choice);
96
  });
97
 
98
  function show_result(choice){
99
+ var q=choice.closest(".question_container");
100
+ if(q.hasAttribute("data-primary"))
101
+ choice.style.background= `linear-gradient(90deg, ${q.dataset.primary} ${choice.dataset.percent}%, ${q.dataset.secondary} 0%)`;
102
+ else
103
+ choice.style.background= `linear-gradient(90deg, var(--percentage-color) ${choice.dataset.percent}%, var(--secondary-color) 0%)`;
104
  choice.innerHTML+=choice.dataset.percent+"%";
105
+ }
106
+
107
+
108
+
109
+
110
+ document.querySelectorAll(".question_container").forEach(q=>{
111
+ if (!q.hasAttribute("data-primary")) return;
112
+
113
+ // console.log(q);
114
+ var style=`
115
+ .question_container[data-primary="${q.dataset.primary}"]{
116
+ background-color:${q.dataset.primary};
117
+ }
118
+ .question_container[data-primary="${q.dataset.primary}"] .choice{
119
+ background-color:${q.dataset.secondary};
120
+ }
121
+ .question_container[data-primary="${q.dataset.primary}"] .choice:hover{
122
+ background-color:${q.dataset.primary};
123
+ }
124
+ .question_container[data-primary="${q.dataset.primary}"] .choice.active{
125
+ background-color:${q.dataset.primary};
126
+ }
127
+ .question_container[data-primary="${q.dataset.primary}"] .vote_btn{
128
+ background-color:${q.dataset.primary};
129
+ }
130
+
131
+ `;
132
+
133
+ custom_style.innerText+=style;
134
+
135
+ });
polls/templates/polls/create.html CHANGED
@@ -9,13 +9,35 @@
9
 
10
  <h2 id="sub_header">Create Poll</h2>
11
 
12
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
 
14
 
15
  <div id="main_container">
16
 
17
 
18
- <div class="question_container">
19
  <div class="question_header">
20
  <textarea id="question_text" placeholder="New question"></textarea>
21
 
 
9
 
10
  <h2 id="sub_header">Create Poll</h2>
11
 
12
+
13
+ <div class="themes_container">
14
+ Themes
15
+ <div class="themes">
16
+ {% for theme in themes %}
17
+ <div class="theme"
18
+
19
+ data-id="{{ theme.pk }}"
20
+
21
+ style="
22
+ background-color: {{ theme.primary_color }};
23
+ color: {{ theme.secondary_color }};
24
+ border: 10px solid {{ theme.secondary_color }};
25
+ "
26
+ onclick="changetheme(this);"
27
+
28
+ >
29
+
30
+ <span>{{ theme }}</span>
31
+ </div>
32
+ {% endfor %}
33
+ </div>
34
+ </div>
35
 
36
 
37
  <div id="main_container">
38
 
39
 
40
+ <div id="question_container">
41
  <div class="question_header">
42
  <textarea id="question_text" placeholder="New question"></textarea>
43
 
polls/templates/polls/index.html CHANGED
@@ -4,6 +4,7 @@
4
  {% load index %}
5
  {% load static %}
6
  <link type="text/css" rel="stylesheet" href="{% static 'polls/index.css' %}">
 
7
  {% endblock %}
8
 
9
  {% block body %}
 
4
  {% load index %}
5
  {% load static %}
6
  <link type="text/css" rel="stylesheet" href="{% static 'polls/index.css' %}">
7
+ <style id="custom_style"></style>
8
  {% endblock %}
9
 
10
  {% block body %}
polls/templates/polls/question_list.html CHANGED
@@ -4,8 +4,14 @@
4
 
5
  <div id="main_container">
6
  {% for question in latest_questions_list %}
7
-
8
- <div class="question_container" data-id="{{ question.pk }}">
 
 
 
 
 
 
9
  <div class="question_header">
10
  <textarea oninput="OnInput(event)" class="question_text" readonly="true">{{ question.question_text }}</textarea>
11
  <div class="right_section">
@@ -34,6 +40,7 @@
34
  {% if question.has_voted %}
35
  data-percent="{{ choice.vote_percent }}"
36
  {% endif %}
 
37
  >
38
 
39
  <span>
@@ -51,7 +58,10 @@
51
  {% if canDelete %}
52
  <button class="delete_btn" onclick="DeletePoll(this)">Delete</button>
53
  {% endif %}
54
- <button class="vote_btn" onclick="Vote(this)">Vote</button>
 
 
 
55
  </div>
56
  </div>
57
  </div>
 
4
 
5
  <div id="main_container">
6
  {% for question in latest_questions_list %}
7
+
8
+ <div class="question_container" data-id="{{ question.pk }}"
9
+
10
+ {% if question.theme_color %}
11
+ data-primary="{{ question.theme_color.primary_color }}"
12
+ data-secondary="{{ question.theme_color.secondary_color }}"
13
+ {% endif %}
14
+ >
15
  <div class="question_header">
16
  <textarea oninput="OnInput(event)" class="question_text" readonly="true">{{ question.question_text }}</textarea>
17
  <div class="right_section">
 
40
  {% if question.has_voted %}
41
  data-percent="{{ choice.vote_percent }}"
42
  {% endif %}
43
+
44
  >
45
 
46
  <span>
 
58
  {% if canDelete %}
59
  <button class="delete_btn" onclick="DeletePoll(this)">Delete</button>
60
  {% endif %}
61
+ <button class="vote_btn" onclick="Vote(this)"
62
+
63
+ >
64
+ Vote</button>
65
  </div>
66
  </div>
67
  </div>
polls/views.py CHANGED
@@ -5,7 +5,7 @@ from django.contrib.auth import get_user_model
5
  from django.contrib.auth.decorators import login_required
6
  from django.urls import reverse
7
  import json
8
- from .models import Question,Choice,Vote
9
  from .forms import UserSignupForm,UserLoginForm
10
 
11
 
@@ -137,15 +137,24 @@ def login(request):
137
 
138
  return render(request,"polls/login.html",context)
139
 
 
140
  @login_required(login_url=login_url)
141
  def create(request):
142
  if request.method=="GET":
143
- return render(request,'polls/create.html',{})
 
 
144
 
145
  json_data=json.loads(request.body)
146
  print(json_data)
 
 
 
 
 
147
  question=Question.objects.create(author=request.user,
148
- question_text=json_data['question_text'])
 
149
  question.save()
150
 
151
  for choice_text in json_data['choice_text_list']:
 
5
  from django.contrib.auth.decorators import login_required
6
  from django.urls import reverse
7
  import json
8
+ from .models import Question,Choice,Vote,ThemeColor
9
  from .forms import UserSignupForm,UserLoginForm
10
 
11
 
 
137
 
138
  return render(request,"polls/login.html",context)
139
 
140
+
141
  @login_required(login_url=login_url)
142
  def create(request):
143
  if request.method=="GET":
144
+ # get themes
145
+ themes=ThemeColor.objects.all()
146
+ return render(request,'polls/create.html',{"themes":themes})
147
 
148
  json_data=json.loads(request.body)
149
  print(json_data)
150
+ if "theme_color" in json_data:
151
+ theme_color=ThemeColor.objects.get(pk=json_data['theme_color'])
152
+ else:
153
+ theme_color=None
154
+
155
  question=Question.objects.create(author=request.user,
156
+ question_text=json_data['question_text'],
157
+ theme_color=theme_color)
158
  question.save()
159
 
160
  for choice_text in json_data['choice_text_list']: