Skip to content

Commit

Permalink
Added limit question feature within duration (#23)
Browse files Browse the repository at this point in the history
* New_Duration_feature

* Added control message within duration feature and made production ready
  • Loading branch information
Apurva-Jyoti-paul authored Jan 1, 2022
1 parent 658a58d commit 4576770
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SECRET_KEY=djangosecretkey
CLIENT_ID=yourgoogleoauthclientid
CLIENT_ID=407408718192.apps.googleusercontent.com
APP_ID=facebookoauthid
APP_SECRET=facebookoauthsecret
DOWNLOAD=passwordtodownloadleaderboard
Expand All @@ -8,4 +8,5 @@ DB_USER=blahaja
DB_PASSWORD=notmypass
DB_HOST=localhost
DB_PORT=5432
DEBUG=True
GOOGLE_MAPS_API_KEY=
6 changes: 5 additions & 1 deletion Digital_Fortress_Backend/dev_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', cast=bool)

ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv())
#ALLOWED_HOSTS = config('ALLOWED_HOSTS', cast=Csv())
ALLOWED_HOSTS = ["*"]
GOOGLE_MAPS_API_KEY = config('GOOGLE_MAPS_API_KEY')


Expand Down Expand Up @@ -159,6 +160,9 @@
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static/')

MEDIA_URL='/media/'
MEDIA_ROOT=os.path.join(BASE_DIR,'media')

CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
CORS_ORIGIN_WHITELIST = [
Expand Down
18 changes: 18 additions & 0 deletions Quiz/migrations/0011_duration_leaderboard_hide.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.4 on 2021-12-28 06:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('Quiz', '0010_duration_leaderboard_freeze'),
]

operations = [
migrations.AddField(
model_name='duration',
name='leaderboard_hide',
field=models.BooleanField(default=0),
),
]
18 changes: 18 additions & 0 deletions Quiz/migrations/0012_duration_max_question.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.4 on 2021-12-28 14:40

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('Quiz', '0011_duration_leaderboard_hide'),
]

operations = [
migrations.AddField(
model_name='duration',
name='max_question',
field=models.IntegerField(default=20),
),
]
1 change: 1 addition & 0 deletions Quiz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class duration(models.Model):
end_time = models.DateTimeField(default=datetime.now)
leaderboard_freeze= models.BooleanField(default = 0)
leaderboard_hide = models.BooleanField(default = 0)
max_question=models.IntegerField(default=20)


def __str__(self):
Expand Down
6 changes: 5 additions & 1 deletion Quiz/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def verifyGoogleToken(token):
idinfo = id_token.verify_oauth2_token(
token, requests.Request(), CLIENT_ID)


if idinfo['iss'] not in ['accounts.google.com', 'https://accounts.google.com']:
raise ValueError('Wrong issuer.')

Expand Down Expand Up @@ -259,7 +260,10 @@ def get(self, request, format=None):
curr_round = Round.objects.get(round_number=player.roundNo)
serializer = RoundSerializer(curr_round)
centre = centrePoint(curr_round)
return Response({"question": serializer.data, "centre": centre, "status": 200, "detail": 1})
if duration.objects.all().first().max_question>=player.roundNo:
return Response({"question": serializer.data, "centre": centre, "status": 200, "detail": 1})
else:
return Response({"message": "Finished!", "status": 404, "detail": 1})
except Round.DoesNotExist:
return Response({"message": "Finished!", "status": 404, "detail": 1})
return Response({"data": None})
Expand Down

0 comments on commit 4576770

Please sign in to comment.