diff --git a/FoodyCore/__init__.py b/FoodyCore/__init__.py index f5e63c0..d4edba2 100644 --- a/FoodyCore/__init__.py +++ b/FoodyCore/__init__.py @@ -23,7 +23,6 @@ def create_app(): MailServer.init_app(app=app) celery_init_app(app=app) - # register blueprints (apps) from FoodyOrder import order app.register_blueprint(order, url_prefix="/order") diff --git a/FoodyCore/baseView.py b/FoodyCore/baseView.py index 975289b..e67892d 100644 --- a/FoodyCore/baseView.py +++ b/FoodyCore/baseView.py @@ -6,13 +6,6 @@ import FoodyAuth.utils as AuthUtils -# @app.after_request -# def after_request(f): -# add custom headers to response (or configure nginx) -# additional header data and ... -# f.headers['X-Frame-Options'] = 'SAMEORIGIN' -# return f - @app.before_request def before_request(): @@ -20,7 +13,6 @@ def before_request(): This Middleware like django authentication put some data in request before heads up to actual view :return: None - is_userAuthenticated = True : if user is authenticated is_userAuthenticated = False : if user is not authenticated @@ -80,7 +72,7 @@ def generate_uuid() -> str: def serve_app_logo() -> str: """ this view serve app logo - if there is no image set for app logo + if there is no image return default logo image """ if (site := SiteSetting.query.filter_by(tag="setting").first()): diff --git a/FoodyUser/views.py b/FoodyUser/views.py index ea0284e..99bfec2 100644 --- a/FoodyUser/views.py +++ b/FoodyUser/views.py @@ -1,3 +1,4 @@ +# build in import os.path import khayyam @@ -15,8 +16,8 @@ @user.route("/UserStatic/") @login_required -def UserStatic(filename): - """Serve Static files to users that have access""" +def UserStatic(filename:str): + """Serve static files to users that authenticated.""" if os.path.exists(User_Static / filename): return send_from_directory(User_Static, filename) else: @@ -24,58 +25,61 @@ def UserStatic(filename): -@user.get("/") +@user.route("/", methods=['GET']) @login_required -def index_view(): +def index_view() -> str: + """return user index page """ return render_template("user/index.html") @user.route("/menu/", methods=["GET"]) @login_required -def get_menu(): - """return food menu for user""" +def get_menu() -> str: + """return food menu page""" ctx = {} - ctx["foods"] = FoodList.query.filter(FoodList.Active == True).all() + ctx["foods"] = FoodList.query.filter_by(Active=True).all() return render_template("user/menu.html", ctx=ctx) @user.route("/order/", methods=["GET"]) @login_required -def order_get(): +def order_get() -> str: + """return ordering page """ return render_template("user/order.html") @user.route("/history/", methods=["GET"]) @login_required -def history_get(): +def history_get() -> str: + """return orders history """ page = request.args.get("page", type=int, default=1) - ctx = { - "orders": Order.query.order_by(Order.OrderDate.desc()).filter(Order.UserID == request.user_object.id).paginate(per_page=15, page=page), - "current_page":page - } + ctx = {"current_page":page} + + ctx["orders"] = Order.query.order_by(Order.OrderDate.desc()) \ + .filter_by(UserID=request.user_object.id) \ + .paginate(per_page=15, page=page) + return render_template("user/history.html", ctx=ctx) @user.route("/panel/", methods=["GET"]) @login_required -def panel_get(): - """ - This View return Template For User Panel - """ +def panel_get() -> str: + """return users panel page""" Today = khayyam.JalaliDate.today() t = TimeStamp() startofMonth = t.convert_jlj2_georgian_d(khayyam.JalaliDate(year=Today.year, month=Today.month, day=1)) endofMonth = t.convert_jlj2_georgian_d(khayyam.JalaliDate(year=Today.year, month=Today.month, day=Today.daysinmonth)) - userDB = request.user_object # get user object from db + user = request.user_object # get user object form = UserPanelEmailForm() - form.Email.data = userDB.Email or "" + form.Email.data = user.Email or "" ctx = { - "user":request.user_object, - "this_month_orders": Order.query.filter(Order.UserID == request.user_object.id).filter(Order.OrderDate >= startofMonth).filter(Order.OrderDate <= endofMonth).count() + "user": request.user_object, + "this_month_orders": Order.query.filter(Order.UserID == user.id).filter(Order.OrderDate >= startofMonth).filter(Order.OrderDate <= endofMonth).count() } return render_template("user/panel.html", ctx=ctx, form=form) @@ -84,29 +88,26 @@ def panel_get(): @user.route("/panel/", methods=["POST"]) @login_required def panel_post(): - """ - this view take a post request for Updating User Email Address in panel - """ + """updating users information in their panel""" - userDB = request.user_object # get user object from db + user = request.user_object # get user object form = UserPanelEmailForm() if not form.validate(): flash("برخی موارد به درستی مقدار دهی نشده اند", "danger") - error = "\n".join([form.errors[err][-1] for err in form.errors ]) + error = "\n".join([form.errors[err][-1] for err in form.errors]) if error: flash(error, "danger") return redirect(url_for('user.panel_get')) - if not userDB.SetEmailAddress(form.Email.data): + if not user.SetEmailAddress(form.Email.data): flash("آدرس ایمیل وارد شده توسط کاربر دیگری در سیستم گرفته شده است \nلطفا آدرس دیگری را وارد کنید", "danger") return redirect(url_for('user.panel_get')) try: - db.session.add(userDB) + db.session.add(user) db.session.commit() except Exception as e: - print(e) db.session.rollback() flash("خطایی هنگام ذخیره سازی رخ داد بعدا امتحان کند", "danger") else: diff --git a/FoodyWeb/template_filters.py b/FoodyWeb/template_filters.py index 3bc1804..6bb220c 100644 --- a/FoodyWeb/template_filters.py +++ b/FoodyWeb/template_filters.py @@ -12,4 +12,4 @@ def ServerRedis(name=None): return ServerRedis.get(name=name) -print("[OK] All Template Filters checked By Flask App ".capitalize()) +print("[OK] Template Filters checked. ".capitalize()) diff --git a/FoodyWeb/views.py b/FoodyWeb/views.py index 5cbf367..ca646de 100644 --- a/FoodyWeb/views.py +++ b/FoodyWeb/views.py @@ -1,5 +1,3 @@ -import os.path - from FoodyWeb import web from flask import send_from_directory, redirect, \ current_app, abort, url_for @@ -10,7 +8,7 @@ @web.route("/Serve/") def Serve(path): """ - Serve Static files for development Mode (Only When APP_DEBUG=True) + Serve Static files for development Mode (Only When APP_DEBUG is True) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Only In Debug Mode Serving Files for development Purposes """ @@ -23,9 +21,8 @@ def Serve(path): @web.route("/") def index_view(): """ - Just redirect to user login page + Just redirect user to login page You can replace this with a nice and simple landing page for you company - return render_template('path/to/landing page.html') """ return redirect(url_for('auth.login')) diff --git a/Make b/Make deleted file mode 100644 index 70d94e2..0000000 --- a/Make +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/bash - -sudo chmod 777 ./Migrate.sh diff --git a/Migrate.sh b/Migrate.sh deleted file mode 100644 index 7f45c4f..0000000 --- a/Migrate.sh +++ /dev/null @@ -1,14 +0,0 @@ -#! /usr/bin/bash - -# sudo chmod +x ./MakeMigrate - -# if migrations directory exists delete it and init -# migrations again - -if [[ "$1" == "\\" && "$2" == "migrations" ]]; then - echo "Migrations directory already exists." - rm -rf "migrations" - echo "deleting Migrations directory" -else - flask db init && flask db migrate && flask db upgrade -fi \ No newline at end of file diff --git a/deploy_to_liara.py b/deploy_to_liara.py deleted file mode 100644 index 57371a9..0000000 --- a/deploy_to_liara.py +++ /dev/null @@ -1,34 +0,0 @@ -import os -import platform - - -operating_system = platform.platform() # Linux - Windows - macOS - - -def replace_env_file(): - if operating_system == "Windows": - os.system("copy .env .env_secure ") - os.system("copy .env.liara .env") - try: - os.system("liara version") - os.system("liara deploy") - except KeyboardInterrupt: - os.system("copy .env .env.liara") - os.system("copy .env_secure .env") - else: - os.system("cp .env .env_secure ") - os.system("cp .env.liara .env") - try: - os.system("liara version") - os.system("liara deploy") - except KeyboardInterrupt: - os.system("cp .env .env.liara") - os.system("cp .env_secure .env") - -def main(): - replace_env_file() - - - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/devTODO.md b/devTODO.md deleted file mode 100644 index 5ed17fa..0000000 --- a/devTODO.md +++ /dev/null @@ -1,23 +0,0 @@ -[ ] - some Methods and function may raise an error during the app Running / time convert => form.py - -[ ] - add task queue for sending email and image process and compress (app.app_context) - -[ ] - clean import (code format) - -[ ] - compress and resize image [rq background task] - -[0] - admin should order food for users in admin panel [guest] - - -[ ] - backUP cli command + cron job - - -[x] - add Persian Date Picker (js-css only) - - -[ ] - improve ui/ux (not important at this time) - -[ ] - api view (not server side rendering) - -[ ] - monitor (user-server status and ...) - diff --git a/run-Celery.sh b/run-Celery.sh deleted file mode 100644 index e27e3cd..0000000 --- a/run-Celery.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/bash - -celery -A make_celery worker -l info -E \ No newline at end of file diff --git a/scripts/CeleryBeat.bat b/scripts/CeleryBeat.bat new file mode 100644 index 0000000..b1c5d2b --- /dev/null +++ b/scripts/CeleryBeat.bat @@ -0,0 +1 @@ +celery -A make_celery beat -l info \ No newline at end of file diff --git a/scripts/CeleryBeat.sh b/scripts/CeleryBeat.sh new file mode 100644 index 0000000..64d528c --- /dev/null +++ b/scripts/CeleryBeat.sh @@ -0,0 +1 @@ +celery -A make_celery beat -l info gevent -E \ No newline at end of file diff --git a/scripts/CeleryWorker.bat b/scripts/CeleryWorker.bat new file mode 100644 index 0000000..15603c3 --- /dev/null +++ b/scripts/CeleryWorker.bat @@ -0,0 +1 @@ +celery -A make_celery worker -l info -P gevent -E \ No newline at end of file diff --git a/scripts/CeleryWorker.sh b/scripts/CeleryWorker.sh new file mode 100644 index 0000000..c6b003e --- /dev/null +++ b/scripts/CeleryWorker.sh @@ -0,0 +1,3 @@ +echo "Starting celery workers" +sleep 1 +celery -A make_celery worker -B -l info -E diff --git a/scripts/Make.sh b/scripts/Make.sh new file mode 100644 index 0000000..bba8a61 --- /dev/null +++ b/scripts/Make.sh @@ -0,0 +1 @@ +./CeleryWorker.sh \ No newline at end of file diff --git a/scripts/MakeMigrate.bat b/scripts/MakeMigrate.bat new file mode 100644 index 0000000..f6c9e49 --- /dev/null +++ b/scripts/MakeMigrate.bat @@ -0,0 +1,3 @@ +flask db init +flask db migrate +flask db upgrade diff --git a/scripts/MakeMigrate.sh b/scripts/MakeMigrate.sh new file mode 100644 index 0000000..f6c9e49 --- /dev/null +++ b/scripts/MakeMigrate.sh @@ -0,0 +1,3 @@ +flask db init +flask db migrate +flask db upgrade diff --git a/scripts/MakeTranslate.bat b/scripts/MakeTranslate.bat new file mode 100644 index 0000000..e69de29 diff --git a/scripts/MakeTranslate.sh b/scripts/MakeTranslate.sh new file mode 100644 index 0000000..e69de29 diff --git a/scripts/Run.bat b/scripts/Run.bat new file mode 100644 index 0000000..e69de29 diff --git a/scripts/Run.sh b/scripts/Run.sh new file mode 100644 index 0000000..e69de29 diff --git a/scripts/runWaitress.bat b/scripts/runWaitress.bat new file mode 100644 index 0000000..68bb3e8 --- /dev/null +++ b/scripts/runWaitress.bat @@ -0,0 +1 @@ +waitress-serve --host 127.0.0.1 --port 8000 --ident "web-server-gateway" app:app diff --git a/scripts/upgrade_all_packages.bat b/scripts/upgrade_all_packages.bat new file mode 100644 index 0000000..5bf74c5 --- /dev/null +++ b/scripts/upgrade_all_packages.bat @@ -0,0 +1,2 @@ +pip freeze | %{$_.split("==")[0]} | %{pip install --upgrade -U $_} + diff --git a/scripts/upgrade_all_packages.sh b/scripts/upgrade_all_packages.sh new file mode 100644 index 0000000..70e8e97 --- /dev/null +++ b/scripts/upgrade_all_packages.sh @@ -0,0 +1 @@ +pip list --outdated --format=freeze | xargs -n 1 pip install -U diff --git a/waitress_runner.py b/waitress_runner.py deleted file mode 100644 index 2f948d2..0000000 --- a/waitress_runner.py +++ /dev/null @@ -1,5 +0,0 @@ -import os - -cmd = """waitress-serve --host 127.0.0.1 --port 8080 --ident "Foody WebApplication" app:app """ - -os.system(cmd) \ No newline at end of file diff --git a/winCelery.bat b/winCelery.bat deleted file mode 100644 index 46dabc6..0000000 --- a/winCelery.bat +++ /dev/null @@ -1 +0,0 @@ -celery -A make_celery worker -l info -E -P gevent \ No newline at end of file