Skip to content

Commit

Permalink
management command to download static libraries locally, update README
Browse files Browse the repository at this point in the history
  • Loading branch information
zackmdavis committed Apr 12, 2015
1 parent dfac4bb commit 4c68901
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ where highlighted substrings overlap. character-by-character feedback

## Development Setup

Requires Python 3.
Developed on Python 3.4 (earlier Python 3s may or may not work).

* Clone the repository: `git clone [email protected]:zackmdavis/Finetooth.git`

Expand All @@ -26,16 +26,20 @@ Requires Python 3.

* Create a file called `.development` (the presence of this file is used to determine that we should use development rather than production-like Django settings): `touch .development`

* Configure static files!

* If you want to serve static JavaScripts and CSS locally, download them with `./manage.py download_statics`.

* If you want to use CDNs, export a truthy "NONLOCAL_STATIC_LIBS" environment variable: `export NONLOCAL_STATIC_LIBS=1`.

* Set up the database: `./manage.py migrate`

* Run the tests!
* *Optional*: run the tests maybe!

* Django tests: `./manage.py test core`
* Django tests: `./manage.py test`

* JavaScript tests:

- Get local copies of jQuery and Underscore: `wget http://code.jquery.com/jquery-2.1.1.min.js http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.js http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.7.0/underscore-min.map -P static/libs/`

- `jasmine`

- Visit *http://localhost:8888/* in your favorite browser!
Expand Down
33 changes: 33 additions & 0 deletions core/management/commands/download_statics.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
from urllib.request import urlretrieve

from django.core.management.base import BaseCommand, CommandError

our_statics = {
'jquery-2.1.1.min.js': "https://code.jquery.com/jquery-2.1.1.min.js",
'underscore-min.js': (
"https://cdnjs.cloudflare.com/ajax/libs/"
"underscore.js/1.7.0/underscore-min.js"),
os.path.join('css', "bootstrap.min.css"): (
"https://netdna.bootstrapcdn.com/bootstrap/3.2.0/css/"
"bootstrap.min.css"),
os.path.join('fonts', "glyphicons-halflings-regular.woff"): (
"https://netdna.bootstrapcdn.com/bootstrap/3.2.0/fonts/"
"glyphicons-halflings-regular.woff"),
os.path.join('fonts', "glyphicons-halflings-regular.ttf"): (
"https://netdna.bootstrapcdn.com/bootstrap/3.2.0/fonts/"
"glyphicons-halflings-regular.ttf"),
'words': "http://www.cs.duke.edu/~ola/ap/linuxwords"
}

class Command(BaseCommand):

def handle(self, *args, **options):
for static, upstream in our_statics.items():
destination = os.path.join('static', 'libs', static)
if not os.path.exists(destination):
self.stdout.write("downloading {} from {} ...".format(
destination, upstream))
urlretrieve(upstream, destination)
else:
self.stdout.write("we already have {}".format(static))
4 changes: 2 additions & 2 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@

STATICFILES_DIRS = ('static',)

SERVE_STATIC_LIBS_LOCALLY = (not os.environ.get('NONLOCAL_STATIC_LIBS')
or ENVIRONMENT is Environment.development)
SERVE_STATIC_LIBS_LOCALLY = (ENVIRONMENT is Environment.development and
not os.environ.get('NONLOCAL_STATIC_LIBS'))

STATIC_URL = '/static/'

Expand Down

0 comments on commit 4c68901

Please sign in to comment.