system-pri/backend
2023-01-16 21:59:49 +01:00
..
app update and add functional tests for students view 2023-01-16 21:59:49 +01:00
config add points for terms in group view for coordinator 2022-12-15 22:32:01 +01:00
fonts update endpoint of downloading examination schedule in pdf format for coordinator view and fix font issues for polish characters 2022-11-17 20:33:20 +01:00
migrations update Group model - add grades field, add set grade for group endpoint for coordinator view 2023-01-16 01:12:15 +01:00
tests update and add functional tests for students view 2023-01-16 21:59:49 +01:00
.dockerignore add docker 2022-05-23 14:23:22 +02:00
.env.example add cors 2022-05-17 16:33:34 +02:00
.gitignore Move backend code to separate folder 2022-05-16 22:42:08 +02:00
Dockerfile add year group and change logic of endpoints v2 2022-11-12 16:18:07 +01:00
Dockerfile.nginx.prod add docker configuration for production 2022-11-18 00:20:50 +01:00
Dockerfile.prod Update prod deployment config 2023-01-09 19:35:41 +00:00
main.py add black, isort and flake8 package, format code, fix examination schedule and enrollments functionality, add chairman of committee field for TermOfDefence entity 2023-01-14 17:38:03 +01:00
nginx.conf add docker configuration for production 2022-11-18 00:20:50 +01:00
pyproject.toml add black, isort and flake8 package, format code, fix examination schedule and enrollments functionality, add chairman of committee field for TermOfDefence entity 2023-01-14 17:38:03 +01:00
pytest.ini add unit tests for backend 2023-01-04 22:51:58 +01:00
Readme.md add black, isort and flake8 package, format code, fix examination schedule and enrollments functionality, add chairman of committee field for TermOfDefence entity 2023-01-14 17:38:03 +01:00
requirements.txt add black, isort and flake8 package, format code, fix examination schedule and enrollments functionality, add chairman of committee field for TermOfDefence entity 2023-01-14 17:38:03 +01:00
setup.cfg add black, isort and flake8 package, format code, fix examination schedule and enrollments functionality, add chairman of committee field for TermOfDefence entity 2023-01-14 17:38:03 +01:00

Installation

Python 3.8 version is required.

python3 --version

Create virtual environment and install packages

virtualenv venv
source ./venv/bin/activate
pip install -r requirements.txt

Usage

Create .env file and fill with similar data like .env.example. Then run application:

flask run

Testing

Run tests

pytest

Run all tests in specific python module

pytest ./tests/unit_tests/test_file.py

Run one test inside of python module

pytest ./tests/unit_tests/test_file.py::test_function_name

Format code:

black path/to/file.py
isort path/to/file.py
flake8

Useful commands:

Add new package

pip install NAME_OF_PACKAGE

Save new added package to requirements

pip freeze > requirements.txt

Flask commands:

Create the application structure directories

flask startapp NAME_OF_APP

Above command create package structure:
Create serializer in schemas.py file:

from marshmallow import Schema, fields

class ExampleSchema(Schema):
    id = fields.Integer()
    name = fields.Str()


Create models in models.py file:

from ..dependencies import db

class Example(db.Model):
    __tablename__ = "examples"

    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(255), unique=True)


Create api routes in routes.py file. You only have to register blueprint in app/__init__.py.

from flask import Blueprint, make_response, jsonify, Response


bp = Blueprint("{name}", __name__, url_prefix="/{name}")


@bp.route("/", methods=["GET"])
def index() -> Response:
    return make_response(jsonify({{"hello": "{name}"}}), 200)


Print all your routes

flask routes

Create migration, but first you have to create model

flask db migrate

Apply your changes to database, use after migration command

flask db upgrade

If you want back changes in your databases, use below command

flask db downgrade

Create empty migration, you can write manually migration here.

flask db revision