|
@@ -1,155 +1,163 @@
|
|
|
Django Hackathon Starter
|
|
|
------------------------
|
|
|
|
|
|
-## What is Django Hackathon Starter
|
|
|
+A boilerplate application for Django web applications.
|
|
|
|
|
|
-> Django Hackathon Starter aims to be a project which will aggegrate data from several APIs, producing a RESTful API which can be consumed by a client (also intended to be built).
|
|
|
+If you've attented hackathons, you already know how much time can be wasted figuring out what language to pick, which web framework to choose, which APIs to incorporate, and figuring out OAuth authentication. Django Hackathon Starter aims to provide these features out of the box, allowing the team to save hours of time getting these pieces together.
|
|
|
|
|
|
-Our deployment can be found [here](http://django-hackathon-starter.herokuapp.com/hackathon/).
|
|
|
+Even if you are not using this for a hackathon, Django Hackathon Starter is sure to save any developer hours or even days of development time and can serve as a learning guide.
|
|
|
|
|
|
-## Running this project
|
|
|
+Basic Authentication / OAuth Signin
|
|
|
|
|
|
-In order to run this project, do the following:
|
|
|
+
|
|
|
|
|
|
- # Install the requirements
|
|
|
- pip install -r requirements.txt
|
|
|
+API Examples
|
|
|
|
|
|
- # Perform database migrations
|
|
|
- python manage.py migrate
|
|
|
+
|
|
|
|
|
|
- # Run the server
|
|
|
- python manage.py runserver
|
|
|
+Twitter Example
|
|
|
|
|
|
-## Front End dependencies
|
|
|
+
|
|
|
|
|
|
-This project relies on Bower for all front end libraries, to avoid pushing up large libraries such as `jQuery` and `Bootstrap`. **Under no circumstance should any front-end libraries manually be pushed up to the repository.** To install `bower`, you will need to install `npm`, which now comes bundled with `node.js`. To install `npm`, simply install [node as follows](https://github.com/joyent/node/wiki/installing-node.js-via-package-manager).
|
|
|
|
|
|
-First, install `bower`:
|
|
|
+Getting Started
|
|
|
+---------------
|
|
|
+To get up and running, simply do the following:
|
|
|
|
|
|
+ git clone https://github.com/DrkSephy/django-hackathon-starter.git
|
|
|
+ cd django-hackathon-starter
|
|
|
+ # Install the requirements
|
|
|
+ pip install -r requirements.txt
|
|
|
+ # Install bower
|
|
|
npm install -g bower
|
|
|
-
|
|
|
-Then:
|
|
|
-
|
|
|
- # In the same directory as requirements.txt
|
|
|
bower install
|
|
|
-
|
|
|
-This will download and extract all the packages listed within `bower.json`.
|
|
|
-
|
|
|
-Then:
|
|
|
-
|
|
|
- # move bower_components into static folder
|
|
|
mv bower_components/ hackathon_starter/hackathon/static
|
|
|
+ # Perform database migrations
|
|
|
+ python manage.py makemigrations
|
|
|
+ python manage.py migrate
|
|
|
|
|
|
-To install the front-end dependencies for the AngularJS client, do the following:
|
|
|
-
|
|
|
- cd public
|
|
|
- bower install
|
|
|
- # Rename bower_components folder to vendor
|
|
|
- mv bower_components/ vendor/
|
|
|
-
|
|
|
-
|
|
|
-## Testing
|
|
|
-
|
|
|
-This project aims to be as close to 100% tested as possible. For a good guide to testing using Python and `Mock`, `Nosetests` and `Unittests` libraries, please [read here](http://docs.python-guide.org/en/latest/writing/tests/).
|
|
|
-
|
|
|
-To run the tests:
|
|
|
-
|
|
|
- hackthon-starter $ python manage.py test hackathon/unittests/
|
|
|
-
|
|
|
-## Code evaluation
|
|
|
-
|
|
|
-In order to write clean code with a consistent style guide, we'll be using `Pylint` to maintain our code. Pylint will display a ton of messages regarding things that should be fixed.
|
|
|
-
|
|
|
-This project will use the camel-case naming convention for variables and function names, which PyLint complains about by default. As such, I have created a pylint configuration file within the home directory of the project (the same directory which contains `ionic`, `angular`, `hackathon_starter`.) To run pylint while supplying a pylint configuration file:
|
|
|
-
|
|
|
- pylint --rcfile path/to/pylintrcfile/.pylintrc hackathon_starter/hackathon/scripts/github.py
|
|
|
-
|
|
|
-Where you can substitute `github.py` with the script you'd like to evaluate.
|
|
|
-
|
|
|
-
|
|
|
-## RESTful endpoints
|
|
|
-
|
|
|
-Using the `Django REST framework`, the current RESTful endpoints exist:
|
|
|
-
|
|
|
- http://127.0.0.1:8000/hackathon/snippets/
|
|
|
-
|
|
|
-The list will appear empty at first, since the database model `Snippets` will be empty. To populate it with some sample data, run the following:
|
|
|
-
|
|
|
- python manage.py shell
|
|
|
- from hackathon.models import Snippet
|
|
|
- from hackathon.serializers import SnippetSerializer
|
|
|
- from rest_framework.renderers import JSONRenderer
|
|
|
- from rest_framework.parsers import JSONParser
|
|
|
-
|
|
|
- snippet = Snippet(code='foo = "bar"\n')
|
|
|
- snippet.save()
|
|
|
-
|
|
|
- snippet = Snippet(code='print "hello, world"\n')
|
|
|
- snippet.save()
|
|
|
-
|
|
|
-The above will open the Django shell, and allow you to create objects and save them to the database. If you then navigate to the URL above, you will see the JSON output of the database model, `Snippet`.
|
|
|
-
|
|
|
-## Django JSON Response Endpoints
|
|
|
-
|
|
|
-As of `Django 1.7x`, there is a new method called `JsonResponse` which allows the user to send JSON data to a URL which makes it available to be consumed by any client. The following endpoints exist:
|
|
|
-
|
|
|
-* `http://127.0.0.1:8000/hackathon/steamDiscountedGames/`: JSON output containing steam discounts data
|
|
|
-* `http://127.0.0.1:8000/hackathon/instagramUser/`: JSON output containing data from an Instagram user through OAuth
|
|
|
-* `http://127.0.0.1:8000/hackathon/githubUser/`: JSON output containing data from a Github User
|
|
|
-
|
|
|
-## AngularJS Client
|
|
|
-
|
|
|
-As of `April 11th, 2015`, there is now a sample AngularJS client which pulls data from the Django sample API endpoint: `http://127.0.0.1:8000/hackathon/snippets/`. To test it, do the following:
|
|
|
-
|
|
|
-* Within the `angular/` directory, run `python -m SimpleHTTPServer 80`. You may need `sudo` on your respective Operating System.
|
|
|
-* Navigate to: `http://localhost/#/snippets`. Here you will see whatever content was stored within the database model, `Snippet`. If nothing shows up, go back to the `RESTful endpoints` step to populate your database with some `Snippet` objects.
|
|
|
-
|
|
|
-The following other links are available on the AngularJS Client:
|
|
|
-
|
|
|
-* `http://localhost/#/githubUser`: Pulls JSON response for Github data from Django
|
|
|
-* `http://localhost/#/steamSales`: Pulls JSON response for Steam sales data from Django
|
|
|
-
|
|
|
-## Ionic Client
|
|
|
-
|
|
|
-As of `April 11th, 2015`, there is now a sample Ionic application which works on iOS. This application pulls data from the Django sample API endpoint: `http://127.0.0.1:8000/hackathon/snippets/`. In order to successfully run this project, you must do the following:
|
|
|
-
|
|
|
- # Make sure django-hackathon-starter is running
|
|
|
- python manage.py runserver
|
|
|
-
|
|
|
- # Install cordova and ionic
|
|
|
- # On a Mac, you'll need to use sudo
|
|
|
- npm install -g cordova ionic
|
|
|
-
|
|
|
- cd ionic
|
|
|
-
|
|
|
- # Add support for the iOS platform
|
|
|
- ionic platform add ios
|
|
|
-
|
|
|
- # Build the project
|
|
|
- ionic build ios
|
|
|
-
|
|
|
-Running the final command, `ionic build ios` will generate an `.xcodeproj` file within `platforms/ionic`. You can open it and then run it, which you should then see a list of all the `Snippet` objects from the Django Hackathon Starter database.
|
|
|
-
|
|
|
-You can also test the project in the browser by doing the following:
|
|
|
-
|
|
|
- cd ionic
|
|
|
- ionic serve
|
|
|
-
|
|
|
-Running `ionic serve` will automatically open up your web browser and run the application.
|
|
|
-
|
|
|
-
|
|
|
-## Building the documentation
|
|
|
-
|
|
|
-In order to build the documentation for this project:
|
|
|
-
|
|
|
- $ cd hackathon_starter
|
|
|
- $ make html
|
|
|
-
|
|
|
-The output is stored within `_build/html`. Open up `index.html` to view the documentation.
|
|
|
-
|
|
|
-## Contributors
|
|
|
-
|
|
|
-* David Leonard
|
|
|
-* Eswari Swarna
|
|
|
-* Marco Quezada
|
|
|
-* Wan Kim Mok
|
|
|
+**NOTE**: We highly recommend creating a [Virtual Environment](http://docs.python-guide.org/en/latest/dev/virtualenvs/). Python Virtual Environments allow developers to work in isolated sandboxes and to create separation between python packages installed via pip.
|
|
|
+
|
|
|
+**NOTE**: To get you up and running quickly, we have provided dummy API keys for use. We highly recommend setting up your own keys and replacing them within `settings.py`.
|
|
|
+
|
|
|
+
|
|
|
+Getting API Keys
|
|
|
+----------------
|
|
|
+# YELP #
|
|
|
+
|
|
|
+1. Register an account on [Yelp.com](http://www.yelp.com/).
|
|
|
+2. Visit the [Yelp for developers page](https://www.yelp.com/developers/manage_api_keys).
|
|
|
+3. You will obtain the following: `CONSUMER KEY`, `CONSUMER SECRET`, `TOKEN`, `TOKEN_SECRET`.
|
|
|
+4. Within `settings.py`, add the following:
|
|
|
+ * `YELP_CONSUMER_KEY` = `Yelp Consumer Key`
|
|
|
+ * `YELP_CONSUMER_SECRET` = `Yelp Consumer Secret`
|
|
|
+ * `YELP_TOKEN` = `Yelp Token`
|
|
|
+ * `YELP_TOKEN_SECRET` = `Yelp Token Secret`
|
|
|
+
|
|
|
+# MEETUP #
|
|
|
+
|
|
|
+1. Register an account on [Meetup.com](http://www.meetup.com/).
|
|
|
+2. Visit [Meetup OAuth Consumers page](https://secure.meetup.com/meetup_api/oauth_consumers/).
|
|
|
+ * Enter a project name for the `consumer name` field.
|
|
|
+ * For `redirect url` field, enter: `http://127.0.0.1:8000/hackathon/`.
|
|
|
+3. Within `settings.py`, add the following:
|
|
|
+ * `MEETUP_CONSUMER_KEY` = `Meetup key`
|
|
|
+ * `MEETUP_CONSUMER_SECRET` = `Meetup secret key`
|
|
|
+
|
|
|
+# TWILIO
|
|
|
+
|
|
|
+1. Register an account on [Twilio.com](https://www.twilio.com/).
|
|
|
+2. Get your [Twilio Number](https://www.twilio.com/user/account/phone-numbers/incoming).
|
|
|
+3. [Setup the numbers](https://www.twilio.com/user/account/phone-numbers/incoming) you want to be able to send messages to.
|
|
|
+4. Grab your `account_sid` and `auth_token` [here](https://www.twilio.com/user/account/voice-messaging).
|
|
|
+5. Within `scripts/twilioapi.py`:
|
|
|
+ * Replace `account_sid` with your own Twilio `account_sid`.
|
|
|
+ * Replace `auth_token` with your own Twilio `auth_token`.
|
|
|
+
|
|
|
+# GITHUB #
|
|
|
+
|
|
|
+1. Register an account on [Github.com](http://www.github.com/).
|
|
|
+2. Visit [Github developer applications page](https://github.com/settings/developers).
|
|
|
+3. Click on **Register new application**.
|
|
|
+ * Enter `Application name` and `Homepage URL` field.
|
|
|
+ * For `redirect url` field, enter: `http://127.0.0.1:8000/hackathon/`.
|
|
|
+4. Click **Register application**.
|
|
|
+5. Within `settings.py`, add the following:
|
|
|
+ * `GITHUB_CLIENT_ID` = `Github-client-id`
|
|
|
+ * `GITHUB_CLIENT_SECRET` = `Github-client-secret`
|
|
|
+
|
|
|
+# TWITTER #
|
|
|
+
|
|
|
+1. Register an account on [Twitter.com](http://www.twitter.com/).
|
|
|
+2. Visit [Twitter application management page](https://apps.twitter.com/).
|
|
|
+3. Click on **Create New App**.
|
|
|
+ * Enter `Application name`, `Description`, and `Website` field.
|
|
|
+ * For `Callback URL` field, enter: `http://127.0.0.1:8000/hackathon/`.
|
|
|
+4. Click **Create your Twitter application**.
|
|
|
+5. Go to the **Permissions** tab.
|
|
|
+6. Under *Access*, select **Read and Write* type.
|
|
|
+7. Go to **Keys and Access Tokens ** tab.
|
|
|
+8. Under *Your Access Token*, click on **Create my access token** to generate access tokens.
|
|
|
+9. Within `settings.py`, add the following:
|
|
|
+ * `TWITTER_CONSUMER_KEY` = `Twitter-consumer-key`
|
|
|
+ * `TWITTER_CONSUMER_SECRET` = `Twitter-consumer-secret`
|
|
|
+ * `TWITTER_ACCESS_TOKEN` = `Twitter-access-token`
|
|
|
+ * `TWITTER_ACCESS_TOKEN_SECRET` = `Twitter-access-token-secret`
|
|
|
+
|
|
|
+# INSTAGRAM #
|
|
|
+
|
|
|
+1. Register an account on [Instagram.com](http://www.instagram.com/).
|
|
|
+2. Visit [Instagram manage clients page](https://instagram.com/developer/clients/manage/).
|
|
|
+3. Click on **Register a New Client**.
|
|
|
+ * Enter `Application name`, `Description`, and `Website URL` field.
|
|
|
+ * For `Redirect URI` field, enter: `http://127.0.0.1:8000/hackathon/`.
|
|
|
+4. Within `settings.py`, add the following:
|
|
|
+ * `INSTAGRAM_CLIENT_ID` = `Instagram-client-id`
|
|
|
+ * `INSTAGRAM_CLIENT_SECRET` = `Instagram-client-secret`
|
|
|
+
|
|
|
+# LINKEDIN #
|
|
|
+
|
|
|
+1. Register an account on [Linkedin.com](http://www.linkedin.com/).
|
|
|
+2. Visit [Linkedin developer Network page](https://www.linkedin.com/secure/developer).
|
|
|
+3. Click on **Add New Application**.
|
|
|
+ * Enter `Company Info`, `Application Info`, and `Contact Info` section.
|
|
|
+ * Under `OAuth User Agreement` section, select scopes needed.
|
|
|
+ * For `OAuth 2.0 Redirect URLs` field, enter: `http://127.0.0.1:8000/hackathon/`.
|
|
|
+4. Click **Add Application**.
|
|
|
+5. Within `settings.py`, add the following:
|
|
|
+ * `LINKEDIN_CLIENT_ID` = `Linkedin-client-id`
|
|
|
+ * `LINKEDIN_CLIENT_SECRET` = `Linkedin-client-secret`
|
|
|
+
|
|
|
+# FACEBOOK #
|
|
|
+
|
|
|
+1. Register an account on [Facebook.com](http://www.facebook.com.com/).
|
|
|
+2. Visit [Facebook Developer Network page](https://developers.facebook.com/).
|
|
|
+3. After logging in, Click on **My Apps** and then on **Add a New App+**.
|
|
|
+ * Choose Website as the platform and add the **name** for your project.
|
|
|
+ * Click on **Create New Facebook APP ID** and choose the **Category** of your application
|
|
|
+ * Click **Create App ID**
|
|
|
+4. After the captcha, scroll down past the quick start and add http://localhost:8000/'.
|
|
|
+5. Within your `views.py` add the **App ID** in `yourappid` underneath the view for your facebook application.
|
|
|
+
|
|
|
+# STEAM #
|
|
|
+
|
|
|
+1. Register an account on [Steam](https://store.steampowered.com/join/).
|
|
|
+2. Visit [Steam Community developers page](https://steamcommunity.com/login/home/?goto=%2Fdev%2Fapikey).
|
|
|
+3. After logging in, add the **Domain Name** as the name of your application and **key** is shown.
|
|
|
+4. Within your `views.py` add the **Key** in `key` underneath the view for your steam application.
|
|
|
+
|
|
|
+# NY TIMES #
|
|
|
+
|
|
|
+1. Register an account on [NY Times Developer Network](http://developer.nytimes.com/docs).
|
|
|
+2. Click on [Register](https://myaccount.nytimes.com/register).
|
|
|
+3. After logging in, click on **APIs** (http://developer.nytimes.com/apps/register)
|
|
|
+ *Write in the **Name** of your application and click each **sub-API** that you will use.
|
|
|
+ * Agree to the **Terms of Service** and click on **Register Application**
|
|
|
+4. Within your `settings.py` add the following:
|
|
|
+ * `POPAPIKEY` = `Most Popular API`
|
|
|
+ * `TOPAPIKEY` = `Top Stories API`
|
|
|
+
|
|
|
+# QUANDL #
|
|
|
+1. Register an account on [Quandl](https://www.quandl.com/)
|
|
|
+2. After logging in, click on **Me** and then **Account settings** to find the API key.
|
|
|
+3. Within your `settings.py`add `QUANDLAPIKEY` = `Key`
|