Bagtrekkin is a full-stack application involving both hardware and software.
This project takes place in a Lean Startup course at the University Federal of Pernambuco.
The application uses Django 1.8 as main framework, PyJade as template rendering tool, Tastypie as API resource provider, UiKit as front-end style and PostgreSQL as database server.
The whole server-side application is currently hosted on Heroku. It uses web
Dynos to run Procfile
in order to start Gunicorn
server.
By following those steps, you'll install the application development environment
- Clone Git repository:
$ git clone git@github.com:goujonpa/bagtrekkin.git
- Create a
virtualenv
to host the application: You may needsudo
to installvirtualenv
globally
# install virtualenv tool manager via pip
$ [sudo] pip install virtualenv
# create a new virtualenv folder called venv
$ virtualenv venv
# activate your virtualenv!
$ source venv/bin/activate
- Install application dependencies via pip:
/!\ Be sure to have your virtualenv activated /!\
This is stipulated by
(venv)
in front of your terminal prompt.
(venv) $ pip install -r requirements.txt
(venv) $ pip install -r requirements-dev.txt
Currently both Tastypie and PyJade are installed from master development branch. When both package will be released in pip. Requirements must be edited.
Read more about Tastypie and PyJade support on Django 1.8.
- Install postgres database server On Debian based distributions, install from package manager:
$ apt-get install postgresql-9.4
On Mac OS X, install from Homebrew, MacPorts or use Postgres.app:
$ brew install postgresql
Initiate a fresh database granted for current user:
$ initdb -D /usr/local/var/postgres
Launch postgresql:
$ pg_ctl -D /usr/local/var/postgres start
Create a new user named bagtrekkin with a password prompted:
$ createuser -W bagtrekkin
Create a dedicated database for bagtrakkin user:
$ createdb -O bagtrekkin -E UTF8 bagtrekkin
We can now try a connection to be sure all is properly setup:
$ psql -U bagtrekkin bagtrekkin
- Setup your local environment variables
- Create a
.env
file in the same folder asmanage.py
:
cat >> .env <<EOF
WEB_CONCURRENCY=2
DEBUG=TRUE
ALLOWED_HOSTS=localhost
DATABASE_URL=postgres://bagtrekkin:<your_db_password>@localhost:5432/bagtrekkin
SECRET_KEY=<your_secret_key>
EOF
-
Replace
<your_secret_key>
with one generated, for instance, using MiniWebTool. -
Replace
<your_db_password>
with the password you setup for postgres bagtrekkin user.
- Run Migrations to create and feed your database:
(venv) $ python manage.py migrate
- Test if everything runs well:
(venv) $ python manage.py runserver
You are now fully operational to join the developer team :)
/!\ Please read carefully How to Contribute /!\
In order to get closer to production environment, you can run python server the same way as Heroku actually do: using foreman
.
Simply install globally Ruby foreman gem
:
$ gem install -g foreman
And run server:
$ foreman start
The first thing you need to do is create a new user using Sign Up
form. It is also an Employee
. Once your account is created, you basically want to be a superuser in order to access django admin interface.
Enter in python shell
(venv) $ python manage.py shell
Import the corresponding module
>>> from django.contrib.auth.models import User
Get your user instance from the models
>>> foo = User.objects.get(username = '<your_username>')
Set your is_staff
property to True
>>> foo.is_staff = True
Set your is_superuser
property to True
>>> foo.is_superuser = True
Save your changes
>>> foo.save()
Verification : load again your user instance from the models
>>> foo = User.objects.get(username = '<your_username')
Check that your changes are applied (next instruction should return True
)
>>> foo.is_superuser
You will have to do the same to be superuser on heroku. Repeat the procedure above.
You can know update your local environment variables by adding:
cat >> .env <<EOF
API_URL=bagtrekkin.herokuapp.com
API_USER=<your_username>
API_KEY=<your_api_key>
EOF
-
Replace
<your_api_key>
with the one generated by the application when you'll create your account. -
Replace
<your_username>
with the one used when you'll create your account.
This configuration is used by rfid_reader.py
micro-client.
-
arduino
folder contains hardware code currently not being used by application server-side (i.e. Hosted on Heroku) -
bagtrekkin
folder contains the server-side application.-
migrations
folder contains all migrations run usingmigrate
management command. If you want to create new migrations, please read carefully How to write Migrations. -
static
folder contains all static resources (i.e. js, css, fonts and img files used by the application). -
templates
folder contains all templates written in Jade and live time compiled using PyJade.
-
-
documentation
folder contains documentation about the project