-
-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade Django to 1.11 [One Step at a time] #135
Changes from 3 commits
60f3ff4
475216b
7665c80
db9d9ba
6b6f25e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,17 +1,12 @@ | ||||||
from django.http import HttpResponse, Http404 | ||||||
from django.shortcuts import render_to_response, redirect | ||||||
from django.template.loader import render_to_string | ||||||
from django.utils import simplejson | ||||||
from django import forms | ||||||
import django | ||||||
|
||||||
from google.appengine.api import users | ||||||
from google.appengine.runtime import DeadlineExceededError | ||||||
|
||||||
import sympy | ||||||
from logic.utils import Eval | ||||||
from logic.logic import SymPyGamma, mathjax_latex | ||||||
from logic.resultsets import get_card, find_result_set | ||||||
|
||||||
import settings | ||||||
import models | ||||||
|
@@ -127,6 +122,7 @@ | |||||
]), | ||||||
] | ||||||
|
||||||
|
||||||
class MobileTextInput(forms.widgets.TextInput): | ||||||
def render(self, name, value, attrs=None): | ||||||
if attrs is None: | ||||||
|
@@ -135,9 +131,11 @@ def render(self, name, value, attrs=None): | |||||
attrs['autocapitalize'] = 'off' | ||||||
return super(MobileTextInput, self).render(name, value, attrs) | ||||||
|
||||||
|
||||||
class SearchForm(forms.Form): | ||||||
i = forms.CharField(required=False, widget=MobileTextInput()) | ||||||
|
||||||
|
||||||
def authenticate(view): | ||||||
def _wrapper(request, **kwargs): | ||||||
user = users.get_current_user() | ||||||
|
@@ -157,6 +155,7 @@ def _wrapper(request, **kwargs): | |||||
return template, params | ||||||
return _wrapper | ||||||
|
||||||
|
||||||
def app_version(view): | ||||||
def _wrapper(request, **kwargs): | ||||||
result = view(request, **kwargs) | ||||||
|
@@ -173,6 +172,7 @@ def _wrapper(request, **kwargs): | |||||
return result | ||||||
return _wrapper | ||||||
|
||||||
|
||||||
@app_version | ||||||
@authenticate | ||||||
def index(request, user): | ||||||
|
@@ -279,19 +279,19 @@ def eval_card(request, card_name): | |||||
except ValueError as e: | ||||||
return HttpResponse(json.dumps({ | ||||||
'error': e.message | ||||||
}), mimetype="application/json") | ||||||
}), content_type="application/json") | ||||||
except DeadlineExceededError: | ||||||
return HttpResponse(json.dumps({ | ||||||
'error': 'Computation timed out.' | ||||||
}), mimetype="application/json") | ||||||
}), content_type="application/json") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think its better to use JsonResponse. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Beyond the scope, See this |
||||||
except: | ||||||
trace = traceback.format_exc(5) | ||||||
return HttpResponse(json.dumps({ | ||||||
'error': ('There was an error in Gamma. For reference' | ||||||
'the last five traceback entries are: ' + trace) | ||||||
}), mimetype="application/json") | ||||||
}), content_type="application/json") | ||||||
|
||||||
return HttpResponse(json.dumps(result), mimetype="application/json") | ||||||
return HttpResponse(json.dumps(result), content_type="application/json") | ||||||
|
||||||
def get_card_info(request, card_name): | ||||||
g, variable, expression, _ = _process_card(request, card_name) | ||||||
|
@@ -301,19 +301,19 @@ def get_card_info(request, card_name): | |||||
except ValueError as e: | ||||||
return HttpResponse(json.dumps({ | ||||||
'error': e.message | ||||||
}), mimetype="application/json") | ||||||
}), content_type="application/json") | ||||||
except DeadlineExceededError: | ||||||
return HttpResponse(json.dumps({ | ||||||
'error': 'Computation timed out.' | ||||||
}), mimetype="application/json") | ||||||
}), content_type="application/json") | ||||||
except: | ||||||
trace = traceback.format_exc(5) | ||||||
return HttpResponse(json.dumps({ | ||||||
'error': ('There was an error in Gamma. For reference' | ||||||
'the last five traceback entries are: ' + trace) | ||||||
}), mimetype="application/json") | ||||||
}), content_type="application/json") | ||||||
|
||||||
return HttpResponse(json.dumps(result), mimetype="application/json") | ||||||
return HttpResponse(json.dumps(result), content_type="application/json") | ||||||
|
||||||
def get_card_full(request, card_name): | ||||||
g, variable, expression, parameters = _process_card(request, card_name) | ||||||
|
@@ -339,10 +339,10 @@ def get_card_full(request, card_name): | |||||
'error': e.message | ||||||
}, | ||||||
'input': expression | ||||||
}), mimetype="text/html") | ||||||
}), content_type="text/html") | ||||||
except DeadlineExceededError: | ||||||
return HttpResponse('Computation timed out.', | ||||||
mimetype="text/html") | ||||||
content_type="text/html") | ||||||
except: | ||||||
trace = traceback.format_exc(5) | ||||||
return HttpResponse(render_to_string('card.html', { | ||||||
|
@@ -352,14 +352,15 @@ def get_card_full(request, card_name): | |||||
'error': trace | ||||||
}, | ||||||
'input': expression | ||||||
}), mimetype="text/html") | ||||||
}), content_type="text/html") | ||||||
|
||||||
response = HttpResponse(html, mimetype="text/html") | ||||||
response = HttpResponse(html, content_type="text/html") | ||||||
response['Access-Control-Allow-Origin'] = '*' | ||||||
response['Access-Control-Allow-Headers'] = 'Content-Type, X-Requested-With' | ||||||
|
||||||
return response | ||||||
|
||||||
|
||||||
def remove_query(request, qid): | ||||||
user = users.get_current_user() | ||||||
|
||||||
|
@@ -381,12 +382,14 @@ def remove_query(request, qid): | |||||
'message': 'Not logged in or invalid user.' | ||||||
} | ||||||
|
||||||
return HttpResponse(json.dumps(response), mimetype='application/json') | ||||||
return HttpResponse(json.dumps(response), content_type='application/json') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Beyond the scope, See this |
||||||
|
||||||
|
||||||
@app_version | ||||||
def view_404(request): | ||||||
return ("404.html", {}) | ||||||
|
||||||
|
||||||
@app_version | ||||||
def view_500(request): | ||||||
return ("500.html", {}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
django==1.3 | ||
django==1.11 | ||
numpy==1.6.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
# root_dir points to this directory (that contains settings.py): | ||
import os | ||
root_dir = os.path.dirname(os.path.abspath(__file__)) | ||
ROOT_DIR = os.path.abspath(os.path.dirname(__file__)) | ||
|
||
DEBUG = False | ||
TEMPLATE_DEBUG = DEBUG | ||
|
@@ -54,13 +54,6 @@ | |
# Make this unique, and don't share it with anybody. | ||
SECRET_KEY = '4v-c#usznhix_^np%w)4yr@dlit*4^47u@uph3xr2gh@7(&z$u' | ||
|
||
# List of callables that know how to import templates from various sources. | ||
TEMPLATE_LOADERS = ( | ||
'django.template.loaders.filesystem.load_template_source', | ||
'django.template.loaders.app_directories.load_template_source', | ||
# 'django.template.loaders.eggs.load_template_source', | ||
) | ||
|
||
MIDDLEWARE_CLASSES = ( | ||
'google.appengine.ext.ndb.django_middleware.NdbDjangoMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
|
@@ -70,9 +63,21 @@ | |
|
||
ROOT_URLCONF = 'urls' | ||
|
||
TEMPLATE_DIRS = ( | ||
root_dir + "/templates", | ||
) | ||
TEMPLATES = [{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [os.path.join(ROOT_DIR, 'templates')], | ||
'OPTIONS': { | ||
'loaders': [ | ||
('django.template.loaders.cached.Loader', [ | ||
'django.template.loaders.filesystem.Loader', | ||
'django.template.loaders.app_directories.Loader', | ||
]), | ||
], | ||
}, | ||
}] | ||
|
||
|
||
ALLOWED_HOSTS = ['127.0.0.1', 'localhost'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allowed hosts should contain the domain 'https://sympygamma.com' for production. |
||
|
||
INSTALLED_APPS = ( | ||
#'django.contrib.auth', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think numpy should be updated to latest.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beyond the scope, See this