Skip to content

Commit f0a2b44

Browse files
committed
redirect issue left.
0 parents  commit f0a2b44

File tree

1,704 files changed

+240727
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,704 files changed

+240727
-0
lines changed

Data for the Google API

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
client id:768856011390-e6mlm3j8uompfqlm56eoo86e5gm80ipj.apps.googleusercontent.com
2+
secret key: 7qyKIxyBCCNXBPSBQg3aMiAN

db.sqlite3

236 KB
Binary file not shown.

manage.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "qrious.settings")
7+
try:
8+
from django.core.management import execute_from_command_line
9+
except ImportError:
10+
# The above import may fail for some other reason. Ensure that the
11+
# issue is really that Django is missing to avoid masking other
12+
# exceptions on Python 2.
13+
try:
14+
import django
15+
except ImportError:
16+
raise ImportError(
17+
"Couldn't import Django. Are you sure it's installed and "
18+
"available on your PYTHONPATH environment variable? Did you "
19+
"forget to activate a virtual environment?"
20+
)
21+
raise
22+
execute_from_command_line(sys.argv)
155 Bytes
Binary file not shown.
292 Bytes
Binary file not shown.

myapp/__pycache__/apps.cpython-36.pyc

500 Bytes
Binary file not shown.
1.49 KB
Binary file not shown.
745 Bytes
Binary file not shown.

myapp/__pycache__/urls.cpython-36.pyc

971 Bytes
Binary file not shown.
4.64 KB
Binary file not shown.

myapp/admin.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.contrib import admin
2+
from myapp.models import Userdata, Question
3+
# Register your models here.
4+
admin.site.register(Userdata)
5+
admin.site.register(Question)

myapp/apps.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.apps import AppConfig
2+
3+
4+
class MyappConfig(AppConfig):
5+
name = 'myapp'
6+
7+
def ready(self):
8+
import myapp.signals

myapp/migrations/0001_initial.py

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.5 on 2019-03-02 14:56
3+
from __future__ import unicode_literals
4+
5+
from django.conf import settings
6+
from django.db import migrations, models
7+
import django.db.models.deletion
8+
9+
10+
class Migration(migrations.Migration):
11+
12+
initial = True
13+
14+
dependencies = [
15+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
16+
]
17+
18+
operations = [
19+
migrations.CreateModel(
20+
name='Question',
21+
fields=[
22+
('question_no', models.AutoField(default=True, primary_key=True, serialize=False)),
23+
('reality_type', models.CharField(choices=[('MAGIC', 'MAGIC'), ('ROBOTICS', 'ROBOTICS'), ('GAMING', 'GAMING'), ('MYTHOLOGY', 'MYTHOLOGY')], max_length=450, null=True)),
24+
('question', models.CharField(max_length=450, unique=True)),
25+
('choice1', models.CharField(max_length=450, null=True)),
26+
('choice2', models.CharField(max_length=450, null=True)),
27+
('choice3', models.CharField(max_length=450, null=True)),
28+
('choice4', models.CharField(max_length=450, null=True)),
29+
('correct_choice', models.CharField(max_length=450, null=True)),
30+
],
31+
),
32+
migrations.CreateModel(
33+
name='Userdata',
34+
fields=[
35+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
36+
('bits_id', models.EmailField(blank=True, max_length=254, null=True)),
37+
('score', models.PositiveIntegerField(default=0)),
38+
('magicmarks', models.IntegerField(default=0)),
39+
('roboticsmarks', models.IntegerField(default=0)),
40+
('mythologymarks', models.IntegerField(default=0)),
41+
('ques_answered', models.CharField(blank=True, max_length=450, null=True)),
42+
('last_question', models.IntegerField(default=0)),
43+
('current_reality', models.IntegerField(default=0)),
44+
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
45+
],
46+
),
47+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.5 on 2019-03-03 11:03
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('myapp', '0001_initial'),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name='question',
17+
name='question_no',
18+
field=models.IntegerField(default=0, primary_key=True, serialize=False),
19+
),
20+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.11.5 on 2019-03-17 02:48
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('myapp', '0002_auto_20190303_1103'),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name='userdata',
17+
name='ques_answered',
18+
field=models.CharField(blank=True, default='', max_length=450),
19+
),
20+
]

myapp/migrations/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

