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

Django 1.11 support #327

Merged
merged 6 commits into from
Sep 10, 2018
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
10 changes: 2 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,11 @@ language: python
python:
- '2.7'
install:
- pip install -r requirements/testing.txt
- pip install coveralls
env:
- DJANGO_SETTINGS_MODULE=paying_for_college.config.settings.standalone
before_script:
- python manage.py migrate
- python manage.py loaddata test_fixture.json
- npm install -g gulp-cli
- pip install coveralls tox
script:
- coverage run manage.py test > /dev/null
- npm config set package-lock false
- tox
- python2.7 setup.py bdist_wheel
- ls dist/*
- gulp lint --travis
Expand Down
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ We follow the [Semantic Versioning 2.0.0](http://semver.org/) format.

## Unreleased

### Added
-

### Changed
- Convert browserify config to webpack.
- Remove unused dependencies.
- Update ESLint config to version 5.
- Fix linter errors.
- Convert to ES6 syntax.
- Add Django 1.11 support.

### Removed
-
Expand Down
55 changes: 13 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,43 +58,36 @@ The app is set up to run as a component of CFPB's website, [consumerfinance.gov]

### Search
The app has a simple API for searching schools by name or nickname. The endpoint, to which you can append a querystring, is:
```
/understanding-your-financial-aid-offer/api/search-schools.json
```

Elasticsearch needs to be running locally for search to work.
Your launch command will vary depending on which version of Elasticsearch is installed.

For 2.x versions installed on a mac with homebrew, this is an example command:

```
elasticsearch --path.conf=/Users/[MAC USERNAME]/homebrew/opt/elasticsearch/config/elasticsearch.yml
/understanding-your-financial-aid-offer/api/search-schools.json
```

1.x versions use a `--config=` param instead of `path.conf=`

An example query is http://localhost:8000/understanding-your-financial-aid-offer/api/search-schools.json?q=harvard.

With elasticsearch running, you can now build an index of college data:
Elasticsearch needs to be running locally for search to work.

With Elasticsearch running, and with college data loaded into your Django database using
the script above, you can now build a search index using this command:

```
./manage.py rebuild_index
./manage.py update_index -r paying_for_college
```

Now you should get a json response when hitting the search API. You can search by school name or nickname, such as:
Now you should get a JSON response when hitting the search API. You can search by school name or nickname, such as:

http://localhost:8000/paying-for-college2/understanding-your-financial-aid-offer/api/search-schools.json?q=jayhawks
http://localhost:8000/understanding-your-financial-aid-offer/api/search-schools.json?q=jayhawks

### Running tests

#### Python Tests
You can run python tests from the project root with this command:
```bash
./pytest.sh
```

Python tests for this project can be run using
[Tox](https://tox.readthedocs.io/en/latest/) with the `tox` command.

#### Javascript Tests
To run JavaScript unit tests:
To run JavaScript unit tests and check for security vulnerabilities in
Node packages (requires a [Snyk](https://snyk.io/) login):

```bash
npm test
Expand Down Expand Up @@ -137,28 +130,6 @@ apache-jmeter-3.0/bin/jmeter.sh -t college-costs/test/load_testing/Offer.jmx -Js

The corresponding `Offer.csv` in `test/load_testing` specified the parameters being used for testing. The order and name of each column is specified in the JMX file under CSV Offer.

<!-- INCLUDE IN setup.sh
- Build the front-end requirements and the JavaScript files.

```bash
npm install
grunt Build
```

## Configuration

If the software is configurable, describe it in detail, either here or in other documentation to which you link.

## Usage

Show users how to use the software.
Be specific.
Use appropriate formatting when showing code snippets.

## How to test the software

If the software includes automated tests, detail how to run those tests. -->

## Getting involved

If you find a bug or see a way to improve the project, we'd love to hear from you. Add an issue, or fork the project and send us a pull request with your suggested changes.
Expand Down
4 changes: 2 additions & 2 deletions paying_for_college/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,8 @@ class Worksheet(models.Model):

def print_vals(obj, val_list=False, val_dict=False, noprint=False):
"""inspect a Django db object"""
keylist = sorted([key for key in obj._meta.get_all_field_names()],
key=lambda s: s.lower())
keylist = sorted(f.name.lower() for f in obj._meta.get_fields())

if val_list:
values = []
for key in keylist:
Expand Down
54 changes: 26 additions & 28 deletions paying_for_college/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.utils import timezone
from django.core.urlresolvers import reverse
from django.views.generic import View, TemplateView
from django.shortcuts import get_object_or_404, render_to_response
from django.shortcuts import get_object_or_404, render
from django.core.mail import send_mail
from django.template import RequestContext
from django.template.loader import get_template
Expand Down Expand Up @@ -135,17 +135,17 @@ def get(self, request, test=False):
warning = ''
OID = ''
if not request.GET:
return render_to_response('worksheet.html',
{'data_js': "0",
'school': school,
'schoolData': school_data,
'program': program,
'programData': program_data,
'oid': OID,
'base_template': BASE_TEMPLATE,
'warning': warning,
'url_root': URL_ROOT},
context_instance=RequestContext(request))
return render(request, 'worksheet.html', {
'data_js': "0",
'school': school,
'schoolData': school_data,
'program': program,
'programData': program_data,
'oid': OID,
'base_template': BASE_TEMPLATE,
'warning': warning,
'url_root': URL_ROOT,
})
if 'oid' in request.GET and request.GET['oid']:
OID = request.GET['oid']
else:
Expand Down Expand Up @@ -179,17 +179,17 @@ def get(self, request, test=False):
warning = IPED_ERROR
else:
warning = IPED_ERROR
return render_to_response('worksheet.html',
{'data_js': "0",
'school': school,
'schoolData': school_data,
'program': program,
'programData': program_data,
'oid': OID,
'base_template': BASE_TEMPLATE,
'warning': warning,
'url_root': URL_ROOT},
context_instance=RequestContext(request))
return render(request, 'worksheet.html', {
'data_js': "0",
'school': school,
'schoolData': school_data,
'program': program,
'programData': program_data,
'oid': OID,
'base_template': BASE_TEMPLATE,
'warning': warning,
'url_root': URL_ROOT,
})


class LandingView(TemplateView):
Expand Down Expand Up @@ -222,15 +222,13 @@ def get_context_data(self):
def post(self, request):
form = self.form
if form.is_valid():
base_template = BASE_TEMPLATE
feedback = Feedback(
message=form.cleaned_data['message'][:2000],
url=form.cleaned_data['referrer'].replace('#info-right', ''))
feedback.save()
return render_to_response(
"feedback_thanks.html",
locals(),
context_instance=RequestContext(request))
return render(request, 'feedback_thanks.html', {
'base_template': BASE_TEMPLATE,
})
else:
return HttpResponseBadRequest("Invalid form")

Expand Down
6 changes: 0 additions & 6 deletions pytest.sh

This file was deleted.

9 changes: 0 additions & 9 deletions requirements/base.txt

This file was deleted.

5 changes: 0 additions & 5 deletions requirements/dev.txt

This file was deleted.

14 changes: 0 additions & 14 deletions requirements/docs.txt

This file was deleted.

5 changes: 0 additions & 5 deletions requirements/testing.txt

This file was deleted.

52 changes: 50 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,49 @@
from setuptools import setup, find_packages


setup_requires=[
'cfgov-setup==1.2',
'setuptools-git-version==1.0.3',
]


install_requires = [
'Django>=1.8,<1.12',
'django-haystack==2.7.0',
'djangorestframework==3.6.4',
'elasticsearch==2.4.1',
'PyYAML==3.11',
'python-dateutil==2.2',
'requests==2.7.0',
'Unipath==1.1',
]


docs_extras = [
'Markdown==2.3.1',
'PyYAML==3.10',
'backports-abc==0.4',
'certifi==2016.8.2',
'click==3.3',
'django-livereload==1.2',
'livereload==2.3.2',
'mkDOCter==1.0.3',
'mkdocs==0.15.3',
'mkdocs-bootstrap==0.1.1',
'mkdocs-bootswatch==0.1.0',
'singledispatch==3.4.0.3',
'six==1.9.0',
'tornado==4.1',
]


testing_extras = [
'coverage==4.2',
'dj-database-url==0.4.2',
'mock==2.0.0',
]


def read_file(filename):
"""Read a file into a string"""
path = os.path.abspath(os.path.dirname(__file__))
Expand Down Expand Up @@ -55,6 +98,11 @@ def read_file(filename):
],
long_description=read_file('README.md'),
zip_safe=False,
setup_requires=['cfgov-setup==1.2', 'setuptools-git-version==1.0.3'],
frontend_build_script='setup.sh'
setup_requires=setup_requires,
install_requires=install_requires,
frontend_build_script='setup.sh',
extras_require={
'docs': docs_extras,
'testing': testing_extras,
}
)
2 changes: 1 addition & 1 deletion standalone_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install(){
dbsetup(){
source .env
echo 'Loading requirements...'
pip install -r requirements/testing.txt
pip install -e '.[docs,testing]'
if [ -f $DATABASE ]; then
echo 'Removing existing database...'
rm -f $DATABASE
Expand Down
14 changes: 14 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tox]
skipsdist=True
envlist=dj{18,111}

[testenv]
install_command=pip install -e ".[testing]" -U {opts} {packages}
commands=
coverage erase
coverage run manage.py test {posargs}
coverage report --show-missing --skip-covered

deps=
dj18: Django>=1.8,<1.9
dj111: Django>=1.11,<1.12