summaryrefslogtreecommitdiff
path: root/website
diff options
context:
space:
mode:
authorprashantsinalkar2019-09-24 16:33:59 +0530
committerprashantsinalkar2019-09-24 16:33:59 +0530
commit57a530976f576cf9b3493b9994e46242ae39b4b9 (patch)
tree3ae39634d83cd1d80773735970fd0bec08ad85e5 /website
parentaf9bfbb8e3b1f08e0df80402cf69d40ff5baf7b4 (diff)
downloadR_on_Cloud_Web_Interface-57a530976f576cf9b3493b9994e46242ae39b4b9.tar.gz
R_on_Cloud_Web_Interface-57a530976f576cf9b3493b9994e46242ae39b4b9.tar.bz2
R_on_Cloud_Web_Interface-57a530976f576cf9b3493b9994e46242ae39b4b9.zip
updated code for flask api
Diffstat (limited to 'website')
-rw-r--r--website/query.py7
-rw-r--r--website/static/website/js/cloud.js10
-rw-r--r--website/static/website/templates/index.html6
-rw-r--r--website/views.py107
4 files changed, 19 insertions, 111 deletions
diff --git a/website/query.py b/website/query.py
index 06e37a7..23f4cea 100644
--- a/website/query.py
+++ b/website/query.py
@@ -48,13 +48,6 @@ GET_TBC_EXAMPLE_FILE_SQL = """
WHERE tcef.filetype = 'S' AND tcef.example_id = %s
"""
-
-# GET_TBC_EXAMPLE_FILE_VIEW_SQL = """
-# SELECT id, views_count FROM textbook_companion_example_views
-# WHERE example_id = %s
-# """
-
-
GET_TBC_CONTRIBUTOR_DETAILS_SQL = """
SELECT preference.id,
proposal.full_name as proposal_full_name,
diff --git a/website/static/website/js/cloud.js b/website/static/website/js/cloud.js
index 6c874fa..ab71be1 100644
--- a/website/static/website/js/cloud.js
+++ b/website/static/website/js/cloud.js
@@ -661,7 +661,7 @@ $(document.body).ready(function() {
token: $(
"[name='csrfmiddlewaretoken']"
).val(),
- session_id: $("#session_id").val() || 0,
+ user_id: $("#user_id").val() || 0,
R_file_id: $("#R_file_id").val() || 0,
code: editor.getValue(),
book_id: $("#books").val() || 0,
@@ -675,6 +675,10 @@ $(document.body).ready(function() {
"Execute");
ajax_loader('clear');
result.setValue(data.output);
+ if (data.error.length != 0)
+ {
+ alert(data.error);
+ }
if(data.graph_exist){
$plot = $("<img>");
$plot.attr({
@@ -1044,8 +1048,8 @@ function doSubmit(){
if(fileSelect.files && fileSelect.files.length == 1){
var file = fileSelect.files[0]
formData.set("file", file , file.name);
- var session_id = document.getElementById("session_id");
- formData.set("session_id", session_id.value)
+ var user_id = document.getElementById("user_id");
+ formData.set("user_id", user_id.value)
// Http Request
var request = new XMLHttpRequest();
request.open('POST', api_url_upload);
diff --git a/website/static/website/templates/index.html b/website/static/website/templates/index.html
index 3020c83..a095bc3 100644
--- a/website/static/website/templates/index.html
+++ b/website/static/website/templates/index.html
@@ -216,10 +216,10 @@
</div>
<textarea id="code" class="form-control" rows="5" placeholder="Write a new code or select existing from above category..." wrap="hard">{{ code }}</textarea>
<br>
- <input type="hidden" id="session_id" name="session_id" value="{{ session_id }}">
+ <input type="hidden" id="user_id" name="user_id" value="{{ user_id }}">
<a id="execute" class="btn btn-dark text-white"><span id="execute-inner">Execute</span></a>
<!-- Trigger the modal with a button -->
- <button id="uploaddataset" type="button" class="btn btn-dark text-white" data-toggle="modal" data-target="#uploaddatasetModal">Upload Dataset</button>
+ <!-- <button id="uploaddataset" type="button" class="btn btn-dark text-white" data-toggle="modal" data-target="#uploaddatasetModal">Upload Dataset</button> -->
<button id="reset" type="button" class="btn btn-dark text-white" data-dismiss="modal">Reset</button>
<!-- Modal -->
@@ -267,7 +267,7 @@
</div>
<textarea id="result" class="form-control" rows="5"></textarea>
<br>
- <a id="bug" href="" class="btn btn-dark text-white float-right" data-toggle="modal" data-target="#bug_form_wrapper">Report bug / Give Feedback</a>
+ <!-- <a id="bug" href="" class="btn btn-dark text-white float-right" data-toggle="modal" data-target="#bug_form_wrapper">Report bug / Give Feedback</a> -->
</div>
</div>
</div>
diff --git a/website/views.py b/website/views.py
index 6948f13..d5eca56 100644
--- a/website/views.py
+++ b/website/views.py
@@ -3,10 +3,7 @@ from django.http import HttpResponse
from django.template import loader
import requests
import uuid
-<<<<<<< HEAD
-=======
from R_on_Cloud.config import (API_URL_UPLOAD)
->>>>>>> fixed conflict
from website.models import *
from django.db.models import Q
import json as simplejson
@@ -14,10 +11,7 @@ from . import utils
from django.db import connections
from .query import *
-<<<<<<< HEAD
-=======
->>>>>>> fixed conflict
def dictfetchall(cursor):
"Return all rows from a cursor as a dict"
columns = [col[0] for col in cursor.description]
@@ -26,10 +20,7 @@ def dictfetchall(cursor):
for row in cursor.fetchall()
]
-<<<<<<< HEAD
-=======
->>>>>>> fixed conflict
def catg(cat_id, all_cat):
if all_cat is False:
category = TextbookCompanionCategoryList.objects.using('r')\
@@ -58,15 +49,10 @@ def get_subcategories(maincat_id):
return subcategories
-<<<<<<< HEAD
-=======
-
->>>>>>> fixed conflict
def get_books(category_id):
with connections['r'].cursor() as cursor:
cursor.execute(GET_TBC_PREFERENCE_FROM_CATEGORY_ID_SQL,
-<<<<<<< HEAD
params=[category_id])
books = dictfetchall(cursor)
return books
@@ -77,30 +63,15 @@ def get_chapters(book_id):
cursor.execute(GET_TBC_CHAPTER_SQL,
params=[book_id])
chapters = dictfetchall(cursor)
-=======
- params=[category_id])
- books = dictfetchall(cursor)
- return books
-def get_chapters(book_id):
- with connections['r'].cursor() as cursor:
- cursor.execute(GET_TBC_CHAPTER_SQL,
- params=[book_id])
- chapters = dictfetchall(cursor)
->>>>>>> fixed conflict
return chapters
def get_examples(chapter_id):
with connections['r'].cursor() as cursor:
cursor.execute(GET_TBC_EXAMPLE_SQL,
-<<<<<<< HEAD
params=[chapter_id])
examples = dictfetchall(cursor)
-=======
- params=[chapter_id])
- examples = dictfetchall(cursor)
->>>>>>> fixed conflict
return examples
@@ -114,37 +85,20 @@ def get_revisions(example_id):
def get_code(file_path, commit_sha):
-<<<<<<< HEAD
+
code = utils.get_file(file_path, commit_sha, main_repo=True)
-=======
- code= utils.get_file(file_path, commit_sha, main_repo=True)
->>>>>>> fixed conflict
return code
def index(request):
context = {}
-<<<<<<< HEAD
-=======
- session_id = uuid.uuid4()
- context['session_id'] = str(session_id)
+ user_id = uuid.uuid4()
+ context['user_id'] = str(user_id)
context['api_url_upload'] = API_URL_UPLOAD
- request.session['session_id'] = str(session_id)
->>>>>>> fixed conflict
+ request.session['user_id'] = str(user_id)
book_id = request.GET.get('book_id')
user = request.user
- # if not user.is_anonymous():
- # social = user.social_auth.get(provider='google-oauth2')
- # url = 'https://www.googleapis.com/plus/v1/people/me'
- # params = {'access_token': social.extra_data['access_token']}
- # # r = requests.get(url, params=params)
- # # print(r.content)
-
- # context = {
- # 'user': user
- # }
-
if not (request.GET.get('eid') or request.GET.get('book_id')):
catg_all = catg(None, all_cat=True)
subcatg_all = subcatg(None, all_subcat=True)
@@ -178,16 +132,10 @@ def index(request):
context['revisions'] = get_revisions(example_id)
with connections['r'].cursor() as cursor:
cursor.execute(GET_TBC_EXAMPLE_R_CLOUD_COMMENT_SQL,
-<<<<<<< HEAD
params=[example_id])
review = cursor.fetchone()
review_url = "https://r.fossee.in/cloud_comments/" + \
str(example_id)
-=======
- params=[example_id])
- review = cursor.fetchone()
- review_url = "https://r.fossee.in/cloud_comments/" + str(example_id)
->>>>>>> fixed conflict
context['review'] = review[0]
context['review_url'] = review_url
@@ -202,6 +150,7 @@ def index(request):
session_code = get_code(
request.session['filepath'], commit_sha)
context['code'] = session_code
+ context['user_id'] = request.session['user_id']
template = loader.get_template('index.html')
return HttpResponse(template.render(context, request))
elif book_id:
@@ -275,26 +224,19 @@ def index(request):
try:
with connections['r'].cursor() as cursor:
cursor.execute(GET_TBC_EXAMPLE_R_CLOUD_COMMENT_SQL,
-<<<<<<< HEAD
params=[eid])
-=======
- params=[eid])
->>>>>>> fixed conflict
+
review = cursor.fetchone()
review_url = "https://r.fossee.in/cloud_comments/" + str(eid)
with connections['r'].cursor() as cursor:
cursor.execute(GET_TBC_EXAMPLE_CHAPTER_ID_SQL,
-<<<<<<< HEAD
params=[eid])
-=======
- params=[eid])
->>>>>>> fixed conflict
+
chapter_id = cursor.fetchone()
with connections['r'].cursor() as cursor:
cursor.execute(GET_TBC_CHAPTER_DETAIL_SQL,
-<<<<<<< HEAD
params=[chapter_id[0]])
chapters = dictfetchall(cursor)
@@ -305,42 +247,24 @@ def index(request):
with connections['r'].cursor() as cursor:
cursor.execute(GET_TBC_PREFERENCE_DETAIL_CATEGORY_SQL,
params=[preference_id[0]])
-=======
- params=[chapter_id[0]])
- chapters = dictfetchall(cursor)
-
- with connections['r'].cursor() as cursor:
- cursor.execute(GET_TBC_CHAPTER_PREFERENCE_ID_SQL,
- params=[chapter_id[0]])
- preference_id = cursor.fetchone()
- with connections['r'].cursor() as cursor:
- cursor.execute(GET_TBC_PREFERENCE_DETAIL_CATEGORY_SQL,
- params=[preference_id[0]])
->>>>>>> fixed conflict
books_detail = cursor.fetchone()
books = get_books(books_detail[1])
maincat_id = books_detail[0]
subcat_id = books_detail[1]
-<<<<<<< HEAD
with connections['r'].cursor() as cursor:
cursor.execute(GET_TBC_EXAMPLE_FILE_SQL,
params=[eid])
-=======
with connections['r'].cursor() as cursor:
cursor.execute(GET_TBC_EXAMPLE_FILE_SQL,
- params=[eid])
->>>>>>> fixed conflict
+ params=[eid])
+
example_file = cursor.fetchone()
example_file_filepath = example_file[4] + '/' + example_file[5]
with connections['r'].cursor() as cursor:
cursor.execute(GET_TBC_EXAMPLE_VIEW_SQL,
-<<<<<<< HEAD
params=[eid])
-=======
- params=[eid])
->>>>>>> fixed conflict
ex_views_count = cursor.fetchone()
request.session['maincat_id'] = maincat_id
@@ -399,10 +323,7 @@ def index(request):
template = loader.get_template('index.html')
return HttpResponse(template.render(context, request))
-<<<<<<< HEAD
-=======
->>>>>>> fixed conflict
def update_view_count(request):
ex_id = request.GET.get('ex_id')
@@ -411,7 +332,6 @@ def update_view_count(request):
Example_chapter_id = cursor.fetchone()
with connections['r'].cursor() as cursor:
cursor.execute(INSERT_TBC_EXAMPLE_VIEW_SQL,
-<<<<<<< HEAD
params=[ex_id, Example_chapter_id[0]])
with connections['r'].cursor() as cursor:
cursor.execute(UPDATE_TBC_EXAMPLE_VIEW_SQL,
@@ -419,15 +339,6 @@ def update_view_count(request):
with connections['r'].cursor() as cursor:
cursor.execute(GET_TBC_EXAMPLE_VIEW_SQL,
params=[ex_id])
-=======
- params=[ex_id,Example_chapter_id[0]])
- with connections['r'].cursor() as cursor:
- cursor.execute(UPDATE_TBC_EXAMPLE_VIEW_SQL,
- params=[ex_id])
- with connections['r'].cursor() as cursor:
- cursor.execute(GET_TBC_EXAMPLE_VIEW_SQL,
- params=[ex_id])
->>>>>>> fixed conflict
Example_views_count = cursor.fetchone()
data = Example_views_count[0]
return HttpResponse(simplejson.dumps(data),