GithubHelp home page GithubHelp logo

alexengelhardt / hired-gun Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 712 KB

A webapp for freelancers to track clients, projects, work sessions, and invoices

Python 67.94% HTML 29.09% CSS 2.54% JavaScript 0.43%

hired-gun's Introduction

hired-gun

A webapp for freelancers to track clients, projects, work sessions, and invoices


How to try this out locally

  • git clone this repository
  • Run python3 manage.py migrate
  • Load some example data into the database by running:
python3 manage.py loaddata projects/fixtures/auth.json
python3 manage.py loaddata projects/fixtures/Client.json 
python3 manage.py loaddata projects/fixtures/Project.json 
python3 manage.py loaddata projects/fixtures/Session.json 
  • Run python3 manage.py runserver to start your local development webserver
  • Browse to http://127.0.0.1:8000
  • Login as user test with password test
    • The user admin with password adminadmin exists too.
  • Go view/edit/delete some data, and build a few reports!

Django notes

Best order for creating a new app:

  • Determine apps and models
    • Try to predict the final models and relations as best as possible
    • Find out how to best split it in apps for now
    • Start with only one app here, though
  • Create Models
    • Determine your models, fields, and relationships
    • Create the models.py
  • admin.py: Create admin views
    • To login to the admin backend and verify:
      • Update settings.py: add ProjectsConfig to INSTALLED_APPS
      • makemigrations projects
      • migrate
  • Fixtures
    • From the admin backend, add sample data
    • export all models to JSON fixtures: python3 manage.py dumpdata --indent=4 projects.Client > projects/fixtures/Client.json (etc. for Project and Session)
  • Frontend:
    • For the beginning, stick with one ListView and one DetailView per model
    • urls.py
    • views.py
    • HTML templates
    • Try these views.
    • If they work, determine what other views you want
      • that's probably "create, update, delete", for now
  • Tests
    • Now start writing tests for the existing code
    • From now on, go TDD and write tests first
  • Static files
    • Start with a CSS and a logo or background image
  • Users
    • Create a login functionality

How to deploy on AWS: Apache2 and mod_wsgi

Deploying on ElasticBeanstalk as described in this official AWS doc didn't work for me out-of-the-box. I wanted to "do it myself" as much as possible, for the learning effect and the higher amount of control.

Do it without virtualenv, without nginx proxy etc. first. Only after that works, introduce the "simplifying" additional steps in order to always be able to isolate the source of failure when something doesn't work.

References:

sudo apt-get update
sudo apt install apache2 apache2-dev virtualenv python3-dev python3-pip
sudo service apache2 restart
sudo ln -sf /usr/bin/python3 /usr/bin/python
  • Apache2 auto-starts on install. You should be able to browse to your instance's public IP now. If not, try sudo service apache2 status. Also check your instance's security group if the machine really is accessible from outside.
  • Run:
sudo chown -R www-data:www-data /var/www
sudo chmod -R g+w /var/www
sudo usermod -a -G www-data ubuntu

# Log out, log in again

mkdir -p /var/www/apps/
cd /var/www/apps
git clone https://github.com/AlexEngelhardt/hired-gun.git
cd hired-gun
virtualenv -p /usr/bin/python3 venv
source venv/bin/activate
pip install -r HiredGun/requirements.txt
# Install wsgi from pip, not via 'apt install libapache2-mod-wsgi':
# https://stackoverflow.com/questions/41005030

# TODO maybe do this from *outside* the virtualenvironment ?
sudo -H pip install mod_wsgi
  • Add this to the bottom of /etc/apache2/apache2.conf (replacing the IP with your actual public IP):
WSGIScriptAlias / /var/www/apps/hired-gun/HiredGun/HiredGun/wsgi.py
WSGIPythonHome /var/www/apps/hired-gun/HiredGun/venv
WSGIPythonPath /var/www/apps/hired-gun/HiredGun

WSGIDaemonProcess 18.196.87.1 python-home=/var/www/apps/hired-gun/HiredGun/venv$
WSGIProcessGroup 18.196.87.1

<Directory /var/www/apps/hired-gun/HiredGun/HiredGun>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
  • Become root, activate your virtualenvironment, then run:
# service apache2 stop  # free port 80
mod_wsgi-express start-server HiredGun/wsgi.py --port 8080 --user www-data --group www-data
  • From local, do sudo apt install lynx and then lynx 127.0.0.1:8080 - this should work!
  • Browse to your public IP at port :8000 and verify it's starting to look like your app (the static files don't work yet)

How to deploy on AWS: nginx and gunicorn / uwsgi

References:


Deployment on PythonAnywhere.com

  • Is cheaper than a dedicated AWS instance
  • But: For the beginning I want to learn all intricacies, and that works best when I have full control. So start on AWS, and once that works, you can switch to PythonAnywhere (or any other managed service, like Heroku).
  • Get this running, in any case - regardless of whether you'll actually use it here later. It helps because it currently throws an error that you should fix (is it INSTALLED_APPS?).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.