Giter Site home page Giter Site logo

companion-backend's Introduction

Companion backend

Develop

Python version

3.9

Create virtual environment

python -m venv .venv

Activate virtual environment

.venv\Scripts\activate

Install dependencies

python -m pip install --upgrade pip
pip install -r requirements.txt

Migrate database

python manage.py migrate

Run development server

python manage.py runserver

Debug

For Visual studio code

Just press F5 (Config is inside .vscode/)

For other editors

Please contribute if you know how.

Config environment variables

Default variables should work out of the box already, but in case you want to customize, here is how.

Add .env file and write your custom variables to it.

Available variables and their data type can be seen in companion/settings.py:

env = environ.Env(
    ...  # Variables are listed here
)

Browsable API

You can login to the browsable API and explore it to help with development.

Collect static

python manage.py collectstatic

Browse!

Go to this URL in your brower. (You may need to register new user and then login if you haven't already)

http://localhost:8000/

Setup background tasks

NOTE This is only needed if you develop features involving background tasks, like sending email, .etc

Rabbitmq

Setup with docker
docker run -d --name rabbitmq -p 5672:5672 rabbitmq
Create user and vhost

Exec into container

docker exec -it rabbitmq bash

Create user, vhost

rabbitmqctl add_user companion_user companion_password
rabbitmqctl add_vhost companion_vhost
rabbitmqctl set_permissions -p companion_vhost companion_user ".*" ".*" ".*"

Celery

Start the worker process
celery --app companion worker --loglevel INFO --pool solo

NOTE Every time you make changes to a task, celery worker should be restarted.

Sending emails

In development, emails are not actually sent, but instead saved to temp/sent_emails. You can inspect this directory to test email sending features.

Test

Run unittests

python manage.py test

Run coverage

coverage run

Get coverage report as html

coverage html

Your report is inside htmlcov directory.

Translations

Make messages

Run this command to collect locale messages to locale/<locale name>/LC_MESSAGES/django.po of each app.

python manage.py makemessages --locale <locale name>

Compile locale messages to .mo files.

python manage.py compilemessages --locale <locale name> --ignore .venv

Production

Database

In development, sqlite is used as DB. In production, if you want to use a different DB, remember to install the appropriate DB client.

Example: for MySQL, you need pip install mysqlclient

Browsable API

In production, only staff users can access browsable API.

To create staff user:

python manage.py createsuperuser

companion-backend's People

Contributors

rockstarr-programmerr avatar

Watchers

James Cloos avatar  avatar

companion-backend's Issues

Logging: downgrade "invalid HTTP_HOST header" logs from ERROR to WARNING

Reason: Lots of these errors come from malicious scripts on the internet trying to exploit some vulnerabilities. We should downgrade them to WARNING so that admins are not bombarded with emails about these errors.

We don't expect any request whose HTTP_HOST header is our IP address anyway.

Settle expenses feature update

  • POST settle: finish event, after that, no more transactions can be made, and list of actions will be created
  • Read, Update actions
  • Event: add is_settled column

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.