first commit

This commit is contained in:
2024-11-07 17:44:29 +03:00
commit 643d6d8f65
247 changed files with 420800 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
# Git
.git
.gitignore
.gitattributes
# CI
.codeclimate.yml
.travis.yml
.taskcluster.yml
# Docker
docker-compose.yml
service_app/Dockerfile
.docker
.dockerignore
# Byte-compiled / optimized / DLL files
**/__pycache__/
**/*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
service_app/env/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# 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/
.coverage
.cache
nosetests.xml
coverage.xml
# Translations
*.mo
*.pot
# Django stuff:
*.log
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Virtual environment
service_app/.env
.venv/
venv/
# PyCharm
.idea
# Python mode for VIM
.ropeproject
**/.ropeproject
# Vim swap files
**/*.swp
# VS Code
.vscode/
test_application/

162
service_app_init/.gitignore vendored Normal file
View File

@@ -0,0 +1,162 @@
# ---> Python
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.idea/
.Python
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
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
service_app/.env
.venv
service_app/env/
venv/
service_app/env/
env.bak/
venv.bak/
# 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/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

View File

@@ -0,0 +1,30 @@
FROM python:3.12-slim-bookworm
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
COPY ../service_app_init/requirements.txt .
RUN uv venv
RUN uv pip install -r requirements.txt
COPY ../service_app_init ./service_app_init
COPY ../databases ./service_app_init/databases
COPY ../api_configs ./service_app_init/api_configs
COPY ../api_events ./service_app_init/api_events
COPY ../api_library ./service_app_init/api_library
COPY ../api_validations ./service_app_init/api_validations
WORKDIR /service_app_init
CMD ["uv", "run", "runner.py"]
# Old File
#FROM python:3.10
#RUN pip install --upgrade pip
#RUN pip install --no-cache-dir --upgrade -r requirements.txt
#CMD ["python", "-m", "app"]

View File

View File

@@ -0,0 +1,110 @@
# A generic, single database configuration.
[alembic]
# path to migration scripts
script_location = alembic
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
# Uncomment the line below if you want the files to be prepended with date and time
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
# for all available tokens
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
# sys.path path, will be prepended to sys.path if present.
# defaults to the current working directory.
prepend_sys_path = .
# timezone to use when rendering the date within the migration file
# as well as the filename.
# If specified, requires the python-dateutil library that can be
# installed by adding `alembic[tz]` to the pip requirements
# string value is passed to dateutil.tz.gettz()
# leave blank for localtime
# timezone =
# max length of characters to apply to the
# "slug" field
# truncate_slug_length = 40
# set to 'true' to run the environment during
# the 'revision' command, regardless of autogenerate
# revision_environment = false
# set to 'true' to allow .pyc and .pyo files without
# a source .py file to be detected as revisions in the
# versions/ directory
# sourceless = false
# version location specification; This defaults
# to alembic/versions. When using multiple version
# directories, initial revisions must be specified with --version-path.
# The path separator used here should be the separator specified by "version_path_separator" below.
# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions
# version path separator; As mentioned above, this is the character used to split
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
# Valid values for version_path_separator are:
#
# version_path_separator = :
# version_path_separator = ;
# version_path_separator = space
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.
# set to 'true' to search source files recursively
# in each "version_locations" directory
# new in Alembic version 1.10
# recursive_version_locations = false
# the output encoding used when revision files
# are written from script.py.mako
# output_encoding = utf-8
; sqlalchemy.url = postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@10.10.2.44:5434/wag_database
sqlalchemy.url = postgresql+psycopg2://berkay_wag_user:berkay_wag_user_password@postgres_commercial:5432/wag_database
[post_write_hooks]
# post_write_hooks defines scripts or Python functions that are run
# on newly generated revision scripts. See the documentation for further
# detail and examples
# format using "black" - use the console_scripts runner, against the "black" entrypoint
# hooks = black
# black.type = console_scripts
# black.entrypoint = black
# black.options = -l 79 REVISION_SCRIPT_FILENAME
# Logging configuration
[loggers]
keys = root,sqlalchemy,alembic
[handlers]
keys = console
[formatters]
keys = generic
[logger_root]
level = WARN
handlers = console
qualname =
[logger_sqlalchemy]
level = WARN
handlers =
qualname = sqlalchemy.engine
[logger_alembic]
level = INFO
handlers =
qualname = alembic
[handler_console]
class = StreamHandler
args = (sys.stderr,)
level = NOTSET
formatter = generic
[formatter_generic]
format = %(levelname)-5.5s [%(name)s] %(message)s
datefmt = %H:%M:%S

View File

@@ -0,0 +1 @@
Generic single-database configuration.

View File

@@ -0,0 +1,79 @@
from logging.config import fileConfig
from sqlalchemy import engine_from_config
from sqlalchemy import pool
from alembic import context
from databases.sql_models.postgres_database import Base
from databases.sql_models import *
# this is the Alembic Config object, which provides
# access to the values within the .ini file in use.
config = context.config
# Interpret the config file for Python logging.
# This line sets up loggers basically.
if config.config_file_name is not None:
fileConfig(config.config_file_name)
# add your model's MetaData object here
# for 'autogenerate' support
# from myapp import mymodel
# target_metadata = mymodel.Base.metadata
target_metadata = Base.metadata
# other values from the config, defined by the needs of env.py,
# can be acquired:
# my_important_option = config.get_main_option("my_important_option")
# ... etc.
def run_migrations_offline() -> None:
"""Run migrations in 'offline' mode.
This configures the context with just a URL
and not an Engine, though an Engine is acceptable
here as well. By skipping the Engine creation
we don't even need a DBAPI to be available.
Calls to context.execute() here emit the given string to the
script output.
"""
url = config.get_main_option("sqlalchemy.url")
context.configure(
url=url,
target_metadata=target_metadata,
literal_binds=True,
dialect_opts={"paramstyle": "named"},
)
with context.begin_transaction():
context.run_migrations()
def run_migrations_online() -> None:
"""Run migrations in 'online' mode.
In this scenario we need to create an Engine
and associate a connection with the context.
"""
connectable = engine_from_config(
config.get_section(config.config_ini_section, {}),
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)
with connectable.connect() as connection:
context.configure(connection=connection, target_metadata=target_metadata)
with context.begin_transaction():
context.run_migrations()
if context.is_offline_mode():
run_migrations_offline()
else:
run_migrations_online()

View File

@@ -0,0 +1,24 @@
"""${message}
Revision ID: ${up_revision}
Revises: ${down_revision | comma,n}
Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
${imports if imports else ""}
# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
branch_labels = ${repr(branch_labels)}
depends_on = ${repr(depends_on)}
def upgrade() -> None:
${upgrades if upgrades else "pass"}
def downgrade() -> None:
${downgrades if downgrades else "pass"}

View File

@@ -0,0 +1,24 @@
import os
def generate_alembic_with_session(text):
from databases.sql_models.postgres_database import session
try:
result = session.execute(
text(
"SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = "
"'alembic_version') AS table_existence;"
)
)
if result.first()[0]:
session.execute(text("delete from alembic_version;"))
session.commit()
except Exception as e:
print(e)
finally:
run_command = "python -m alembic stamp head;"
run_command += (
"python -m alembic revision --autogenerate;python -m alembic upgrade head;"
)
os.system(run_command)

View File

@@ -0,0 +1,32 @@
from service_app_init.initialize_app.initialize_default_department import (
create_occupant_types_defaults,
create_application_defaults,
)
from service_app_init.initialize_app.initiator import init_api_enums_build_types
from service_app_init.initialize_app.model_initator import copy_validations_to_database
from service_app_init.initialize_app.modules_and_services_init import (
create_endpoints_from_api_functions,
create_modules_and_services_and_actions,
)
from service_app_init.initialize_app.event_initator import (
add_events_all_services_and_occupant_types,
create_all_events_from_actions,
add_events_to_system_super_user,
)
from service_app_init.initialize_app.initialize_identity_address_defaults import (
create_identity_address_defaults,
)
__all__ = [
"create_application_defaults",
"create_occupant_types_defaults",
"init_api_enums_build_types",
"copy_validations_to_database",
"create_endpoints_from_api_functions",
"create_modules_and_services_and_actions",
"create_all_events_from_actions",
"add_events_all_services_and_occupant_types",
"create_identity_address_defaults",
"add_events_to_system_super_user",
]

View File

@@ -0,0 +1,409 @@
{
"cities": [
{
"ref_id" : 1,
"licence_plate" : "01",
"city_name" : "Adana"
},
{
"ref_id" : 2,
"licence_plate" : "02",
"city_name" : "Adıyaman"
},
{
"ref_id" : 3,
"licence_plate" : "03",
"city_name" : "Afyonkarahisar"
},
{
"ref_id" : 4,
"licence_plate" : "04",
"city_name" : "Ağrı"
},
{
"ref_id" : 5,
"licence_plate" : "05",
"city_name" : "Amasya"
},
{
"ref_id" : 6,
"licence_plate" : "06",
"city_name" : "Ankara"
},
{
"ref_id" : 7,
"licence_plate" : "07",
"city_name" : "Antalya"
},
{
"ref_id" : 8,
"licence_plate" : "08",
"city_name" : "Artvin"
},
{
"ref_id" : 9,
"licence_plate" : "09",
"city_name" : "Aydın"
},
{
"ref_id" : 10,
"licence_plate" : "10",
"city_name" : "Balıkesir"
},
{
"ref_id" : 11,
"licence_plate" : "11",
"city_name" : "Bilecik"
},
{
"ref_id" : 12,
"licence_plate" : "12",
"city_name" : "Bingöl"
},
{
"ref_id" : 13,
"licence_plate" : "13",
"city_name" : "Bitlis"
},
{
"ref_id" : 14,
"licence_plate" : "14",
"city_name" : "Bolu"
},
{
"ref_id" : 15,
"licence_plate" : "15",
"city_name" : "Burdur"
},
{
"ref_id" : 16,
"licence_plate" : "16",
"city_name" : "Bursa"
},
{
"ref_id" : 17,
"licence_plate" : "17",
"city_name" : "Çanakkale"
},
{
"ref_id" : 18,
"licence_plate" : "18",
"city_name" : "Çankırı"
},
{
"ref_id" : 19,
"licence_plate" : "19",
"city_name" : "Çorum"
},
{
"ref_id" : 20,
"licence_plate" : "20",
"city_name" : "Denizli"
},
{
"ref_id" : 21,
"licence_plate" : "21",
"city_name" : "Diyarbakır"
},
{
"ref_id" : 22,
"licence_plate" : "22",
"city_name" : "Edirne"
},
{
"ref_id" : 23,
"licence_plate" : "23",
"city_name" : "Elazığ"
},
{
"ref_id" : 24,
"licence_plate" : "24",
"city_name" : "Erzincan"
},
{
"ref_id" : 25,
"licence_plate" : "25",
"city_name" : "Erzurum"
},
{
"ref_id" : 26,
"licence_plate" : "26",
"city_name" : "Eskişehir"
},
{
"ref_id" : 27,
"licence_plate" : "27",
"city_name" : "Gaziantep"
},
{
"ref_id" : 28,
"licence_plate" : "28",
"city_name" : "Giresun"
},
{
"ref_id" : 29,
"licence_plate" : "29",
"city_name" : "Gümüşhane"
},
{
"ref_id" : 30,
"licence_plate" : "30",
"city_name" : "Hakkari"
},
{
"ref_id" : 31,
"licence_plate" : "31",
"city_name" : "Hatay"
},
{
"ref_id" : 32,
"licence_plate" : "32",
"city_name" : "Isparta"
},
{
"ref_id" : 33,
"licence_plate" : "33",
"city_name" : "Mersin"
},
{
"ref_id" : 34,
"licence_plate" : "34",
"city_name" : "İstanbul"
},
{
"ref_id" : 35,
"licence_plate" : "35",
"city_name" : "İzmir"
},
{
"ref_id" : 36,
"licence_plate" : "36",
"city_name" : "Kars"
},
{
"ref_id" : 37,
"licence_plate" : "37",
"city_name" : "Kastamonu"
},
{
"ref_id" : 38,
"licence_plate" : "38",
"city_name" : "Kayseri"
},
{
"ref_id" : 39,
"licence_plate" : "39",
"city_name" : "Kırklareli"
},
{
"ref_id" : 40,
"licence_plate" : "40",
"city_name" : "Kırşehir"
},
{
"ref_id" : 41,
"licence_plate" : "41",
"city_name" : "Kocaeli"
},
{
"ref_id" : 42,
"licence_plate" : "42",
"city_name" : "Konya"
},
{
"ref_id" : 43,
"licence_plate" : "43",
"city_name" : "Kütahya"
},
{
"ref_id" : 44,
"licence_plate" : "44",
"city_name" : "Malatya"
},
{
"ref_id" : 45,
"licence_plate" : "45",
"city_name" : "Manisa"
},
{
"ref_id" : 46,
"licence_plate" : "46",
"city_name" : "Kahramanmaraş"
},
{
"ref_id" : 47,
"licence_plate" : "47",
"city_name" : "Mardin"
},
{
"ref_id" : 48,
"licence_plate" : "48",
"city_name" : "Muğla"
},
{
"ref_id" : 49,
"licence_plate" : "49",
"city_name" : "Muş"
},
{
"ref_id" : 50,
"licence_plate" : "50",
"city_name" : "Nevşehir"
},
{
"ref_id" : 51,
"licence_plate" : "51",
"city_name" : "Niğde"
},
{
"ref_id" : 52,
"licence_plate" : "52",
"city_name" : "Ordu"
},
{
"ref_id" : 53,
"licence_plate" : "53",
"city_name" : "Rize"
},
{
"ref_id" : 54,
"licence_plate" : "54",
"city_name" : "Sakarya"
},
{
"ref_id" : 55,
"licence_plate" : "55",
"city_name" : "Samsun"
},
{
"ref_id" : 56,
"licence_plate" : "56",
"city_name" : "Siirt"
},
{
"ref_id" : 57,
"licence_plate" : "57",
"city_name" : "Sinop"
},
{
"ref_id" : 58,
"licence_plate" : "58",
"city_name" : "Sivas"
},
{
"ref_id" : 59,
"licence_plate" : "59",
"city_name" : "Tekirdağ"
},
{
"ref_id" : 60,
"licence_plate" : "60",
"city_name" : "Tokat"
},
{
"ref_id" : 61,
"licence_plate" : "61",
"city_name" : "Trabzon"
},
{
"ref_id" : 62,
"licence_plate" : "62",
"city_name" : "Tunceli"
},
{
"ref_id" : 63,
"licence_plate" : "63",
"city_name" : "Şanlıurfa"
},
{
"ref_id" : 64,
"licence_plate" : "64",
"city_name" : "Uşak"
},
{
"ref_id" : 65,
"licence_plate" : "65",
"city_name" : "Van"
},
{
"ref_id" : 66,
"licence_plate" : "66",
"city_name" : "Yozgat"
},
{
"ref_id" : 67,
"licence_plate" : "67",
"city_name" : "Zonguldak"
},
{
"ref_id" : 68,
"licence_plate" : "68",
"city_name" : "Aksaray"
},
{
"ref_id" : 69,
"licence_plate" : "69",
"city_name" : "Bayburt"
},
{
"ref_id" : 70,
"licence_plate" : "70",
"city_name" : "Karaman"
},
{
"ref_id" : 71,
"licence_plate" : "71",
"city_name" : "Kırıkkale"
},
{
"ref_id" : 72,
"licence_plate" : "72",
"city_name" : "Batman"
},
{
"ref_id" : 73,
"licence_plate" : "73",
"city_name" : ırnak"
},
{
"ref_id" : 74,
"licence_plate" : "74",
"city_name" : "Bartın"
},
{
"ref_id" : 75,
"licence_plate" : "75",
"city_name" : "Ardahan"
},
{
"ref_id" : 76,
"licence_plate" : "76",
"city_name" : "Iğdır"
},
{
"ref_id" : 77,
"licence_plate" : "77",
"city_name" : "Yalova"
},
{
"ref_id" : 78,
"licence_plate" : "78",
"city_name" : "Karabük"
},
{
"ref_id" : 79,
"licence_plate" : "79",
"city_name" : "Kilis"
},
{
"ref_id" : 80,
"licence_plate" : "80",
"city_name" : "Osmaniye"
},
{
"ref_id" : 81,
"licence_plate" : "81",
"city_name" : "Düzce"
}
]}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,6 @@
cities:
cities.ref_id == cities.city_code
district_code:
district_code.ref_id == district_code.district_code

View File

@@ -0,0 +1,139 @@
def create_all_events_from_actions():
import api_events
from databases.sql_models import Events
active_confirmed = dict(
created_by="System",
confirmed_by="System",
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
an_empty_list, duplicate_list = [], []
for event in events.__all__:
event_selected = getattr(events, event)
for (
event_selected_key,
event_selected_one,
) in event_selected.__event_keys__.items():
an_empty_list.append(event_selected_key)
event_selected_function = getattr(event_selected, event_selected_one, None)
if endpoint_match := event_selected.action_match:
if event_selected_function:
selected_event = Events.find_one(
event_type=event_selected.event_type,
function_class=event,
function_code=event_selected_key,
endpoint_id=endpoint_match.id,
endpoint_uu_id=str(endpoint_match.uu_id),
**active_confirmed,
)
if not selected_event:
created_event = Events.create(
event_type=event_selected.event_type,
function_class=event,
function_code=event_selected_key,
endpoint_id=endpoint_match.id,
endpoint_uu_id=str(endpoint_match.uu_id),
**active_confirmed,
)
print(f"Event created: {created_event.uu_id}")
for item in an_empty_list:
if an_empty_list.count(item) > 1:
if item not in duplicate_list:
duplicate_list.append(item)
if duplicate_list:
raise Exception(
f"Duplicate events found: {duplicate_list}. Check events folder look for given uu-ids."
)
return True
def add_events_all_services_and_occupant_types():
from database_sql_models import Services, Service2Events
import tasks2events
active_confirmed = dict(
created_by="System",
confirmed_by="System",
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
for event_block in tasks2events.__all__:
event_block_class = getattr(tasks2events, event_block)
service_selected = Services.find_one(
service_code=getattr(event_block_class, "service_code", None),
)
if not service_selected:
raise Exception(f"{event_block_class.service_code} service is not found")
service_selected.update(
related_responsibility=getattr(event_block_class, "related_code", None)
)
for block in event_block_class():
event_id, event_uu_id = block
Service2Events.find_or_create(
service_id=service_selected.id,
service_uu_id=str(service_selected.uu_id),
event_id=event_id,
event_uu_id=event_uu_id,
**active_confirmed,
)
def add_events_to_system_super_user():
from events.events_bind_services import ServiceBindEmployeeEventMethods
from database_sql_models import Services, Employees, Staff
add_service = Services.find_one(service_code="SRE-SUE")
if not add_service:
raise Exception("Service not found")
find_staff = Staff.find_one(staff_code="SUE")
if not find_staff:
raise Exception("Super User not found")
add_employee = Employees.find_one(staff_id=find_staff.id)
if not add_employee:
raise Exception("Super User Employee not found")
ServiceBindEmployeeEventMethods.bind_services_employee(
service_id=add_service.id,
employee_id=add_employee.id,
)
# super_user_service = Services.find_or_create(service_code="SRE-SU")
# if not super_user_service:
# raise Exception("Super user is service not found")
#
# user_default_service = Services.find_or_create(service_code="AUTH")
# if not user_default_service:
# raise Exception("AUTH service is not found")
#
# for item in SuperUserEventBlock():
# event_id, event_uu_id = item
# Service2Events.find_or_create(
# service_id=super_user_service.id,
# service_uu_id=str(super_user_service.uu_id),
# event_id=event_id,
# event_uu_id=event_uu_id,
# **active_confirmed,
# )
#
# for event_block in AuthDefaultEventBlock():
# event_id, event_uu_id = event_block
# Service2Events.find_or_create(
# service_id=user_default_service.id,
# service_uu_id=str(user_default_service.uu_id),
# event_id=event_id,
# event_uu_id=event_uu_id,
# **active_confirmed,
# )

View File

@@ -0,0 +1,420 @@
from databases.no_sql_models.validations import DomainViaUser
from databases import MongoQueryIdentity, Event2Employee, OccupantTypes
def create_occupant_types_defaults():
"""
occupant_category = mapped_column(String, server_default="")
occupant_category_type = mapped_column(String, server_default="")
occupant_is_unique = mapped_column(Boolean, server_default="0")
"""
list_occupant_types = [
{
"occupant_type": "Toplantı Başkanı",
"occupant_description": "Toplantı Başkanı",
"occupant_code": "MT-PRS",
"occupant_category": "Toplantı",
"occupant_category_type": "MT",
"occupant_is_unique": True,
},
{
"occupant_type": "Toplantı Katip",
"occupant_description": "Toplantıda tutanak tutan kişi",
"occupant_code": "MT-WRT",
"occupant_category": "Toplantı",
"occupant_category_type": "MT",
"occupant_is_unique": True,
},
{
"occupant_type": "Toplantı Katılımcısı",
"occupant_description": "Toplantıda sadece katılan kişi",
"occupant_code": "MT-ATT",
"occupant_category": "Toplantı",
"occupant_category_type": "MT",
"occupant_is_unique": False,
},
{
"occupant_type": "Toplantı Danışman",
"occupant_description": "Toplantıda danışmanlık yapan kişi",
"occupant_code": "MT-ADV",
"occupant_category": "Toplantı",
"occupant_category_type": "MT",
"occupant_is_unique": False,
},
{
"occupant_type": "Toplantı Seçilmiş Başkanı",
"occupant_description": "Toplantı Seçilmiş Başkanı",
"occupant_code": "MT-VPR",
"occupant_category": "Toplantı",
"occupant_category_type": "MT",
"occupant_is_unique": True,
},
{
"occupant_type": "Daire Sahibi",
"occupant_description": "Daire Sahibi",
"occupant_code": "FL-OWN",
"occupant_category": "Daire",
"occupant_category_type": "FL",
"occupant_is_unique": True,
},
{
"occupant_type": "Daire Kiracısı",
"occupant_description": "Daire Kiracısı",
"occupant_code": "FL-TEN",
"occupant_category": "Daire",
"occupant_category_type": "FL",
"occupant_is_unique": True,
},
{
"occupant_type": "Daire Sakini",
"occupant_description": "Daire Sakini",
"occupant_code": "FL-RES",
"occupant_category": "Daire",
"occupant_category_type": "FL",
"occupant_is_unique": False,
},
{
"occupant_type": "Daire Sakini Vekili",
"occupant_description": "Daire Sakini Vekili",
"occupant_code": "FL-REP",
"occupant_category": "Daire",
"occupant_category_type": "FL",
"occupant_is_unique": False,
},
{
"occupant_type": "Bina Avukatı",
"occupant_description": "Bina Avukatı",
"occupant_code": "BU-ATT",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": False,
},
{
"occupant_type": "Bina Avukatı Yardımcısı",
"occupant_description": "Bina Avukatı Yardımcısı",
"occupant_code": "BU-ATA",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": False,
},
{
"occupant_type": "Bina Denetmen Yardımcısı",
"occupant_description": "Bina Denetmen Yardımcısı",
"occupant_code": "BU-SPA",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": False,
},
{
"occupant_type": "Bina Denetmeni",
"occupant_description": "Bina Denetmeni",
"occupant_code": "BU-SPV",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": False,
},
{
"occupant_type": "Bina Yönetici Yardımcısı",
"occupant_description": "Bina Yönetici Yardımcısı",
"occupant_code": "BU-MNA",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": False,
},
{
"occupant_type": "Bina Yöneticisi",
"occupant_description": "Bina Yöneticisi",
"occupant_code": "BU-MNG",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": True,
},
{
"occupant_type": "Bina Muhasabecisi",
"occupant_description": "Bina Muhasabecisi",
"occupant_code": "BU-ACC",
"occupant_category": "Bina",
"occupant_category_type": "BU",
"occupant_is_unique": False,
},
]
for list_occupant_type in list_occupant_types:
OccupantTypes.find_or_create(**{"is_confirmed": True, **list_occupant_type})
def create_application_defaults():
from database_sql_models import (
Companies,
Departments,
Duty,
Duties,
Employees,
People,
Users,
Staff,
RelationshipDutyCompany,
)
created_by, confirmed_by = "System", "System"
company_management = Companies.find_or_create(
**{
"formal_name": "Evyos LTD",
"public_name": "Evyos Verimlilik Sistemleri",
"company_type": "LTD",
"commercial_type": "Commercial",
"tax_no": "123132123132",
"company_tag": "Evyos",
"default_lang_type": "TR",
"default_money_type": "TL",
"created_by": created_by,
"confirmed_by": confirmed_by,
"is_commercial": True,
**dict(
is_confirmed=True, active=True, deleted=False, is_notification_send=True
),
}
)
Duties.init_a_company_default_duties(
company_id=company_management.id, company_uu_id=str(company_management.uu_id)
)
bulk_duty = Duty.find_one(
duty_code="BULK",
)
RelationshipDutyCompany.find_or_create(
duties_id=bulk_duty.id,
owner_id=company_management.id,
member_id=company_management.id,
parent_id=None,
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
it_dept = Departments.find_one(
department_name="IT Department",
department_code="ITD001",
company_id=company_management.id,
company_uu_id=str(company_management.uu_id),
**dict(
is_confirmed=True, active=True, deleted=False, is_notification_send=True
),
)
Duty.find_or_create(
**dict(
duty_name="Database Manager",
duty_code="DM",
duty_description="Database Manager",
created_by=created_by,
confirmed_by=confirmed_by,
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
)
Duty.find_or_create(
**dict(
duty_name="Network Manager",
duty_code="NM",
duty_description="Network Manager",
created_by=created_by,
confirmed_by=confirmed_by,
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
)
application_manager_duty = Duty.find_or_create(
duty_name="Application Manager",
duty_code="AM",
duty_description="Application Manager",
created_by=created_by,
confirmed_by=confirmed_by,
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
application_super_user_duty = Duty.find_or_create(
duty_name="Super User",
duty_code="SUE",
duty_description="Super User",
created_by=created_by,
confirmed_by=confirmed_by,
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
application_manager_duties = Duties.find_or_create(
department_id=it_dept.id,
department_uu_id=str(it_dept.uu_id),
duties_id=application_manager_duty.id,
duties_uu_id=str(application_manager_duty.uu_id),
company_id=company_management.id,
company_uu_id=str(company_management.uu_id),
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
super_user_duties = Duties.find_or_create(
department_id=it_dept.id,
department_uu_id=str(it_dept.uu_id),
duties_id=application_super_user_duty.id,
duties_uu_id=str(application_manager_duty.uu_id),
company_id=company_management.id,
company_uu_id=str(company_management.uu_id),
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
app_manager = People.find_or_create(
**{
"firstname": "Berkay Application Manager",
"surname": "Karatay",
"sex_code": "M",
"middle_name": "",
"father_name": "Father",
"mother_name": "Mother",
"country_code": "TR",
"national_identity_id": "12312312312",
"birth_place": "Ankara",
"birth_date": "01.07.1990",
"tax_no": "1231231231",
"created_by": created_by,
"confirmed_by": confirmed_by,
**dict(
is_confirmed=True, active=True, deleted=False, is_notification_send=True
),
}
)
sup_manager = People.find_or_create(
**{
"firstname": "Berkay Super User",
"surname": "Karatay",
"sex_code": "M",
"middle_name": "",
"father_name": "Father",
"mother_name": "Mother",
"country_code": "TR",
"national_identity_id": "12312312313",
"birth_place": "Ankara",
"birth_date": "01.07.1990",
"tax_no": "1231231232",
"created_by": created_by,
"confirmed_by": confirmed_by,
**dict(
is_confirmed=True, active=True, deleted=False, is_notification_send=True
),
}
)
application_manager_staff = Staff.find_or_create(
staff_description="Application Manager",
staff_name="Application Manager Employee",
staff_code="AME",
duties_id=application_manager_duties.id,
duties_uu_id=str(application_manager_duty.uu_id),
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
super_user_staff = Staff.find_or_create(
staff_description="Super User",
staff_name="Super User Employee",
staff_code="SUE",
duties_id=super_user_duties.id,
duties_uu_id=str(application_manager_duty.uu_id),
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
app_manager_employee = Employees.find_or_create(
staff_id=application_manager_staff.id,
staff_uu_id=str(application_manager_staff.uu_id),
people_id=app_manager.id,
people_uu_id=str(app_manager.uu_id),
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
super_user_employee = Employees.find_or_create(
staff_id=super_user_staff.id,
staff_uu_id=str(super_user_staff.uu_id),
people_id=sup_manager.id,
people_uu_id=str(sup_manager.uu_id),
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
app_manager_user = Users.find_or_create(
person_id=app_manager.id,
person_uu_id=str(app_manager.uu_id),
user_tag=app_manager.person_tag,
email="karatay.berkay.man@evyos.com.tr",
phone_number="+901111111111",
avatar="https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg",
created_by=created_by,
confirmed_by=confirmed_by,
related_company=str(company_management.uu_id),
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
if not app_manager_user.is_found:
app_manager_user.reset_password_token()
MongoQueryIdentity(
company_uuid=company_management.uu_id
).create_domain_via_user(
payload=DomainViaUser(
user_uu_id=str(app_manager_user.uu_id),
main_domain="evyos.com.tr",
other_domains_list=["evyos.com.tr"],
)
)
sup_manager_employee = Users.find_or_create(
person_id=sup_manager.id,
person_uu_id=str(sup_manager.uu_id),
user_tag=sup_manager.person_tag,
email="karatay.berkay.sup@evyos.com.tr",
phone_number="+901111111112",
avatar="https://s.tmimgcdn.com/scr/800x500/276800/building-home-nature-logo-vector-template-3_276851-original.jpg",
created_by=created_by,
confirmed_by=confirmed_by,
related_company=str(company_management.uu_id),
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
if not sup_manager_employee.is_found:
sup_manager_employee.reset_password_token()
MongoQueryIdentity(
company_uuid=company_management.uu_id
).create_domain_via_user(
payload=DomainViaUser(
user_uu_id=str(sup_manager_employee.uu_id),
main_domain="evyos.com.tr",
other_domains_list=["evyos.com.tr"],
)
)

View File

@@ -0,0 +1,185 @@
from json import loads
from os import path
path_to_folder = "initialize_app/default_inits"
list_of_snippets = [
"countries.json",
"cities.json",
"district.json",
"locality.json",
"neighborhood.json",
]
def create_country_defaults(path_to_joined_folder, confirmed_by_system):
from database_sql_models import (
AddressCountry,
)
with open(path_to_joined_folder("countries.json"), "r") as file:
countries = loads(file.read())
print("Countries are read from file ------------------")
if not countries:
print("Countries json file is empty")
for country in countries.get("tr_co"):
country_obj = AddressCountry.find_or_create(
country_name=country.get("country_name"),
country_code=country.get("country_code"),
ref_id=str(country.get("ref_id")),
**confirmed_by_system,
)
def create_cities_defaults(path_to_joined_folder, confirmed_by_system, state_id):
from database_sql_models import (
AddressCity,
)
with open(path_to_joined_folder("cities.json"), "r") as file:
cities = loads(file.read())
print("Cities are read from file ------------------")
if not cities:
print("Cities json file is empty")
for city in cities.get("cities"):
city_obj = AddressCity.find_or_create(
state_id=state_id,
city_name=city.get("city_name"),
city_code=city.get("licence_plate"),
licence_plate=city.get("licence_plate"),
ref_id=str(city.get("ref_id")),
**confirmed_by_system,
)
print(f"City {city_obj.city_name} is created")
def create_district_defaults(path_to_joined_folder, confirmed_by_system):
from database_sql_models import (
AddressCity,
AddressDistrict,
)
with open(path_to_joined_folder("district.json"), "r") as file:
districts = loads(file.read())
print("Districts are read from file ------------------")
if not districts:
print("Districts json file is empty")
for district in districts.get("tr_ilce"):
city = AddressCity.find_one(ref_id=str(district.get("city_id")))
if not city:
print(f"City with ref_id {district.get('city_id')} is not found")
district_obj = AddressDistrict.find_or_create(
city_id=city.id,
district_name=district.get("district_name"),
district_code=str(district.get("ref_id")),
ref_id=str(district.get("ref_id")),
**confirmed_by_system,
)
print(f"District {district_obj} is created")
def create_locality_defaults(path_to_joined_folder, confirmed_by_system):
from database_sql_models import (
AddressDistrict,
AddressLocality,
)
with open(path_to_joined_folder("locality.json"), "r") as file:
localities = loads(file.read())
print("Localities are read from file ------------------")
if not localities:
print("Localities json file is empty")
for locality in localities.get("tr_semt"):
district = AddressDistrict.find_one(ref_id=str(locality.get("district_id")))
if not district:
print(
f"District with ref_id {locality.get('district_id')} is not found"
)
locality_obj = AddressLocality.find_or_create(
district_id=district.id,
locality_name=locality.get("locality_name"),
locality_code=str(locality.get("post_code")),
ref_id=str(locality.get("ref_id")),
**confirmed_by_system,
)
print(f"Locality {locality_obj} is created")
def create_neighborhood_defaults(path_to_joined_folder, confirmed_by_system):
from database_sql_models import (
AddressLocality,
AddressNeighborhood,
AddressDistrict,
)
with open(path_to_joined_folder("neighborhood.json"), "r") as file:
neighborhoods = loads(file.read())
print("Neighborhoods are read from file ------------------")
if not neighborhoods:
print("Neighborhoods json file is empty")
for neighborhood in neighborhoods.get("tr_mahalle_koy"):
locality = AddressLocality.find_one(
ref_id=str(neighborhood.get("locality_id"))
)
district = AddressDistrict.find_one(
ref_id=str(neighborhood.get("district_id"))
)
if not district:
print(
f"District with ref_id {neighborhood.get('district_id')} is not found"
)
neighborhood_obj = AddressNeighborhood.find_or_create(
locality_id=locality.id if locality else None,
district_id=district.id,
neighborhood_name=neighborhood.get("neighborhood_name"),
neighborhood_code=str(neighborhood.get("ref_id")),
ref_id=str(neighborhood.get("ref_id")),
**confirmed_by_system,
)
print(f"Neighborhood {neighborhood_obj} is created")
def create_identity_address_defaults():
from database_sql_models import (
AddressCountry,
AddressState,
)
print("Creating address defaults ------------------")
path_to_joined_folder = lambda json_name: path.join(path_to_folder, json_name)
confirmed_by_system = dict(
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
created_by="System",
confirmed_by="System",
)
create_country_defaults(path_to_joined_folder, confirmed_by_system)
turkey = AddressCountry.find_one(ref_id="90")
turkey_state = AddressState.find_or_create(
state_name="Türkiye",
state_code="TR",
country_id=turkey.id,
**confirmed_by_system,
)
create_cities_defaults(path_to_joined_folder, confirmed_by_system, turkey_state.id)
create_district_defaults(path_to_joined_folder, confirmed_by_system)
create_locality_defaults(path_to_joined_folder, confirmed_by_system)
create_neighborhood_defaults(path_to_joined_folder, confirmed_by_system)
print("All address defaults are created ------------------")
return True

View File

@@ -0,0 +1,242 @@
def init_api_enums_build_types():
from database_sql_models import BuildTypes
from database_sql_models.others.enums import ApiEnumDropdown
from validations import InsertBuildTypes
insert_types = [
{
"function_code": "EVYOS",
"type_code": "APT_KZN",
"type_name": "Apartman Kazan Dairesi",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "APT_GRJ",
"type_name": "Apartman Garaj",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "APT_DP",
"type_name": "Apartman Depo",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "DAIRE",
"type_name": "Apartman Dairesi",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "APT",
"type_name": "Apartman Binası",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "APT_YNT",
"type_name": "Apartman Yönetimi",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "APT_PRK",
"type_name": "Apartman Açık Park Alanı",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "APT_YSL",
"type_name": "Apartman Yeşil Alan",
"lang": "TR",
},
{
"function_code": "EVYOS",
"type_code": "APT_YOL",
"type_name": "Apartman Ara Yol",
"lang": "TR",
},
]
for insert_type in insert_types:
build_types = InsertBuildTypes(
function_code="EVYOS",
lang=insert_type["lang"],
type_code=str(insert_type["type_code"]).upper(),
type_name=insert_type["type_name"],
is_confirmed=True,
)
BuildTypes.find_or_create(**build_types.model_dump())
insert_enums = [
{"enum_class": "BuildDuesTypes", "type_code": "BDT-D", "type_name": "Debit"},
{
"enum_class": "BuildDuesTypes",
"type_code": "BDT-A",
"type_name": "Add Debit",
},
{
"enum_class": "BuildDuesTypes",
"type_code": "BDT-R",
"type_name": "Renovation",
},
{
"enum_class": "BuildDuesTypes",
"type_code": "BDT-L",
"type_name": "Lawyer expence",
},
{
"enum_class": "BuildDuesTypes",
"type_code": "BDT-sf",
"type_name": "Service fee",
},
{
"enum_class": "AccountingReceiptTypes",
"type_code": "ART-A",
"type_name": "Kasa Tahsil Fişi",
},
{
"enum_class": "AccountingReceiptTypes",
"type_code": "ART-E",
"type_name": "Kasa Tediye Fişi",
},
{
"enum_class": "AccountingReceiptTypes",
"type_code": "ART-M",
"type_name": "Mahsup Fişi",
},
{
"enum_class": "AccountingReceiptTypes",
"type_code": "ART-O",
"type_name": "ılış Fişi",
},
{
"enum_class": "AccountingReceiptTypes",
"type_code": "ART-C",
"type_name": "Kapanış Fişi",
},
{"enum_class": "IbanBudgetType", "type_code": "IBT-I", "type_name": "Iban"},
{"enum_class": "IbanBudgetType", "type_code": "IBT-B", "type_name": "Budget"},
{
"enum_class": "IbanBudgetType",
"type_code": "IBT-TR",
"type_name": "Transaction records",
},
{"enum_class": "ProjectTypes", "type_code": "R", "type_name": "Tadilat"},
{
"enum_class": "ProjectTypes",
"type_code": "PT-C",
"type_name": "Mahkeme süreçleri",
},
{
"enum_class": "ProjectTypes",
"type_code": "PT-Z",
"type_name": "Sıfır Bakiye",
},
{
"enum_class": "EdmBudgetType",
"type_code": "PT-B",
"type_name": "Banka records",
},
{
"enum_class": "EdmBudgetType",
"type_code": "PT-S",
"type_name": "Sistem kaydı",
},
{
"enum_class": "EdmBudgetType",
"type_code": "EBT-C",
"type_name": "Build, Flat or Site records",
},
{"enum_class": "ExpireType", "type_code": "1", "type_name": "daily"},
{"enum_class": "ExpireType", "type_code": "7", "type_name": "weekly"},
{"enum_class": "ExpireType", "type_code": "30", "type_name": "monthly"},
{"enum_class": "ExpireType", "type_code": "90", "type_name": "quarter"},
{"enum_class": "ExpireType", "type_code": "180", "type_name": "six_month"},
{"enum_class": "ExpireType", "type_code": "365", "type_name": "yearly"},
{"enum_class": "PhoneType", "type_code": "M", "type_name": "cep tel"},
{"enum_class": "PhoneType", "type_code": "L", "type_name": "sabit telefon"},
{"enum_class": "PhoneType", "type_code": "F", "type_name": "fax"},
{"enum_class": "PhoneType", "type_code": "C", "type_name": "santral"},
{
"enum_class": "PhoneType",
"type_code": "G",
"type_name": "ülke genelindeki hatlar 444",
},
{"enum_class": "PerComType", "type_code": "1", "type_name": "Person"},
{"enum_class": "PerComType", "type_code": "2", "type_name": "Company"},
{"enum_class": "Directions", "type_code": "NN", "type_name": "North"},
{"enum_class": "Directions", "type_code": "EE", "type_name": "East"},
{"enum_class": "Directions", "type_code": "SS", "type_name": "South"},
{"enum_class": "Directions", "type_code": "WW", "type_name": "West"},
{"enum_class": "Directions", "type_code": "NE", "type_name": "North East"},
{"enum_class": "Directions", "type_code": "NW", "type_name": "North West"},
{"enum_class": "Directions", "type_code": "SE", "type_name": "South East"},
{"enum_class": "Directions", "type_code": "SW", "type_name": "South West"},
{
"enum_class": "MeetingTypes",
"type_code": "MT-RBM",
"type_name": "Regular Building Meeting",
},
{
"enum_class": "MeetingTypes",
"type_code": "MT-DBM",
"type_name": "Disaster Building Meeting",
},
{
"enum_class": "MeetingTypes",
"type_code": "MT-EBM",
"type_name": "Emergency Building Meeting",
},
{
"enum_class": "DebitTypes",
"type_code": "DT-D",
"type_name": "Debit Sender",
},
{
"enum_class": "DebitTypes",
"type_code": "DT-R",
"type_name": "Credit Receiver",
},
{
"enum_class": "DebitTypes",
"type_code": "DT-Z",
"type_name": "Zero Balance",
},
{
"enum_class": "ProjectTeamTypes",
"type_code": "PTT-LDR",
"type_name": "Project Leader",
},
{
"enum_class": "ProjectTeamTypes",
"type_code": "PTT-RSP",
"type_name": "Project Responsible",
},
{
"enum_class": "ProjectTeamTypes",
"type_code": "PTT-EMP",
"type_name": "Project Employee",
},
{
"enum_class": "ProjectTeamTypes",
"type_code": "PTT-FIN",
"type_name": "Project Finance Responsible",
},
]
for insert_enum in insert_enums:
ApiEnumDropdown.find_or_create(
enum_class=insert_enum["enum_class"],
value=insert_enum["type_name"],
key=str(insert_enum["type_code"]).upper(),
description=insert_enum["type_name"],
)
# for insert_meeting_type in insert_meeting_types:
# ApiEnumDropdown.find_or_create(
# enum_class=insert_meeting_type["enum_class"],
# value=insert_meeting_type["value"],
# key=str(insert_meeting_type["key"]).upper(),
# description=insert_meeting_type["description"],
# )

View File

@@ -0,0 +1,44 @@
import validations
# from database_sql_models.event.event import Models, ModelEntities
def get_upper_only(text: str):
sc_letter, th_letter = text[1], text[2]
upper_letters = "".join(letter for letter in text if str(letter).isupper())
return upper_letters[0] + sc_letter + th_letter + upper_letters[1:]
def copy_validations_to_database():
for validation in validations.__all__:
validation_pydantic = getattr(validations, validation)
model_dict = {
"model_owner": "system",
"model_type": "BaseModel",
"model_name": validation_pydantic.__name__,
"model_description": "",
"model_code": get_upper_only(validation_pydantic.__name__),
"is_confirmed": True,
"deleted": False,
"active": True,
}
# created_model = Models.find_or_create(**model_dict)
fields = validation_pydantic.model_fields
for field, info in fields.items():
default_value = (
None
if getattr(info, "default").__str__() == "PydanticUndefined"
else getattr(info, "default")
)
model_field_dict = {
"field_name": field,
"field_type": str(info.annotation),
"field_required": bool(info.is_required()),
"model_id": created_model.id,
"is_confirmed": True,
"deleted": False,
"active": True,
}
if default_value:
model_field_dict.update({"field_default_value": str(default_value)})
# ModelEntities.find_or_create(**model_field_dict)

View File

@@ -0,0 +1,333 @@
import typing
from database_sql_models import (
Modules,
Duty,
Services,
Service2Events,
OccupantTypes,
EndpointRestriction,
)
def create_endpoints_from_api_functions():
from app import app as api_app
for route in api_app.routes:
route_path, route_summary = (
str(getattr(route, "path")),
str(getattr(route, "name")) or "",
)
# if route_path in Config.INSECURE_PATHS:
# continue
# print('route_path ', route_path, 'route_summary', route_summary)
create_dict = dict(
is_confirmed=True,
active=True,
deleted=False,
is_notification_send=True,
)
methods = [method.lower() for method in getattr(route, "methods")]
for route_method in methods:
restriction = EndpointRestriction.find_or_create(
**dict(
endpoint_method=route_method,
endpoint_name=route_path,
endpoint_desc=route_summary.replace("_", " "),
endpoint_function=route_summary,
**create_dict,
)
)
if not restriction.is_found:
restriction.endpoint_code = f"AR{str(restriction.id).zfill(3)}"
restriction.save()
return
def create_services_building(module_dict: dict):
"""
4. Service [Bina] Yönetim - OPTIONAL
5. Service [Bina] Yasal İşler - OPTIONAL
6. Service [Bina] Temizlik - OPTIONAL
7. Service [Bina] Isınma Sistemi - OPTIONAL
8. Service [Bina] Güvenlik Sistemi + OPTIONAL
9. Service [Bina] Bakım + OPTIONAL
10. Service [Bina] Onarım + OPTIONAL
11 Service [Bina] Gözlem + OPTIONAL
"""
Services.find_or_create(
**module_dict,
service_name="Building Management",
service_description="Building Management Service",
service_code="SR-BLD-MNG",
)
Services.find_or_create(
**module_dict,
service_name="Building Legal Affairs",
service_description="Building Legal Affairs Service",
service_code="SR-BLD-LGL",
)
Services.find_or_create(
**module_dict,
service_name="Building Cleaning",
service_description="Building Cleaning Service",
service_code="SR-BLD-CLN",
)
Services.find_or_create(
**module_dict,
service_name="Building Heating System",
service_description="Building Heating System Service",
service_code="SR-BLD-HTS",
)
Services.find_or_create(
**module_dict,
service_name="Building Security System",
service_description="Building Security System Service",
service_code="SR-BLD-SEC",
)
Services.find_or_create(
**module_dict,
service_name="Building Maintenance",
service_description="Building Maintenance Service",
service_code="SR-BLD-MNT",
)
Services.find_or_create(
**module_dict,
service_name="Building Repair",
service_description="Building Repair Service",
service_code="SR-BLD-RPR",
)
Services.find_or_create(
**module_dict,
service_name="Building Observation",
service_description="Building Observation Service",
service_code="SR-BLD-OBS",
)
return
def create_services_flat(module_dict: dict):
"""
11. Service [Daire] Kiralama + OPTIONAL
12. Service [Daire] Satış + OPTIONAL
13. Service [Daire] Tadiilat + OPTIONAL
14. Service [Daire] Temizlik + OPTIONAL
11 Service [Daire] Gözlem + OPTIONAL
"""
Services.find_or_create(
**module_dict,
service_name="Flat Rent",
service_description="Flat Rent Service",
service_code="SR-FLT-RNT",
)
Services.find_or_create(
**module_dict,
service_name="Flat Sale",
service_description="Flat Sale Service",
service_code="SR-FLT-SAL",
)
Services.find_or_create(
**module_dict,
service_name="Flat Renovation",
service_description="Flat Renovation Service",
service_code="SR-FLT-RNV",
)
Services.find_or_create(
**module_dict,
service_name="Flat Cleaning",
service_description="Flat Cleaning Service",
service_code="SR-FLT-CLN",
)
Services.find_or_create(
**module_dict,
service_name="Flat Observation",
service_description="Flat Observation Service",
service_code="SR-FLT-OBS",
)
return
def create_services_authenticate(module_dict: dict):
authentication_service = Services.find_or_create(
**module_dict,
service_name="Authenticate",
service_description="Authenticate Service",
service_code="AUTH",
)
return
def create_services_meeting(module_dict: dict):
Services.find_or_create(
**module_dict,
service_name="Meeting Regular",
service_description="Regular Meeting Service",
service_code="MEET-REG",
)
Services.find_or_create(
**module_dict,
service_name="Meeting Emergency",
service_description="Emergency Meeting Service",
service_code="MEET-EMR",
)
Services.find_or_create(
**module_dict,
service_name="Meeting Demand",
service_description="Demand Meeting Service",
service_code="MEET-DMN",
)
return
def create_modules_and_services_and_actions():
erp_module = Modules.find_or_create(
**{
"module_name": "EVYOS ERP",
"module_description": "EVYOS Enterprise Resource Planning",
"module_code": "EVYOS-ERP",
"module_layer": 1,
"is_default_module": False,
"is_confirmed": True,
}
)
build_module = Modules.find_or_create(
**{
"module_name": "Bina Yönetim Modülü",
"module_description": "Building Management Module",
"module_code": "BLD-MNG",
"module_layer": 1,
"is_default_module": False,
"is_confirmed": True,
}
)
user_module = Modules.find_or_create(
**{
"module_name": "Kullancı Modülü",
"module_description": "Kullanıcı Genel Modülü",
"module_code": "USR-PUB",
"module_layer": 1,
"is_default_module": True,
"is_confirmed": True,
}
)
erp_module_module_dict = dict(
module_id=erp_module.id,
module_uu_id=str(erp_module.uu_id),
is_confirmed=True,
)
build_module_module_dict = dict(
module_id=build_module.id,
module_uu_id=str(build_module.uu_id),
is_confirmed=True,
)
user_module_module_dict = dict(
module_id=user_module.id,
module_uu_id=str(user_module.uu_id),
is_confirmed=True,
)
duty_objects = Duty.filter_all(
Duty.duty_code.notin_(["BULK", "OCCUPANT", "BM0001"])
)
for duty_object in duty_objects.data:
Services.find_or_create(
**erp_module_module_dict,
service_name=duty_object.duty_name,
service_description=duty_object.duty_description,
service_code=f"SRE-{duty_object.duty_code}",
)
occupant_types = OccupantTypes.filter_all()
for occupant_type in occupant_types.data:
Services.find_or_create(
**build_module_module_dict,
service_name=occupant_type.occupant_type,
service_description=occupant_type.occupant_description,
service_code=f"SRO-{occupant_type.occupant_code}",
)
create_services_authenticate(module_dict=user_module_module_dict)
create_services_meeting(module_dict=build_module_module_dict)
create_services_building(module_dict=build_module_module_dict)
create_services_flat(module_dict=build_module_module_dict)
return
#
# super_admin_module_created=None
# create_address_service(add_module=super_admin_module_created)
# create_post_code_service(add_module=super_admin_module_created)
# create_authentication_service(add_module=super_admin_module_created)
# create_build_service(add_module=super_admin_module_created)
# create_build_parts_service(add_module=super_admin_module_created)
# create_build_area_service(add_module=super_admin_module_created)
# create_build_sites_service(add_module=super_admin_module_created)
# # create_build_types_service(add_module=super_admin_module_created)
# create_living_spaces_service(add_module=super_admin_module_created)
# create_company_service(add_module=super_admin_module_created)
# create_department_service(add_module=super_admin_module_created)
# create_duties_service(add_module=super_admin_module_created)
# create_duty_service(add_module=super_admin_module_created)
# create_employee_service(add_module=super_admin_module_created)
# create_staff_service(add_module=super_admin_module_created)
#
# create_decision_book_service(add_module=super_admin_module_created)
# create_decision_book_items_service(add_module=super_admin_module_created)
# create_build_decision_book_items_debits_service(
# add_module=super_admin_module_created
# )
# # create_build_decision_book_person_service(add_module=super_admin_module_created)
# # create_build_decision_book_person_service(add_module=super_admin_module_created)
#
# create_actions_service(add_module=super_admin_module_created)
# create_events_service(add_module=super_admin_module_created)
# create_model_service(add_module=super_admin_module_created)
# create_model_entities_service(add_module=super_admin_module_created)
# create_modules_service(add_module=super_admin_module_created)
# create_services_service(add_module=super_admin_module_created)
# create_event_to_bind_people_service(add_module=super_admin_module_created)
# create_bind_service_service(add_module=super_admin_module_created)
#
# create_people_service(add_module=super_admin_module_created)
# create_project_decision_book_service(add_module=super_admin_module_created)
# create_project_decision_book_items_service(add_module=super_admin_module_created)
# create_build_project_decision_book_items_debits_service(
# add_module=super_admin_module_created
# )
# create_build_project_decision_book_person_service(
# add_module=super_admin_module_created
# )
# create_endpoint_restriction_service(add_module=super_admin_module_created)
# create_users_service(add_module=super_admin_module_created)
#
# return
# account_service_endpoint = EndpointRestriction.find_one(
# endpoint_function="account_service"
# )
# account_service = Services.find_or_create(
# service_name="Account",
# service_description="Account Service",
# service_code="ACC",
# )
# address_service = Services.find_or_create(
# service_name="Address",
# service_description="Address Service",
# service_code="ADD",
# )
# api_service = Services.find_or_create(
# service_name="Api",
# service_description="Api Service",
# service_code="API",
# )
# application_service = Services.find_or_create(
# service_name="Application",
# service_description="Application Service",
# service_code="APP",
# )

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,9 @@
arrow
alembic
Deprecated
fastapi
python-dotenv
pydantic
sqlalchemy-mixins
psycopg2-binary
pymongo

113
service_app_init/runner.py Normal file
View File

@@ -0,0 +1,113 @@
def do_alembic():
from sqlalchemy import text
from alembic_generate import generate_alembic_with_session
generate_alembic_with_session(text=text)
def create_application_defaults_func(create_address=False):
from databases import (
AddressCity,
AddressStreet,
AddressLocality,
AddressDistrict,
AddressNeighborhood,
AddressState,
AddressCountry,
)
from initialize_app import (
create_modules_and_services_and_actions,
create_endpoints_from_api_functions,
create_all_events_from_actions,
create_application_defaults,
init_api_enums_build_types,
add_events_all_services_and_occupant_types,
add_events_to_system_super_user,
create_occupant_types_defaults,
)
create_application_defaults()
create_occupant_types_defaults()
init_api_enums_build_types()
create_endpoints_from_api_functions()
create_modules_and_services_and_actions()
if create_all_events_from_actions():
add_events_all_services_and_occupant_types()
add_events_to_system_super_user()
if not create_address:
return
confirmed_dict = {
"is_confirmed": True,
"active": True,
"is_notification_send": True,
"created_by": "System",
"confirmed_by": "System",
}
country = AddressCountry.find_or_create(
country_name="TÜRKİYE", country_code="TR", **confirmed_dict
)
state = AddressState.find_or_create(
state_name="TÜRKİYE",
state_code="TR",
phone_code="90",
country_id=country.id,
country_uu_id=str(country.uu_id),
**confirmed_dict
)
city = AddressCity.find_or_create(
city_name="ANKARA",
city_code="6",
licence_plate="06",
state_id=state.id,
state_uu_id=str(state.uu_id),
**confirmed_dict
)
district = AddressDistrict.find_or_create(
district_name="ÇANKAYA",
district_code="1231",
city_id=city.id,
city_uu_id=str(city.uu_id),
**confirmed_dict
)
locality = AddressLocality.find_or_create(
locality_name="MERKEZ",
locality_code="2431",
type_code="3",
type_description=None,
district_id=district.id,
district_uu_id=str(district.uu_id),
**confirmed_dict
)
neighborhood = AddressNeighborhood.find_or_create(
neighborhood_name="AYRANCI MAHALLESİ",
neighborhood_code="1522",
type_code="1",
type_description="MAHALLESİ",
locality_id=locality.id,
locality_uu_id=str(locality.uu_id),
**confirmed_dict
)
street = AddressStreet.find_or_create(
street_name="REŞAT NURİ CADDESİ",
type_description="CADDESİ",
type_code="3",
street_code="52270",
neighborhood_id=neighborhood.id,
neighborhood_uu_id=str(neighborhood.uu_id),
**confirmed_dict
)
return
if __name__ == "__main__":
print("service_app_init is running")
init_alembic_address = False
if init_alembic_address:
do_alembic()
create_application_defaults_func(create_address=False)