myapp/models.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from django.db import models
2+
from django.contrib.auth.models import User
3+
# Create your models here.
4+
5+
REALITY_TYPES = (
6+
('MAGIC', 'MAGIC'),
7+
('ROBOTICS', 'ROBOTICS'),
8+
('GAMING', 'GAMING'),
9+
('MYTHOLOGY', 'MYTHOLOGY'),
10+
)
11+
12+
13+
class Userdata(models.Model):
14+
user = models.OneToOneField(User, on_delete=models.CASCADE)
15+
bits_id = models.EmailField(blank=True, null=True)
16+
score = models.PositiveIntegerField(default=0)
17+
magicmarks = models.IntegerField(default=0)
18+
roboticsmarks = models.IntegerField(default=0)
19+
mythologymarks = models.IntegerField(default=0)
20+
ques_answered = models.CharField(max_length=450, blank=True, default='')
21+
last_question = models.IntegerField(default=0)
22+
current_reality = models.IntegerField(default=0)
23+
24+
# def __str__(self):
25+
# return self.name
26+
27+
28+
class Question(models.Model):
29+
#question_no = models.AutoField(primary_key=True)
30+
question_no = models.IntegerField(default=0, primary_key=True)
31+
reality_type = models.CharField(max_length=450, choices=REALITY_TYPES, null=True)
32+
question = models.CharField(max_length=450, unique=True)
33+
choice1 = models.CharField(max_length=450, null=True)
34+
choice2 = models.CharField(max_length=450, null=True)
35+
choice3 = models.CharField(max_length=450, null=True)
36+
choice4 = models.CharField(max_length=450, null=True)
37+
correct_choice = models.CharField(max_length=450, null=True)
38+
39+
def __str__(self):
40+
return str(self.question_no)

myapp/signals.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from django.contrib.auth.models import User
2+
from django.db.models.signals import post_save
3+
from django.dispatch import receiver
4+
5+
from .models import Userdata
6+
7+
8+
@receiver(post_save, sender=User)
9+
def create_user_profile(sender, instance, created, **kwargs):
10+
if created:
11+
userdata = Userdata.objects.create(user=instance, bits_id=instance.email)
12+
userdata.save()
13+
14+
15+
@receiver(post_save, sender=User)
16+
def save_profile(sender, instance, **kwargs):
17+
instance.userdata.save()

myapp/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

myapp/urls.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from django.conf.urls import url
2+
from myapp.views import home, roulette, loading, l_out, quiz, userdat, intro, getquestion, leaderboard_view, realitychange, postanswer
3+
4+
urlpatterns = [
5+
url(r'^$', home, name='myapp-home'),
6+
url(r'^loading$', loading, name='myapp-load'),
7+
url(r'^roulette$', roulette, name='myapp-roulette'),
8+
url(r'^getInfo$', userdat, name='myapp-get-usrdata'),
9+
url(r'^reality/get/request$', realitychange, name='myapp-post-reality'),
10+
url(r'^(?P<filename>[^/]+)/$', intro, name='myapp-intro'),
11+
url(r'^(?P<basename>[^/]+)/(?P<filename>[^/]+)$', quiz, name='myapp-quiz'),
12+
url(r'^questions/reality/request$', getquestion, name='myapp-getques'),
13+
url(r'^answer/ajax/post$', postanswer, name='myapp-post-answer'),
14+
url(r'^leaderboard$', leaderboard_view, name='myapp-leaderboard'),
15+
url(r'^logout$', l_out, name='myapp-logout'),
16+
]
17+
# /get_question
18+
# /get_leaderboard

