Skip to content
Open
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
23 changes: 22 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
amqp==2.3.2
billiard==3.5.0.4
cachetools==4.2.0
celery==4.2.1
certifi==2020.12.5
chardet==4.0.0
click==6.7
Django==2.1.11
django-admin==1.3.0
Expand All @@ -9,16 +12,34 @@ django-excel-response2==2.0.8
django-extensions==2.1.2
django-six==1.0.4
et-xmlfile==1.0.1
google-api-core==1.24.1
google-api-python-client==1.12.8
google-auth==1.24.0
google-auth-httplib2==0.0.4
google-auth-oauthlib==0.4.2
googleapis-common-protos==1.52.0
httplib2==0.18.1
idna==2.10
jdcal==1.4
kombu==4.2.1
lxml==4.2.4
mysqlclient==1.3.13
oauthlib==3.1.0
openpyxl==2.5.5
protobuf==3.14.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
python-docx==0.8.7
python-dotenv==0.15.0
pytz==2018.5
redis==2.10.6
requests==2.25.1
requests-oauthlib==1.3.0
rsa==4.7
screen==1.0.1
six==1.11.0
six==1.15.0
uritemplate==3.0.1
urllib3==1.26.2
vine==1.1.4
xlrd==1.1.0
xlwt==1.3.0
1 change: 1 addition & 0 deletions searchapp/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ class QuestionsFilter(admin.ModelAdmin):
admin.site.register(Questions, QuestionsFilter)
admin.site.register(SubjectSplit)
admin.site.register(Chapter, ChapterFilter)
admin.site.register(FormAuth)
44 changes: 44 additions & 0 deletions searchapp/generate_doc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
from docx import Document
import datetime
import os
from django.conf import settings
from json import dumps, loads
import pickle
from .models import FormAuth
import os.path
from googleapiclient import errors
from googleapiclient.discovery import build
from google_auth_oauthlib.flow import InstalledAppFlow
from google.auth.transport.requests import Request

qtype_to_section = {"1A": "A", "1B": "B", "2": "C", "3": "D", "5": "E"}


SCOPES = ['https://www.googleapis.com/auth/forms']
API_ID="MisrDt1oXa2FhUFiDHl9Yn5oDBuBhNfqu"

def get_no_of_questions(questions_mapping, question_type):
count = 0
for row in questions_mapping:
Expand Down Expand Up @@ -77,3 +89,35 @@ def convert_to_doc(questions_mapping, subject):
filepath = os.path.join('searchapp/static/docs', filename)
document.save(filepath)
return filepath

def convert_to_form(questions_mapping, subject, required, heading, user):
creds = get_creds(user)
service = build('script', 'v1', credentials=creds)
required = dumps(required)
questions_mapping = dumps(questions_mapping)
request = {"function": "create_form", "parameters": [{"required": required, "heading": heading, "question_mapping": questions_mapping, "subject": subject}], "devMode": "true"}
response = service.scripts().run(body=request, scriptId=API_ID).execute()
return response

def get_creds(user):
creds = None
flag = 0
if FormAuth.objects.filter(user=user).exists():
data = FormAuth.objects.get(user=user).creds
creds = pickle.loads(data)
flag = 1
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
if(flag == 1):
token = FormAuth.objects.get(user=user)
token.creds = pickle.dumps(creds)
token.save()
else:
data = FormAuth(user=user, creds=pickle.dumps(creds))
data.save()
return creds
6 changes: 5 additions & 1 deletion searchapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def __str__(self):
return self.subject_name


class FormAuth(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True)
creds = models.BinaryField(max_length=800)

class Questions(models.Model):
ONE = 1
TWO = 2
Expand Down Expand Up @@ -108,7 +112,7 @@ class SubjectSplit(models.Model):
question_type = models.IntegerField(
choices=Questions.QUESTION_TYPE_CHOICES, null=True, default=Questions.TEXT)
total_questions = models.IntegerField(default=0)
questions_to_attempt = models.IntegerField(default=0)
questions_to_attempt = models.PositiveIntegerField(default=0)

def __str__(self):
return self.name
Expand Down
Loading