first commit

This commit is contained in:
BartekSynapsi 2021-12-04 21:41:57 +01:00
commit b99a6e4193
39 changed files with 36241 additions and 0 deletions

143
.gitignore vendored Normal file
View File

@ -0,0 +1,143 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv/
env/
venv/
ENV/
env.bak/
venv.bak/
.idea/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
#VS Code
.vscode

36
Makefile Normal file
View File

@ -0,0 +1,36 @@
COMPOSE_FILE_PATH := -f docker-compose.yml
help: ## Show this help.
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
build: ## Build developer docker images
docker-compose build
up: ## Run developer docker images
docker-compose $(COMPOSE_FILE_PATH) up -d
django-shell: ## Run django shell in developer container
docker-compose $(COMPOSE_FILE_PATH) run backend python manage.py shell
stop: ## Stop developer docker images
@docker-compose stop
restart:
@make -s stop
@make -s up
install: ## Install requrirements packages
pip install pip-tools
pip install -r requirements.txt -r dev-requirements.txt
(cd frontend && npm install)
lint: ## Run linters
isort backend/
black backend/
(cd frontend && npm run lint --fix)
install-oracle: ## install oracle db (maybe in use in future)
mkdir oracle
git clone https://github.com/oracle/docker-images.git oracle
wget https://download.oracle.com/otn-pub/otn_software/db-express/oracle-database-xe-18c-1.0-1.x86_64.rpm -P oracle
cp oracle/oracle-database-xe-18c-1.0-1.x86_64.rpm oracle/OracleDatabase/SingleInstance/dockerfiles/18.4.0
./oracle/OracleDatabase/SingleInstance/dockerfiles/buildContainerImage.sh -x -v 18.4.0

87
README.md Normal file
View File

@ -0,0 +1,87 @@
# Systemy rozmyte
## Frontend URL
```
http://localhost:8080/
```
## Backend URL
```
http://localhost:8000/
```
## Run in Docker
You need to install Docker and Docker-compose
### Running in docker
To build:
```
make build
```
To run:
```
make up
```
## Locally
### Requirements
* Python 3.10
* PostgreSQL
* Node v15.13.0
Create virtual environment
```sh
python3 -m venv venv
. venv/bin/activate
```
Install requirements:
```sh
make install
```
Create .env file in backend directory & copy variables:
```sh
SECRET_KEY=SECRET_KEY
DEBUG=1
ALLOWED_HOSTS=localhost 127.0.0.1
SQL_HOST=localhost
SQL_PORT=5432
POSTGRES_PASSWORD=sysrozm
POSTGRES_DB=sysrozm
POSTGRES_USER=sysrozm
```
### Create database:
```sh
sudo -u postgres psql
```
```sql
CREATE DATABASE sysrozm;
CREATE USER sysrozm WITH PASSWORD 'sysrozm';
GRANT ALL PRIVILEGES ON DATABASE sysrozm TO sysrozm;
```
Allow user to create databases:
```sql
ALTER USER sysrozm CREATEDB;
```
## Run
```sh
(cd backend && python3 manage.py runserver)
(cd frontend && npm run serve)
```
## Install pre-commit
1. Run command in project directory
```
make install-pre-commit
```
## Run linters
1. Run command in project directory
```
make lint
```

View File

159
backend/backend/settings.py Normal file
View File

@ -0,0 +1,159 @@
"""
Django settings for backend project.
Generated by 'django-admin startproject' using Django 2.2.10.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.2/ref/settings/
"""
import os
from pathlib import Path
import environ
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
env = environ.Env()
if os.path.exists(env_path := os.path.join(BASE_DIR, "dev.env")):
env.read_env(env_path)
if os.path.exists(env_path := os.path.join(BASE_DIR, ".env")):
env.read_env(env_path)
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env("SECRET_KEY")
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env.bool("DEBUG")
ALLOWED_HOSTS = env("ALLOWED_HOSTS").split()
# Application definition
INSTALLED_APPS = [
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
# packages
"rest_framework",
"corsheaders",
"django_filters",
# apps
]
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
# CORS Middleware
"corsheaders.middleware.CorsMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = "backend.urls"
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
WSGI_APPLICATION = "backend.wsgi.application"
# Database
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql_psycopg2",
"NAME": env("POSTGRES_DB"),
"USER": env("POSTGRES_USER"),
"PASSWORD": env("POSTGRES_PASSWORD"),
"HOST": env("SQL_HOST"),
"PORT": env("SQL_PORT"),
}
}
# Password validation
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_ROOT = BASE_DIR / "static"
STATIC_URL = "/static/"
STATICFILES_DIRS = (BASE_DIR / "staticfiles",)
MEDIA_ROOT = BASE_DIR / "media"
MEDIA_URL = "/media/"
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
# CORS
CORS_ALLOWED_ORIGINS = env(
"ALLOWED_ORIGINS",
default="http://localhost:3000",
).split()

21
backend/backend/urls.py Normal file
View File

