Commit 8bc945bf4929a9c2aa77e6dbf50121fd96f30c6b
Exists in
master
Merge branch 'admin' into 'master'
Admin
Showing 32 changed files Inline Diff
- __pycache__/__init__.cpython-310.pyc
- __pycache__/main.cpython-310.pyc
- __pycache__/routes.cpython-310.pyc
- components/__pycache__/__init__.cpython-310.pyc
- components/adm/README.md
- components/adm/adm/.idea/.gitignore
- components/adm/adm/.idea/adm.iml
- components/adm/adm/.idea/inspectionProfiles/Project_Default.xml
- components/adm/adm/.idea/inspectionProfiles/profiles_settings.xml
- components/adm/adm/.idea/misc.xml
- components/adm/adm/.idea/modules.xml
- components/adm/adm/.idea/vcs.xml
- components/adm/adm/__pycache__/__init__.cpython-310.pyc
- components/adm/adm/__pycache__/__init__.cpython-311.pyc
- components/adm/adm/__pycache__/models.cpython-310.pyc
- components/adm/adm/__pycache__/views.cpython-310.pyc
- components/adm/adm/__pycache__/views.cpython-311.pyc
- components/adm/adm/models.py
- components/adm/adm/views.py
- components/adm/requirements.txt
- components/adm/setup.py
- components/k2test/__pycache__/__init__.cpython-310.pyc
- components/k2test/k2test/__pycache__/__init__.cpython-310.pyc
- components/k2test/k2test/__pycache__/views.cpython-310.pyc
- components/k2test/k2test/views.py
- db/database.db
- k2/__pycache__/__init__.cpython-310.pyc
- k2/__pycache__/k2cfg.cpython-310.pyc
- k2/__pycache__/k2inst.cpython-310.pyc
- k2/__pycache__/k2obj.cpython-310.pyc
- main.py
- routes.py
__pycache__/__init__.cpython-310.pyc
No preview for this file type
__pycache__/main.cpython-310.pyc
No preview for this file type
__pycache__/routes.cpython-310.pyc
No preview for this file type
components/__pycache__/__init__.cpython-310.pyc
No preview for this file type
components/adm/README.md
| File was created | 1 | # main.py | |
| 2 | |||
| 3 | from components.adm.adm.views import adm | ||
| 4 | from components.test.test.views import test | ||
| 5 | |||
| 6 | app.register_blueprint(adm, url_prefix='/adm') | ||
| 7 | |||
| 8 | cd components/adm | ||
| 9 | pip install -r requirements.txt | ||
| 10 | |||
| 11 | |||
| 12 | endpoint "http://127.0.0.1:5000/adm/register" | ||
| 13 | dictionary to register in such way | ||
| 14 | { | ||
| 15 | "login": "xxx", | ||
| 16 | "password": "xxx", | ||
| 17 | "name": "xxx", | ||
| 18 | "email": "xxx" | ||
| 19 | } | ||
| 20 | |||
| 21 | |||
| 22 | endpoint "http://127.0.0.1:5000/adm/login" | ||
| 23 | dictionary to login in such way | ||
| 24 | { | ||
| 25 | "login":"xxx", | ||
| 26 | "password":"xxx" | ||
| 27 | } | ||
| 28 | |||
| 29 | endpoint http://127.0.0.1:5000/adm/changePassword | ||
| 30 | dictionary to changePassword in such way | ||
| 31 | { | ||
| 32 | "old_password":"xxx", | ||
| 33 | "new_password": "xxx", | ||
| 34 | "re_new_password": "xxx" | ||
| 35 | } | ||
| 36 | endpoint http://127.0.0.1:5000/adm/newUser | ||
| 37 | { | ||
| 38 | "login": "xxx", | ||
| 39 | "password": "xxx", | ||
| 40 | "name": "xxx", | ||
| 41 | "email": "xxx", | ||
| 42 | "phone": "xxx", | ||
| 43 | "repassword": "xxx" | ||
| 44 | |||
| 45 | } |
components/adm/adm/.idea/.gitignore
| File was created | 1 | # Default ignored files | |
| 2 | /shelf/ | ||
| 3 | /workspace.xml | ||
| 4 | # Editor-based HTTP Client requests | ||
| 5 | /httpRequests/ | ||
| 6 | # Datasource local storage ignored files | ||
| 7 | /dataSources/ | ||
| 8 | /dataSources.local.xml | ||
| 9 |
components/adm/adm/.idea/adm.iml
| File was created | 1 | <?xml version="1.0" encoding="UTF-8"?> | |
| 2 | <module type="PYTHON_MODULE" version="4"> | ||
| 3 | <component name="NewModuleRootManager"> | ||
| 4 | <content url="file://$MODULE_DIR$" /> | ||
| 5 | <orderEntry type="inheritedJdk" /> | ||
| 6 | <orderEntry type="sourceFolder" forTests="false" /> | ||
| 7 | </component> | ||
| 8 | <component name="TemplatesService"> | ||
| 9 | <option name="TEMPLATE_CONFIGURATION" value="Jinja2" /> | ||
| 10 | <option name="TEMPLATE_FOLDERS"> | ||
| 11 | <list> | ||
| 12 | <option value="$MODULE_DIR$/templates" /> | ||
| 13 | </list> | ||
| 14 | </option> | ||
| 15 | </component> | ||
| 16 | </module> |
components/adm/adm/.idea/inspectionProfiles/Project_Default.xml
| File was created | 1 | <component name="InspectionProjectProfileManager"> | |
| 2 | <profile version="1.0"> | ||
| 3 | <option name="myName" value="Project Default" /> | ||
| 4 | <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" /> | ||
| 5 | <inspection_tool class="JSHint" enabled="true" level="ERROR" enabled_by_default="true" /> | ||
| 6 | <inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true"> | ||
| 7 | <option name="ignoredPackages"> | ||
| 8 | <value> | ||
| 9 | <list size="13"> | ||
| 10 | <item index="0" class="java.lang.String" itemvalue="blinker" /> | ||
| 11 | <item index="1" class="java.lang.String" itemvalue="greenlet" /> | ||
| 12 | <item index="2" class="java.lang.String" itemvalue="Werkzeug" /> | ||
| 13 | <item index="3" class="java.lang.String" itemvalue="Flask-WTF" /> | ||
| 14 | <item index="4" class="java.lang.String" itemvalue="SQLAlchemy" /> | ||
| 15 | <item index="5" class="java.lang.String" itemvalue="MarkupSafe" /> | ||
| 16 | <item index="6" class="java.lang.String" itemvalue="click" /> | ||
| 17 | <item index="7" class="java.lang.String" itemvalue="Flask-SQLAlchemy" /> | ||
| 18 | <item index="8" class="java.lang.String" itemvalue="Jinja2" /> | ||
| 19 | <item index="9" class="java.lang.String" itemvalue="Flask-Login" /> | ||
| 20 | <item index="10" class="java.lang.String" itemvalue="WTForms" /> | ||
| 21 | <item index="11" class="java.lang.String" itemvalue="itsdangerous" /> | ||
| 22 | <item index="12" class="java.lang.String" itemvalue="Flask" /> | ||
| 23 | </list> | ||
| 24 | </value> | ||
| 25 | </option> | ||
| 26 | </inspection_tool> | ||
| 27 | </profile> | ||
| 28 | </component> |
components/adm/adm/.idea/inspectionProfiles/profiles_settings.xml
| File was created | 1 | <component name="InspectionProjectProfileManager"> | |
| 2 | <settings> | ||
| 3 | <option name="USE_PROJECT_PROFILE" value="false" /> | ||
| 4 | <version value="1.0" /> | ||
| 5 | </settings> | ||
| 6 | </component> |
components/adm/adm/.idea/misc.xml
| File was created | 1 | <?xml version="1.0" encoding="UTF-8"?> | |
| 2 | <project version="4"> | ||
| 3 | <component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" /> | ||
| 4 | </project> |
components/adm/adm/.idea/modules.xml
| File was created | 1 | <?xml version="1.0" encoding="UTF-8"?> | |
| 2 | <project version="4"> | ||
| 3 | <component name="ProjectModuleManager"> | ||
| 4 | <modules> | ||
| 5 | <module fileurl="file://$PROJECT_DIR$/.idea/adm.iml" filepath="$PROJECT_DIR$/.idea/adm.iml" /> | ||
| 6 | </modules> | ||
| 7 | </component> | ||
| 8 | </project> |
components/adm/adm/.idea/vcs.xml
| File was created | 1 | <?xml version="1.0" encoding="UTF-8"?> | |
| 2 | <project version="4"> | ||
| 3 | <component name="VcsDirectoryMappings"> | ||
| 4 | <mapping directory="$PROJECT_DIR$/.." vcs="Git" /> | ||
| 5 | </component> | ||
| 6 | </project> |
components/adm/adm/__pycache__/__init__.cpython-310.pyc
No preview for this file type
components/adm/adm/__pycache__/__init__.cpython-311.pyc
No preview for this file type
components/adm/adm/__pycache__/models.cpython-310.pyc
No preview for this file type
components/adm/adm/__pycache__/views.cpython-310.pyc
No preview for this file type
components/adm/adm/__pycache__/views.cpython-311.pyc
No preview for this file type
components/adm/adm/models.py
| File was created | 1 | import uuid | |
| 2 | from sqlalchemy import Column, Integer, String | ||
| 3 | from sqlalchemy.ext.declarative import declarative_base | ||
| 4 | from flask_jwt_extended import create_access_token | ||
| 5 | from datetime import timedelta | ||
| 6 | import hashlib | ||
| 7 | from flask import current_app as k2 | ||
| 8 | |||
| 9 | |||
| 10 | Base = declarative_base() | ||
| 11 | |||
| 12 | class k2users(Base): | ||
| 13 | __tablename__ = 'k2users' | ||
| 14 | user_id = Column(Integer, primary_key=True) | ||
| 15 | login = Column(String(50)) | ||
| 16 | name = Column(String(50)) | ||
| 17 | email = Column(String(150)) | ||
| 18 | password = Column(String(50)) | ||
| 19 | phone = Column(String(20)) | ||
| 20 | |||
| 21 | def __init__(self, **kwargs): | ||
| 22 | self.user_id = hashlib.md5(str(uuid.uuid4()).encode()).hexdigest() | ||
| 23 | self.login = kwargs.get('login') | ||
| 24 | self.password = hashlib.md5(kwargs.get('password').encode()).hexdigest() | ||
| 25 | self.name = kwargs.get('name') | ||
| 26 | self.email = kwargs.get('email') | ||
| 27 | self.phone = kwargs.get('phone') | ||
| 28 | |||
| 29 | def get_token(self, expire_time=24): | ||
| 30 | expires_delta = timedelta(expire_time) | ||
| 31 | token = create_access_token(identity=self.user_id, expires_delta=expires_delta) | ||
| 32 | return token | ||
| 33 | |||
| 34 | @classmethod | ||
| 35 | def authenticate(cls, login, password): | ||
| 36 | session = k2.extensions['sqlalchemy'].db.session | ||
| 37 | user = '' | ||
| 38 | try: | ||
| 39 | user = session.query(cls).filter(cls.login == login).filter(cls.password == hashlib.md5(password.encode()).hexdigest()).one() | ||
| 40 | except: | ||
| 41 | user = None | ||
| 42 | |||
| 43 | return user |
components/adm/adm/views.py
| File was created | 1 | import hashlib | |
| 2 | import uuid | ||
| 3 | from flask import Blueprint, request, jsonify | ||
| 4 | from flask import current_app as k2 | ||
| 5 | from flask_jwt_extended import jwt_required, get_jwt_identity | ||
| 6 | # from flask_sqlalchemy import session | ||
| 7 | # from sqlalchemy.orm import sessionmaker | ||
| 8 | # from k2.k2inst import Component | ||
| 9 | |||
| 10 | from .models import k2users | ||
| 11 | |||
| 12 | |||
| 13 | adm = Blueprint('adm', __name__, template_folder='templates', static_folder='static', static_url_path='/adm') | ||
| 14 | |||
| 15 | |||
| 16 | @adm.route('/register', methods=["POST"]) | ||
| 17 | def register(): | ||
| 18 | params = request.json | ||
| 19 | session = k2.extensions['sqlalchemy'].db.session | ||
| 20 | try: | ||
| 21 | user = k2users(**params) | ||
| 22 | session.add(user) | ||
| 23 | session.commit() | ||
| 24 | token = user.get_token() | ||
| 25 | return {'access_token': token} | ||
| 26 | except: | ||
| 27 | return jsonify({'error': 'Unauthorized'}), 401 | ||
| 28 | |||
| 29 | |||
| 30 | @adm.route('/login', methods=["POST"]) | ||
| 31 | def login(): | ||
| 32 | params = request.json | ||
| 33 | login = params.get('login') | ||
| 34 | password = params.get('password') | ||
| 35 | user = k2users.authenticate(login, password) | ||
| 36 | if user: | ||
| 37 | token = user.get_token() | ||
| 38 | return {'access_token': token} | ||
| 39 | else: | ||
| 40 | return jsonify({'error': 'Unauthorized'}), 401 | ||
| 41 | |||
| 42 | |||
| 43 | @adm.route('/logout', methods=["GET"]) | ||
| 44 | @jwt_required() | ||
| 45 | def logout(): | ||
| 46 | response = { | ||
| 47 | 'message': 'Logged out successfully' | ||
| 48 | } | ||
| 49 | return jsonify(response) | ||
| 50 | |||
| 51 | |||
| 52 | @adm.route('/users', methods=["GET"]) | ||
| 53 | @jwt_required() | ||
| 54 | def grid_users(): | ||
| 55 | return jsonify({"data": "users"}) | ||
| 56 | |||
| 57 | |||
| 58 | @adm.route('/roles', methods=["GET"]) | ||
| 59 | @jwt_required() | ||
| 60 | def grid_roles(): | ||
| 61 | return jsonify({"data": "roles"}) | ||
| 62 | |||
| 63 | |||
| 64 | @adm.route('/usersclients', methods=["GET"]) | ||
| 65 | @jwt_required() | ||
| 66 | def users_clients(): | ||
| 67 | return jsonify({"data": "roles"}) | ||
| 68 | |||
| 69 | @adm.route('/menuaaccess', methods=["GET"]) | ||
| 70 | @jwt_required() | ||
| 71 | def menu_aaccess(): | ||
| 72 | return jsonify({"data": "roles"}) | ||
| 73 | |||
| 74 | |||
| 75 | @adm.route('/newUser', methods=["GET", "POST"]) | ||
| 76 | @jwt_required() | ||
| 77 | def newUser(): | ||
| 78 | session = k2.extensions['sqlalchemy'].db.session | ||
| 79 | exist = session.query(k2users).filter_by(login=request.json['login']).first() | ||
| 80 | if not exist: | ||
| 81 | res = k2users( | ||
| 82 | user_id=hashlib.md5(str(uuid.uuid4()).encode()).hexdigest(), | ||
| 83 | login=request.json['login'], | ||
| 84 | name=request.json['name'], | ||
| 85 | email=request.json['email'], | ||
| 86 | password=hashlib.md5(request.json['password'].encode()).hexdigest(), | ||
| 87 | phone=request.json['phone']) | ||
| 88 | if res: | ||
| 89 | session.add(res) | ||
| 90 | session.commit() | ||
| 91 | return jsonify({'status': 'ok'}) | ||
| 92 | else: | ||
| 93 | return jsonify({'error': 'Such user exist'}), 404 | ||
| 94 | |||
| 95 | |||
| 96 | @adm.route('/changePassword', methods=["POST"]) | ||
| 97 | @jwt_required() | ||
| 98 | def changePassword(): | ||
| 99 | session = k2.extensions['sqlalchemy'].db.session | ||
| 100 | current_user = get_jwt_identity() | ||
| 101 | user = session.query(k2users).filter_by(user_id=current_user).first() | ||
| 102 | if user.password == hashlib.md5(request.json['old_password'].encode()).hexdigest(): | ||
| 103 | if request.json['new_password'] == request.json['re_new_password']: | ||
| 104 | user.password = hashlib.md5(request.json['new_password'].encode()).hexdigest() | ||
| 105 | session.commit() | ||
| 106 | else: | ||
| 107 | return jsonify({'error': 'Пароль не найден в базе'}), 404 | ||
| 108 | else: | ||
| 109 | return jsonify({'error': 'Пароль не совпвдает'}), 404 | ||
| 110 | return jsonify({'status': 'ok'}) | ||
| 111 | |||
| 112 | |||
| 113 | @adm.route('/menu-items') | ||
| 114 | def menu_items(): | ||
| 115 | menu = [ | ||
| 116 | {"heading": 'APPS & PAGES'}, | ||
| 117 | { | ||
| 118 | "title": 'Адміністрування сайту', | ||
| 119 | |||
| 120 | "icon": {"icon": 'mdi mdi-database'}, | ||
| 121 | "children": [ | ||
| 122 | {'title': 'Зміна паролю', 'to': 'adm-changePassword'}, | ||
| 123 | {'title': 'Новий користувач', 'to': 'adm-newUser'}, | ||
| 124 | {'title': 'Користувачі', 'to': 'adm-users'}, | ||
| 125 | {'title': 'Користувачі клієнти', 'to': 'adm-usersclients'}, | ||
| 126 | {'title': 'Права', 'to': 'adm-roles'}, | ||
| 127 | {'title': 'Доступ до меню', 'to': 'adm-menuaaccess'}, | ||
| 128 | ], | ||
| 129 | }] | ||
| 130 | |||
| 131 | return menu | ||
| 132 | |||
| 133 | |||
| 134 | |||
| 135 | |||
| 136 | |||
| 137 |
components/adm/requirements.txt
| File was created | 1 | blinker==1.6.2 | |
| 2 | click==8.1.3 | ||
| 3 | dnspython==2.3.0 | ||
| 4 | email-validator==2.0.0.post2 | ||
| 5 | Flask==2.3.2 | ||
| 6 | Flask-Cors==3.0.10 | ||
| 7 | Flask-JWT-Extended==4.5.2 | ||
| 8 | Flask-Login==0.6.2 | ||
| 9 | Flask-Mail==0.9.1 | ||
| 10 | Flask-MySQLdb==1.0.1 | ||
| 11 | Flask-SQLAlchemy==3.0.3 | ||
| 12 | flask-staticdirs==1.0.1 | ||
| 13 | Flask-WTF==1.1.1 | ||
| 14 | greenlet==2.0.2 | ||
| 15 | idna==3.4 | ||
| 16 | itsdangerous==2.1.2 | ||
| 17 | Jinja2==3.1.2 | ||
| 18 | jsonify==0.5 | ||
| 19 | MarkupSafe==2.1.2 | ||
| 20 | mysql-connector-python==8.0.33 | ||
| 21 | mysqlclient==2.1.1 | ||
| 22 | protobuf==3.20.3 | ||
| 23 | PyJWT==2.7.0 | ||
| 24 | pytz==2023.3 | ||
| 25 | PyYAML==6.0 | ||
| 26 | six==1.16.0 | ||
| 27 | SQLAlchemy==2.0.15 | ||
| 28 | typing_extensions==4.6.2 | ||
| 29 | Werkzeug==2.3.4 | ||
| 30 | WTForms==3.0.1 | ||
| 31 |
components/adm/setup.py
| File was created | 1 | from setuptools import setup | |
| 2 | |||
| 3 | setup( | ||
| 4 | name='adm', | ||
| 5 | version='1.0.0', | ||
| 6 | description='Description of my project', | ||
| 7 | author='Your Name', | ||
| 8 | author_email='yourname@example.com', | ||
| 9 | keywords="adm, k2", | ||
| 10 | python_requires=">=3.7, <=3.11.2", | ||
| 11 | packages=['adm'], | ||
| 12 | package_data={ # Optional | ||
| 13 | }, | ||
| 14 | install_requires=[""], | ||
| 15 | ) |
components/k2test/__pycache__/__init__.cpython-310.pyc
No preview for this file type
components/k2test/k2test/__pycache__/__init__.cpython-310.pyc
No preview for this file type
components/k2test/k2test/__pycache__/views.cpython-310.pyc
No preview for this file type
components/k2test/k2test/views.py
| 1 | from flask import render_template, redirect, request | 1 | from flask import render_template, redirect, request |
| 2 | from flask_login import login_user, current_user, logout_user, login_required | 2 | from flask_login import login_user, current_user, logout_user, login_required |
| 3 | from flask import current_app as k2 | 3 | from flask import current_app as k2 |
| 4 | from flask import Blueprint, json | 4 | from flask import Blueprint, json |
| 5 | from flask_sqlalchemy import SQLAlchemy | 5 | from flask_sqlalchemy import SQLAlchemy |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | k2test = Blueprint('k2test', __name__, template_folder='templates', static_folder='static',) | 9 | k2test = Blueprint('k2test', __name__, template_folder='templates', static_folder='static',) |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | @k2test.route('/new') | 13 | @k2test.route('/new') |
| 14 | def new_component(): | 14 | def new_component(): |
| 15 | db = k2.extensions['sqlalchemy'].db | 15 | db = k2.extensions['sqlalchemy'].db |
| 16 | connection = db.engine.connect() | 16 | connection = db.engine.connect() |
| 17 | query = db.text("SELECT email, login FROM k2users") | 17 | query = db.text("SELECT email, login FROM k2users") |
| 18 | result = connection.execute(query).fetchall() | 18 | result = connection.execute(query).fetchall() |
| 19 | rows = [dict(email=row.email, login=row.login) for row in result] | 19 | rows = [dict(email=row.email, login=row.login) for row in result] |
| 20 | # Перетворення результату на JSON | 20 | # Перетворення результату на JSON |
| 21 | json_result = json.dumps(rows) | 21 | json_result = json.dumps(rows) |
| 22 | return json_result | 22 | return json_result |
| 23 | 23 | ||
| 24 | @k2test.route('/new2') | 24 | @k2test.route('/new2') |
| 25 | def new_component2(): | 25 | def new_component2(): |
| 26 | return render_template('new2.html') | 26 | return render_template('new2.html') |
| 27 | 27 | ||
| 28 | @k2test.route('/new3') | 28 | @k2test.route('/new3') |
| 29 | def new_component3(): | 29 | def new_component3(): |
| 30 | return 'сторінка 3' | 30 | return 'сторінка 3' |
| 31 | 31 | ||
| 32 | @k2test.route('/new4') | 32 | @k2test.route('/new4') |
| 33 | def new_component4(): | 33 | def new_component4(): |
| 34 | return 'сторінка 4' | 34 | return 'сторінка 4' |
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | @k2test.route('/menu-items') | 37 | @k2test.route('/menu-items') |
| 38 | def menu_items(): | 38 | def menu_items(): |
| 39 | data = [ | 39 | data = [ |
| 40 | { | 40 | { |
| 41 | 41 | ||
| 42 | 'title': 'Тестова компонента', | 42 | 'title': 'Тестова компонента', |
| 43 | 'category': 'Тест', | 43 | 'category': 'Тест', |
| 44 | 'icon': {'icon': 'mdi-chart-timeline-variant'}, | 44 | 'icon': {'icon': 'mdi-chart-timeline-variant'}, |
| 45 | 'children': [ | 45 | 'children': [ |
| 46 | {'title': 'Тест 3', 'to': 'k2test-new3'}, | 46 | {'title': 'Тест 3', 'to': 'k2test-new3'}, |
| 47 | {'title': 'Тест 3', 'to': 'k2test-new4'}, | 47 | {'title': 'Тест 3', 'to': 'k2test-new4'}, |
| 48 | ], | 48 | ], |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | ] | 51 | ] |
| 52 | return data | 52 | return data |
db/database.db
No preview for this file type
k2/__pycache__/__init__.cpython-310.pyc
No preview for this file type
k2/__pycache__/k2cfg.cpython-310.pyc
No preview for this file type
k2/__pycache__/k2inst.cpython-310.pyc
No preview for this file type
k2/__pycache__/k2obj.cpython-310.pyc
No preview for this file type
main.py
| 1 | from flask_cors import CORS | 1 | from flask_cors import CORS |
| 2 | from flask_babel import Babel | 2 | from flask_babel import Babel |
| 3 | from flask_jwt_extended import JWTManager | ||
| 3 | #from k2.k2inst import * | 4 | #from k2.k2inst import * |
| 4 | from flask import Flask | 5 | from flask import Flask |
| 5 | from k2.k2cfg import k2 | 6 | from k2.k2cfg import k2 |
| 6 | 7 | ||
| 7 | # configure flask app | 8 | # configure flask app |
| 8 | app = Flask(__name__) | 9 | app = Flask(__name__) |
| 9 | app.config['SECRET_KEY'] = k2.secret_key | 10 | app.config['SECRET_KEY'] = k2.secret_key |
| 11 | |||
| 10 | #app.config.from_object(k2) | 12 | #app.config.from_object(k2) |
| 11 | 13 | ||
| 12 | # init db | 14 | # init db |
| 13 | k2().init_db(app) | 15 | k2().init_db(app) |
| 14 | CORS(app) | 16 | CORS(app) |
| 17 | jwt = JWTManager(app) | ||
| 15 | 18 | ||
| 16 | #translate | 19 | #translate |
| 17 | k2.load_babel_translation_directories() | 20 | k2.load_babel_translation_directories() |
| 18 | app.config['BABEL_TRANSLATION_DIRECTORIES'] = k2.babel_translation_directories | 21 | app.config['BABEL_TRANSLATION_DIRECTORIES'] = k2.babel_translation_directories |
| 19 | babel = Babel(app) | 22 | babel = Babel(app) |
| 20 | babel.init_app(app, locale_selector=k2.get_locale) | 23 | babel.init_app(app, locale_selector=k2.get_locale) |
| 21 | 24 | ||
| 22 | #menu | 25 | #menu |
| 23 | k2.get_menu_elenents() | 26 | k2.get_menu_elenents() |
| 24 | 27 | ||
| 25 | # flask routing | 28 | # flask routing |
| 26 | from routes import * | 29 | from routes import * |
| 27 | 30 | ||
| 28 | if __name__ == '__main__': | 31 | if __name__ == '__main__': |
| 29 | app.run(debug=True, port=5000) | 32 | app.run(debug=True, port=5000) |
| 30 | 33 | ||
| 31 | 34 | ||
| 32 | 35 | ||
| 33 | 36 | ||
| 37 | |||
| 38 |
routes.py
| 1 | from flask import Flask | 1 | from flask import Flask |
| 2 | #app = Flask(__name__) | 2 | #app = Flask(__name__) |
| 3 | from main import app, babel | 3 | from main import app, babel |
| 4 | from k2.k2inst import components_bp | 4 | from k2.k2inst import components_bp |
| 5 | app.register_blueprint(components_bp) | 5 | app.register_blueprint(components_bp) |
| 6 | 6 | ||
| 7 | from components.k2test.k2test.views import k2test | 7 | from components.k2test.k2test.views import k2test |
| 8 | app.register_blueprint(k2test, url_prefix='/k2test') | 8 | app.register_blueprint(k2test, url_prefix='/k2test') |
| 9 | |||
| 10 | from components.adm.adm.views import adm | ||
| 11 | app.register_blueprint(adm, url_prefix='/adm') | ||
| 9 | 12 |