myapp/views.py

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
from __future__ import unicode_literals
2+
from django.shortcuts import render, redirect, HttpResponse, HttpResponseRedirect
3+
from django.contrib.auth import logout
4+
from django.views.decorators.csrf import csrf_exempt
5+
from django.http import JsonResponse, HttpResponseRedirect
6+
from .models import Userdata, Question
7+
import json
8+
9+
# Create your views here.
10+
11+
12+
def userdat(request):
13+
usrdata = {}
14+
if request.user.is_authenticated():
15+
# username,score,current_reality,last_question
16+
user = request.user
17+
print(type(str(request.user)))
18+
usrdata["username"] = user.username
19+
usrdata["score"] = user.userdata.score
20+
usrdata["current_reality"] = user.userdata.current_reality
21+
usrdata["answered_questions"] = user.userdata.last_question
22+
return JsonResponse(usrdata, safe=False,)
23+
# score,question,last_question's answer(POST),
24+
25+
26+
def home(request):
27+
if(request.method == 'POST'):
28+
logout(request)
29+
return redirect('/accounts/google/login')
30+
return render(request, 'index.html')
31+
32+
33+
def loading(request):
34+
return render(request, 'loader.html')
35+
36+
37+
def roulette(request):
38+
if request.user.userdata.current_reality == 0:
39+
return render(request, 'roulette.html')
40+
else:
41+
url_list = ['mythology', 'magic', 'robotic', 'gaming']
42+
redirect_url = ''.join(
43+
["/roulette/", url_list[request.user.userdata.current_reality-1], "des.html"])
44+
return redirect(redirect_url)
45+
46+
47+
def l_out(request):
48+
logout(request)
49+
return redirect('/')
50+
51+
52+
def intro(request, filename):
53+
return render(request, filename)
54+
55+
56+
def quiz(request, filename, basename):
57+
return render(request, filename)
58+
59+
60+
def leaderboard_view(request):
61+
data = []
62+
leaderboard = Userdata.objects.order_by('score').reverse()[:10]
63+
for user in leaderboard:
64+
user_details = {"name": user.user.username, "score": user.score}
65+
data.append(user_details)
66+
67+
obj = Userdata.objects.get(user=request.user)
68+
my_details = {"name": obj.user.username, "score": obj.score}
69+
data.append(my_details)
70+
return JsonResponse(data, safe=False)
71+
72+
73+
@csrf_exempt
74+
def postanswer(request):
75+
if request.method == 'POST':
76+
print(request.POST)
77+
print("last_question=", request.user.userdata.last_question)
78+
print("current_reality=", request.user.userdata.current_reality)
79+
ques_no = request.POST['question']
80+
request.user.userdata.last_question = ques_no
81+
request.user.userdata.save()
82+
ques_answered = request.user.userdata.ques_answered
83+
ques_answered = ques_answered+str(ques_no)+'-'
84+
queslist = ques_answered.split('-')[:-1]
85+
for i in range(len(queslist)):
86+
queslist[i] = int(queslist[i])
87+
request.user.userdata.ques_answered = ques_answered
88+
request.user.userdata.save()
89+
print(request.user.userdata.ques_answered)
90+
print("last_question_updated=", request.user.userdata.last_question)
91+
question = Question.objects.get(question_no=ques_no)
92+
selected_choice = request.POST['answer']
93+
print(question)
94+
print(selected_choice)
95+
if question.reality_type == 'MAGIC':
96+
if selected_choice == question.correct_choice:
97+
power = request.user.userdata.magicmarks
98+
request.user.userdata.score += 2 ** power
99+
request.user.userdata.magicmarks += 1
100+
else:
101+
request.user.userdata.magicmarks = 0
102+
elif question.reality_type == 'ROBOTICS':
103+
if selected_choice == question.correct_choice:
104+
simcorrect = request.user.userdata.roboticsmarks
105+
if simcorrect < 5:
106+
request.user.userdata.roboticsmarks += 1
107+
else:
108+
request.user.userdata.score += 25
109+
else:
110+
request.user.userdata.roboticsmarks = 0
111+
elif question.reality_type == 'GAMING':
112+
if selected_choice == question.correct_choice:
113+
request.user.userdata.score += 4
114+
else:
115+
request.user.userdata.score -= 1
116+
elif question.reality_type == 'MYTHOLOGY':
117+
if selected_choice == question.correct_choice:
118+
correct = request.user.userdata.mythologymarks
119+
if correct == 1:
120+
request.user.userdata.score += 2
121+
elif correct == 2:
122+
request.user.userdata.score += 3
123+
elif correct == 3:
124+
request.user.userdata.score += 5
125+
elif correct == 4:
126+
request.user.userdata.score += 8
127+
elif correct == 5:
128+
request.user.userdata.score += 13
129+
correct += 1
130+
request.user.userdata.save()
131+
print("score=", request.user.userdata.score)
132+
return HttpResponse('')
133+
134+
135+
@csrf_exempt
136+
def getquestion(request):
137+
if request.user.is_authenticated():
138+
ques_no = request.user.userdata.last_question
139+
reality = request.user.userdata.current_reality
140+
print(reality)
141+
ques_answered = request.user.userdata.ques_answered
142+
queslist = ques_answered.split('-')[:-1]
143+
for i in range(len(queslist)):
144+
queslist[i] = int(queslist[i])
145+
print(queslist)
146+
if ques_no in range((reality-1)*5+1, (reality)*5):
147+
question = Question.objects.get(question_no=(ques_no+1))
148+
elif ques_no != reality*5:
149+
question = Question.objects.get(question_no=((reality-1)*5+1))
150+
else:
151+
request.user.userdata.current_reality = 0
152+
request.user.userdata.save()
153+
question = Question.objects.get(question_no=1)
154+
return HttpResponseRedirect('/roulette')
155+
score = request.user.userdata.score
156+
print("correct_choice=", question.correct_choice)
157+
question_obj = {'question_number': question.question_no, 'question': question.question, 'option1': question.choice1, 'option2': question.choice2,
158+
'option3': question.choice3, 'option4': question.choice4, 'correct_choice': question.correct_choice, 'score': score}
159+
return JsonResponse(question_obj)
160+
161+
162+
@csrf_exempt
163+
def realitychange(request):
164+
if request.user.is_authenticated():
165+
if request.method == 'POST':
166+
request.user.userdata.current_reality = request.POST['reality']
167+
request.user.userdata.save()
168+
return HttpResponse('')
169+
170+
# 1. powerscheme - 2 ki power, resets on wrong answer
171+
# 2. all or nothing - all sahi to number warna gaye
172+
# 3. normal marking with negative +4 -1
173+
# 4. fibonacci marking
174+
# json.load(request.body.decode('utf-8'))
175+
# index
176+
# questions send
177+
# answer check
178+
# leaderboard
179+
# score calculate
180+
# reality check
181+
# total score
156 Bytes
Binary file not shown.
2.7 KB
Binary file not shown.
1004 Bytes
Binary file not shown.
530 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)