@ -0,0 +1,21 @@
"""backend URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/2.2/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
urlpatterns = [
path("admin/", admin.site.urls),
]

16
backend/backend/wsgi.py Normal file
View File

@ -0,0 +1,16 @@
"""
WSGI config for backend project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")
application = get_wsgi_application()

21
backend/manage.py Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "backend.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == "__main__":
main()

4
dev-requirements.txt Normal file
View File

@ -0,0 +1,4 @@
black==21.10b0
isort==5.9.3
pre-commit==2.15.0
pytest-django==4.4.0

5
dev.db.env Normal file
View File

@ -0,0 +1,5 @@
SQL_HOST=db
SQL_PORT=5432
POSTGRES_PASSWORD=sysrozm
POSTGRES_DB=sysrozm
POSTGRES_USER=sysrozm

3
dev.env Normal file
View File

@ -0,0 +1,3 @@
SECRET_KEY=SECRET_KEY
DEBUG=1
ALLOWED_HOSTS=localhost 127.0.0.1

40
docker-compose.yml Normal file
View File

@ -0,0 +1,40 @@
version: "3"
services:
backend:
build:
context: .
dockerfile: docker/backend.Dockerfile
ports:
- 8000:8000
command: python manage.py runserver 0.0.0.0:8000
entrypoint: /opt/backend-entrypoint.sh
env_file:
- dev.env
- dev.db.env
volumes:
- ./backend:/opt/backend
- ./docker/backend-entrypoint.sh:/opt/backend-entrypoint.sh:z
depends_on:
- db
frontend:
build:
context: .
dockerfile: docker/frontend.Dockerfile
ports:
- 8080:8080
entrypoint: /opt/frontend-entrypoint.sh
volumes:
- ./frontend:/opt/frontend
- ./docker/frontend-entrypoint.sh:/opt/frontend-entrypoint.sh:z
db:
image: postgres:13
env_file:
- dev.db.env
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:

14
docker/backend-entrypoint.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/sh
echo "Waiting for Oracle..."
until nc -z $SQL_HOST $SQL_PORT; do
sleep 1
done
echo "Oracle started"
python3 manage.py makemigrations
python3 manage.py migrate
exec "$@"

10
docker/backend.Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM python:3.10
RUN apt-get update && apt-get -y install netcat
WORKDIR /opt/backend/
COPY requirements.txt .
COPY dev-requirements.txt .
RUN pip install -r requirements.txt -r dev-requirements.txt

4
docker/frontend-entrypoint.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
npm install
npm run serve

View File

@ -0,0 +1,3 @@
FROM node:15.13-alpine
WORKDIR /opt/frontend/

3
frontend/.browserslistrc Normal file
View File

@ -0,0 +1,3 @@
> 1%
last 2 versions
not dead

30
frontend/.eslintrc.js Normal file
View File

@ -0,0 +1,30 @@
module.exports = {
root: true,
env: {
node: true,
},
extends: ["plugin:vue/essential", "eslint:recommended", "@vue/prettier"],
parserOptions: {
parser: "babel-eslint",
},
rules: {
"no-console": process.env.NODE_ENV === "production" ? "warn" : "off",
"no-debugger": process.env.NODE_ENV === "production" ? "warn" : "off",
},
overrides: [
{
files: [
"**/__tests__/*.{j,t}s?(x)",
"**/tests/unit/**/*.spec.{j,t}s?(x)",
],
env: {
jest: true,
},
},
],
};

23
frontend/.gitignore vendored Normal file
View File

@ -0,0 +1,23 @@
.DS_Store
node_modules
/dist
# local env files
.env.local
.env.*.local
# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View File

@ -0,0 +1,4 @@
{
"trailingComma": "all",
"endOfLine": "auto"
}

24
frontend/README.md Normal file
View File

@ -0,0 +1,24 @@
# frontend
## Project setup
```
npm install
```
### Compiles and hot-reloads for development
```
npm run serve
```
### Compiles and minifies for production
```
npm run build
```
### Lints and fixes files
```
npm run lint
```
### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/).

3
frontend/babel.config.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
presets: ["@vue/cli-plugin-babel/preset", "@babel/preset-env"],
};

3
frontend/jest.config.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
preset: "@vue/cli-plugin-unit-jest",
};

35362
frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

79
frontend/package.json Normal file
View File

