Skip to content
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

Merged
merged 5 commits into from
Apr 12, 2020
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
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ install: "pip install -r requirements.txt"

before_script:
- cd ..
- wget https://storage.googleapis.com/appengine-sdks/deprecated/195/google_appengine_1.9.5.zip -nv
- unzip -q google_appengine_1.9.5.zip
- wget https://storage.googleapis.com/appengine-sdks/featured/google_appengine_1.9.90.zip -nv
- unzip -q google_appengine_1.9.90.zip
- export SDK_LOCATION="$(pwd)/google_appengine"
- cd $TRAVIS_BUILD_DIR
- git fetch --tags
Expand Down
4 changes: 3 additions & 1 deletion app.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ handlers:

libraries:
- name: django
version: "1.3"
version: "1.11"
- name: numpy
version: "1.6.1"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
version: "1.6.1"
version: "1.18.1"

I think numpy should be updated to latest.

Copy link
Member Author

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

- name: ssl
version: "latest"
39 changes: 21 additions & 18 deletions app/views.py
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
Expand Down Expand Up @@ -127,6 +122,7 @@
]),
]


class MobileTextInput(forms.widgets.TextInput):
def render(self, name, value, attrs=None):
if attrs is None:
Expand All @@ -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()
Expand All @@ -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)
Expand All @@ -173,6 +172,7 @@ def _wrapper(request, **kwargs):
return result
return _wrapper


@app_version
@authenticate
def index(request, user):
Expand Down Expand Up @@ -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")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its better to use JsonResponse.

Copy link
Member Author

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

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)
Expand All @@ -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)
Expand All @@ -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', {
Expand All @@ -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()

Expand All @@ -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')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return HttpResponse(json.dumps(response), content_type='application/json')
return JsonResponse(response)

Copy link
Member Author

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



@app_version
def view_404(request):
return ("404.html", {})


@app_version
def view_500(request):
return ("500.html", {})
5 changes: 3 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Must set this env var *before* importing any part of Django
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi
from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

application = django.core.handlers.wsgi.WSGIHandler()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
django==1.3
django==1.11
numpy==1.6.1
33 changes: 22 additions & 11 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand All @@ -70,9 +63,27 @@

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',
'.sympygamma.com',
'.sympy.org',
'.appspot.com'
]

INSTALLED_APPS = (
#'django.contrib.auth',
Expand Down
2 changes: 1 addition & 1 deletion templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
</p>

<p>
&copy; 2013 SymPy Development Team. This project is
&copy; 2013-2020 SymPy Development Team. This project is
open-source: <a href="https://github.com/sympy/sympy_gamma/">
SymPy Gamma on Github</a>.
</p>
Expand Down
29 changes: 15 additions & 14 deletions urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.conf.urls.defaults import *
from django.conf.urls import url

from app import views

# Uncomment the next two lines to enable the admin:
# from django.contrib import admin
Expand All @@ -7,23 +9,22 @@
import os.path
p = os.path.join(os.path.dirname(__file__), 'media/')

urlpatterns = patterns(
'',
urlpatterns = [
# Example:
# (r'^notebook/', include('notebook.foo.urls')),
(r'^$', 'app.views.index'),
url(r'^$', views.index),

(r'^input/', 'app.views.input'),
(r'^about/$', 'app.views.about'),
(r'^random', 'app.views.random_example'),
url(r'^input/', views.input),
url(r'^about/$', views.about),
url(r'^random', views.random_example),

(r'user/remove/(?P<qid>.*)$', 'app.views.remove_query'),
url(r'user/remove/(?P<qid>.*)$', views.remove_query),

(r'card/(?P<card_name>\w*)$', 'app.views.eval_card'),
url(r'card/(?P<card_name>\w*)$', views.eval_card),

(r'card_info/(?P<card_name>\w*)$', 'app.views.get_card_info'),
url(r'card_info/(?P<card_name>\w*)$', views.get_card_info),

(r'card_full/(?P<card_name>\w*)$', 'app.views.get_card_full')
url(r'card_full/(?P<card_name>\w*)$', views.get_card_full)


# Uncomment the admin/doc line below and add 'django.contrib.admindocs'
Expand All @@ -32,7 +33,7 @@

# Uncomment the next line to enable the admin:
# (r'^admin/(.*)', admin.site.root),
)
]

handler404 = 'app.views.view_404'
handler500 = 'app.views.view_500'
handler404 = views.view_404
handler500 = views.view_500