Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DATABASE_NAME=screencast
DATABASE_USER=screencastadmin@screencast2020
DATABASE_PASSWORD=screencast2020!
DATABASE_HOST=screencast2020.postgres.database.azure.com
DATABASE_NAME=screencast
DATABASE_USER=screencastadmin@screencast2020
DATABASE_PASSWORD=screencast2020!
DATABASE_HOST=screencast2020.postgres.database.azure.com
DATABASE_PORT=5432
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ __pycache__
myvenv
db.sqlite3
/static
.DS_Store
.DS_Store
# Elastic Beanstalk Files
.elasticbeanstalk/*
!.elasticbeanstalk/*.cfg.yml
!.elasticbeanstalk/*.global.yml
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN python -m pip install --upgrade pip
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/

3 changes: 1 addition & 2 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
web: gunicorn screencast --log-file -
web: python manage.py runserver 0.0.0.0:5000
web: gunicorn screencast.wsgi
2 changes: 1 addition & 1 deletion api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def validate(self,data):
"result":result
}


class SocialSerializer(serializers.Serializer):
"""
Serializer which accepts an OAuth2 access token and provider.
Expand Down
1 change: 1 addition & 0 deletions api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
path('refresh',TokenRefreshView.as_view(),name='token_refresh'),
path('question',views.getquestion.as_view(),name='question api'),
path('facebooklogin',views.facebooklogin.as_view(),name='facebooklogin'),
path('status',views.configstatus,name='quiz_status'),
]
24 changes: 22 additions & 2 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
from social_django.utils import load_strategy, load_backend
from social_core.backends.oauth import BaseOAuth2
from social_core.exceptions import MissingBackend, AuthTokenError, AuthForbidden
import time
# Create your views here.

import requests as r


@api_view(['GET'])
Expand Down Expand Up @@ -52,6 +53,23 @@ def get(self,request):
}
return Response(response)

import pytz
utc=pytz.UTC
@api_view(['GET'])
def configstatus(request):
configs=config.objects.all()
if configs:
response={
"current_day":configs[0].current_day,
"start_time":configs[0].quiz_start.replace(tzinfo=utc),
"end_time":configs[0].quiz_endtime.replace(tzinfo=utc)
}
return Response(response)
response={
"status":404,
"message":"no confings founnd"
}
return Response(response)
class Answer(APIView):
permission_classes=(IsAuthenticated,)

Expand Down Expand Up @@ -120,8 +138,10 @@ def post(self, request):
class facebooklogin(APIView):

def post(self,request):
print(request.data)
accesstoken=request.data.get('accesstoken')
expiration_time=request.data.get('expiration_time')
print(expiration_time)
userID=request.data.get('userID')
if(int(expiration_time) < int(time.time())):
content= {"status": 404}
Expand All @@ -138,7 +158,7 @@ def post(self,request):
username= idInfo['name'],
image= idInfo['picture']['data']['url'],
try:
user = User.objects.get(email=data['email'])
user = User.objects.get(email=email)
except User.DoesNotExist:
user = User()
user.username = username
Expand Down
23 changes: 23 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: '3'

services:
db:
image: postgres
environment:
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
web:
build: .
command: gunicorn screencast.wsgi:application --bind 0.0.0.0:8000
ports:
- "8000:8000"
depends_on:
- db
- migration

migration:
build: .
command: python manage.py migrate --noinput
depends_on:
- db
116 changes: 58 additions & 58 deletions quiz/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,58 @@
# Generated by Django 3.0.5 on 2020-06-19 07:29

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='config',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('current_day', models.IntegerField()),
('q_no', models.IntegerField()),
('quiz_start', models.DateTimeField()),
('quiz_endtime', models.DateTimeField()),
],
),
migrations.CreateModel(
name='Question',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('question', models.CharField(max_length=550)),
('day', models.IntegerField()),
('question_no', models.IntegerField()),
('answer', models.CharField(max_length=100)),
('audio', models.FileField(blank=True, upload_to='media/audios')),
('image', models.ImageField(blank=True, upload_to='media/images')),
('hint', models.CharField(default='na', max_length=555)),
],
options={
'ordering': ['day', 'question_no'],
},
),
migrations.CreateModel(
name='UserScore',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=55, null=True)),
('score', models.IntegerField(default=0)),
('rank', models.IntegerField(null=True)),
('current_question', models.IntegerField()),
('last_modified', models.DateTimeField(auto_now=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['-score', 'last_modified'],
},
),
]
# Generated by Django 3.0.5 on 2020-06-19 07:29
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='config',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('current_day', models.IntegerField()),
('q_no', models.IntegerField()),
('quiz_start', models.DateTimeField()),
('quiz_endtime', models.DateTimeField()),
],
),
migrations.CreateModel(
name='Question',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('question', models.CharField(max_length=550)),
('day', models.IntegerField()),
('question_no', models.IntegerField()),
('answer', models.CharField(max_length=100)),
('audio', models.FileField(blank=True, upload_to='media/audios')),
('image', models.ImageField(blank=True, upload_to='media/images')),
('hint', models.CharField(default='na', max_length=555)),
],
options={
'ordering': ['day', 'question_no'],
},
),
migrations.CreateModel(
name='UserScore',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=55, null=True)),
('score', models.IntegerField(default=0)),
('rank', models.IntegerField(null=True)),
('current_question', models.IntegerField()),
('last_modified', models.DateTimeField(auto_now=True)),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'ordering': ['-score', 'last_modified'],
},
),
]
11 changes: 6 additions & 5 deletions quiz/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ def quiz_active(self):
return False
return True
def save(self, force_insert=False, force_update=False, *args, **kwargs):
players=UserScore.objects.all()
for player in players:
player.current_question=1
player.save()
super(config, self).save(force_insert, force_update, *args, **kwargs)
if not self.pk:
players=UserScore.objects.all()
for player in players:
player.current_question=1
player.save()
super(config, self).save(force_insert, force_update, *args, **kwargs)
Binary file modified requirements.txt
Binary file not shown.
47 changes: 27 additions & 20 deletions screencast/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import os
from datetime import timedelta
import django_heroku
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Expand All @@ -20,12 +21,12 @@
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'k(o5900674725b3)1w5(lgz$9ckubfetysox12!(3h4=73+@^&'
SECRET_KEY = os.environ.get('SECRET_KEY','k(o5900674725b3)1w5(lgz$9ckubfetysox12!(3h4=73+@^&')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['screencast20.azurewebsites.net','127.0.0.1','.herokuapp.com','.pythonanywhere.com']
ALLOWED_HOSTS = []


# Application definition
Expand All @@ -41,7 +42,7 @@
'account',
'api',
'rest_framework',
#'corsheaders',
'corsheaders',
'rest_framework_social_oauth2',
'oauth2_provider',
'social_django',
Expand Down Expand Up @@ -94,11 +95,6 @@
WSGI_APPLICATION = 'screencast.wsgi.application'
CORS_ORIGIN_ALLOW_ALL = True

CORS_ORIGIN_WHITELIST = (
'http//:localhost:8000',
# add your frontend server site here
)


# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
Expand All @@ -109,20 +105,29 @@
#'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
#}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'screencast',
'USER': 'screencastadmin@screencast2020',
'PASSWORD': 'screencast2020!',
'HOST': 'screencast2020.postgres.database.azure.com',

'OPTIONS': {
#'sslmode': 'require',
if 'RDS_DB_NAME' in os.environ:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ['RDS_DB_NAME'],
'USER': os.environ['RDS_USERNAME'],
'PASSWORD': os.environ['RDS_PASSWORD'],
'HOST': os.environ['RDS_HOSTNAME'],
'PORT': os.environ['RDS_PORT'],
}
}
else :
DATABASES = { # GALAXYZPJ'S LOCAL INSTANCE
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'postgres',
'PASSWORD': 'postgres',
'HOST': 'postgres',
'PORT': '5432',
}
}
#DATABASES = {
#DATABpippiASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.postgresql_psycopg2',
# 'NAME': 'd8s04nkvqhp0h4',
Expand Down Expand Up @@ -230,4 +235,6 @@
'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp',
'SLIDING_TOKEN_LIFETIME': timedelta(minutes=30),
'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1),
}
}

django_heroku.settings(locals())