@ -0,0 +1,79 @@
{
"name": "frontend",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"test:unit": "vue-cli-service test:unit --setupTestFrameworkScriptFile=./tests/setup.js",
"lint": "vue-cli-service lint"
},
"dependencies": {
"core-js": "^3.6.5",
"vue": "^2.6.11",
"vue-router": "^3.2.0",
"vuetify": "^2.4.0",
"vuex": "^3.4.0"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"**/*.js": [
"npm run lint",
"git add"
]
},
"devDependencies": {
"@babel/core": "^7.16.0",
"@babel/preset-env": "^7.16.4",
"@vue/cli-plugin-babel": "~4.5.0",
"@vue/cli-plugin-eslint": "~4.5.0",
"@vue/cli-plugin-router": "~4.5.0",
"@vue/cli-plugin-unit-jest": "^4.5.15",
"@vue/cli-plugin-vuex": "~4.5.0",
"@vue/cli-service": "~4.5.0",
"@vue/eslint-config-prettier": "^6.0.0",
"@vue/test-utils": "^1.3.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^10.1.0",
"babel-jest": "^27.3.1",
"eslint": "^6.7.2",
"eslint-plugin-prettier": "^3.3.1",
"eslint-plugin-vue": "^6.2.2",
"husky": "^7.0.4",
"lint-staged": "^12.1.2",
"prettier": "^2.2.1",
"sass": "~1.32.0",
"sass-loader": "^10.0.0",
"vue-cli-plugin-vuetify": "^2.4.3",
"vue-template-compiler": "^2.6.11",
"vuetify-loader": "^1.7.0"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
".*\\.(vue)$": "vue-jest",
".*\\.(js)$": "babel-jest"
},
"moduleNameMapper": {
"^@/(.*)$": "<rootDir>/src/$1"
},
"collectCoverage": true,
"collectCoverageFrom": [
"**/*.{js,vue}",
"!**/node_modules/**"
]
},
"babel": {
"presets": [
"@babel/preset-env"
]
}
}

BIN
frontend/public/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<title><%= htmlWebpackPlugin.options.title %></title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:100,300,400,500,700,900">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css">
</head>
<body>
<noscript>
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id="app"></div>
<!-- built files will be auto injected -->
</body>
</html>

22
frontend/src/App.vue Normal file
View File

@ -0,0 +1,22 @@
<template>
<v-app>
<v-main>
<AppBar />
<router-view />
</v-main>
</v-app>
</template>
<script>
import AppBar from "./components/AppBar.vue";
export default {
name: "App",
components: {
AppBar,
},
data: () => ({
//
}),
};
</script>

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -0,0 +1 @@
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 87.5 100"><defs><style>.cls-1{fill:#1697f6;}.cls-2{fill:#7bc6ff;}.cls-3{fill:#1867c0;}.cls-4{fill:#aeddff;}</style></defs><title>Artboard 46</title><polyline class="cls-1" points="43.75 0 23.31 0 43.75 48.32"/><polygon class="cls-2" points="43.75 62.5 43.75 100 0 14.58 22.92 14.58 43.75 62.5"/><polyline class="cls-3" points="43.75 0 64.19 0 43.75 48.32"/><polygon class="cls-4" points="64.58 14.58 87.5 14.58 43.75 100 43.75 62.5 64.58 14.58"/></svg>

After

Width:  |  Height:  |  Size: 539 B

View File

@ -0,0 +1,6 @@
<template>
<v-app-bar dense dark>
<v-app-bar-nav-icon></v-app-bar-nav-icon>
<v-app-bar-title>Systemy rozmyte</v-app-bar-title>
</v-app-bar>
</template>

View File

@ -0,0 +1,11 @@
<template><div></div></template>
<script>
export default {
name: "Hello",
data: () => ({}),
};
</script>
<style scoped></style>

14
frontend/src/main.js Normal file
View File

@ -0,0 +1,14 @@
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import vuetify from "./plugins/vuetify";
Vue.config.productionTip = false;
new Vue({
router,
store,
vuetify,
render: (h) => h(App),
}).$mount("#app");

View File

@ -0,0 +1,6 @@
import Vue from "vue";
import Vuetify from "vuetify/lib/framework";
Vue.use(Vuetify);
export default new Vuetify({});

View File

@ -0,0 +1,27 @@
import Vue from "vue";
import VueRouter from "vue-router";
Vue.use(VueRouter);
const routes = [
{
path: "/",
name: "Home",
component: () => import(/* webpackChunkName: "home" */ "../views/Home.vue"),
},
];
const router = new VueRouter({
mode: "history",
base: process.env.BASE_URL,
routes,
});
const DEFAULT_TITLE = "Systemy rozmyte";
router.afterEach((to) => {
Vue.nextTick(() => {
document.title = `${to.name} - ${DEFAULT_TITLE}` || DEFAULT_TITLE;
});
});
export default router;

View File

@ -0,0 +1,11 @@
import Vue from "vue";
import Vuex from "vuex";
Vue.use(Vuex);
export default new Vuex.Store({
state: {},
mutations: {},
actions: {},
modules: {},
});

View File

@ -0,0 +1,17 @@
<template>
<div>
<hello-world />
</div>
</template>
<script>
import HelloWorld from "../components/HelloWorld";
export default {
name: "Home",
components: {
HelloWorld,
},
};
</script>

3
frontend/vue.config.js Normal file
View File

@ -0,0 +1,3 @@
module.exports = {
transpileDependencies: ["vuetify"],
};

7
requirements.txt Normal file
View File

@ -0,0 +1,7 @@
celery==5.1.2
Django==3.2.9
django-cors-headers==3.10.0
django-environ==0.4.5
django-filter==21.1
djangorestframework==3.12.4
psycopg2-binary==2.9.1