Skip to content

Commit

Permalink
clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
alisharify7 committed Jul 1, 2024
1 parent e59f03f commit 9c05aaf
Show file tree
Hide file tree
Showing 26 changed files with 51 additions and 128 deletions.
1 change: 0 additions & 1 deletion FoodyCore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 1 addition & 9 deletions FoodyCore/baseView.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,13 @@
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():
"""
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
Expand Down Expand Up @@ -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()):
Expand Down
59 changes: 30 additions & 29 deletions FoodyUser/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# build in
import os.path
import khayyam

Expand All @@ -15,67 +16,70 @@

@user.route("/UserStatic/<path:filename>")
@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:
return "File Not Found!", 404



@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)

Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion FoodyWeb/template_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ def ServerRedis(name=None):
return ServerRedis.get(name=name)


print("[OK] All Template Filters checked By Flask App <FoodyWeb>".capitalize())
print("[OK] Template Filters checked. <FoodyWeb>".capitalize())
7 changes: 2 additions & 5 deletions FoodyWeb/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import os.path

from FoodyWeb import web
from flask import send_from_directory, redirect, \
current_app, abort, url_for
Expand All @@ -10,7 +8,7 @@
@web.route("/Serve/<path:path>")
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
"""
Expand All @@ -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'))
Expand Down
3 changes: 0 additions & 3 deletions Make

This file was deleted.

14 changes: 0 additions & 14 deletions Migrate.sh

This file was deleted.

34 changes: 0 additions & 34 deletions deploy_to_liara.py

This file was deleted.

23 changes: 0 additions & 23 deletions devTODO.md

This file was deleted.

3 changes: 0 additions & 3 deletions run-Celery.sh

This file was deleted.

1 change: 1 addition & 0 deletions scripts/CeleryBeat.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
celery -A make_celery beat -l info
1 change: 1 addition & 0 deletions scripts/CeleryBeat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
celery -A make_celery beat -l info gevent -E
1 change: 1 addition & 0 deletions scripts/CeleryWorker.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
celery -A make_celery worker -l info -P gevent -E
3 changes: 3 additions & 0 deletions scripts/CeleryWorker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
echo "Starting celery workers"
sleep 1
celery -A make_celery worker -B -l info -E
1 change: 1 addition & 0 deletions scripts/Make.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./CeleryWorker.sh
3 changes: 3 additions & 0 deletions scripts/MakeMigrate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flask db init
flask db migrate
flask db upgrade
3 changes: 3 additions & 0 deletions scripts/MakeMigrate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
flask db init
flask db migrate
flask db upgrade
Empty file added scripts/MakeTranslate.bat
Empty file.
Empty file added scripts/MakeTranslate.sh
Empty file.
Empty file added scripts/Run.bat
Empty file.
Empty file added scripts/Run.sh
Empty file.
1 change: 1 addition & 0 deletions scripts/runWaitress.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
waitress-serve --host 127.0.0.1 --port 8000 --ident "web-server-gateway" app:app
2 changes: 2 additions & 0 deletions scripts/upgrade_all_packages.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pip freeze | %{$_.split("==")[0]} | %{pip install --upgrade -U $_}

1 change: 1 addition & 0 deletions scripts/upgrade_all_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pip list --outdated --format=freeze | xargs -n 1 pip install -U
5 changes: 0 additions & 5 deletions waitress_runner.py

This file was deleted.

1 change: 0 additions & 1 deletion winCelery.bat

This file was deleted.

0 comments on commit 9c05aaf

Please sign in to comment.