Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/SalamLang/Salam
Browse files Browse the repository at this point in the history
  • Loading branch information
BaseMax committed Jan 1, 2025
2 parents d228776 + e734fec commit be5eb25
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 31 deletions.
33 changes: 18 additions & 15 deletions config/admin/app.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os
from typing import List
from typing import List, Union

import werkzeug
import yaml
from flask import Flask, Response, redirect, render_template, request, session, url_for
from flask import Flask, redirect, render_template, request, session, url_for, Response
from werkzeug.wrappers import Response as WerkzeugResponse

# Create an alias for the response type to handle both werkzeug and flask Response
ResponseType = Union[str, Response, WerkzeugResponse]

app = Flask(__name__)
app.secret_key = "your_secret_key"
Expand Down Expand Up @@ -133,7 +136,7 @@ def index() -> str:


@app.route("/edit/<path:filepath>", methods=["POST"])
def edit_file_action(filepath: str) -> werkzeug.Response:
def edit_file_action(filepath: str) -> ResponseType:
"""
Handles editing an existing YAML file by receiving new data via POST request.
Expand Down Expand Up @@ -172,7 +175,7 @@ def edit_file_action(filepath: str) -> werkzeug.Response:


@app.route("/edit/<path:filepath>", methods=["GET"])
def edit_file(filepath: str) -> str:
def edit_file(filepath: str) -> ResponseType:
"""
Displays the editing page for a given YAML file, showing the current contents.
Expand All @@ -185,7 +188,7 @@ def edit_file(filepath: str) -> str:
file_path = os.path.join(YAML_DIR, filepath)

if not os.path.exists(file_path) or not os.path.isfile(file_path):
return werkzeug.redirect(url_for("index"))
return redirect(url_for("index"))

data = read_yaml(file_path)
columns = get_dynamic_columns(data)
Expand All @@ -209,7 +212,7 @@ def edit_file(filepath: str) -> str:


@app.route("/add-file", methods=["POST"])
def add_file_action() -> str:
def add_file_action() -> ResponseType:
"""
Handles the action to add a new YAML file via POST request.
Expand All @@ -222,15 +225,15 @@ def add_file_action() -> str:
session["message"] = "Filename is required."
session["message_type"] = "error"

return werkzeug.redirect(url_for("index"))
return redirect(url_for("index"))

new_file = new_file.strip()

if new_file == "":
session["message"] = "Filename is required."
session["message_type"] = "error"

return werkzeug.redirect(url_for("index"))
return redirect(url_for("index"))

new_file = new_file.lstrip("/")

Expand All @@ -243,30 +246,30 @@ def add_file_action() -> str:
session["message"] = "Invalid filename or directory traversal attempt."
session["message_type"] = "error"

return werkzeug.redirect(url_for("index"))
return redirect(url_for("index"))

if os.path.exists(path):
session["message"] = "File already exists."
session["message_type"] = "error"

return werkzeug.redirect(url_for("index"))
return redirect(url_for("index"))

try:
write_yaml(path, {"items": []})

session["message"] = "File created."
session["message_type"] = "ok"

return werkzeug.redirect(url_for("index"))
return redirect(url_for("index"))
except Exception as e:
session["message"] = f"Failed to create file: {e}"
session["message_type"] = "error"

return werkzeug.redirect(url_for("index"))
return redirect(url_for("index"))


@app.route("/delete-file/<path:filepath>", methods=["POST"])
def delete_file_action(filepath: str) -> str:
def delete_file_action(filepath: str) -> ResponseType:
"""
Handles the deletion of a YAML file based on the provided file path.
Expand Down Expand Up @@ -294,7 +297,7 @@ def delete_file_action(filepath: str) -> str:
session["message"] = f"File '{filepath}' not found or invalid path."
session["message_type"] = "error"

return werkzeug.redirect(url_for("index"))
return redirect(url_for("index"))


if __name__ == "__main__":
Expand Down
Empty file added config/layout/__init__.py
Empty file.
Empty file.
Empty file.
4 changes: 2 additions & 2 deletions config/layout/attribute/style/global_value.validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../module"))
)

from utils import error, load_yaml
from validation import validate_item_structure
from module.utils import error, load_yaml
from module.validation import validate_item_structure

FILE = os.path.join(os.path.dirname(__file__), "global_value.yaml")
LANGUAGES = ["en", "fa"]
Expand Down
4 changes: 2 additions & 2 deletions config/layout/attribute/style/state.validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../module"))
)

from utils import error, load_yaml
from validation import validate_item_structure
from module.utils import error, load_yaml
from module.validation import validate_item_structure

FILE = os.path.join(os.path.dirname(__file__), "state.yaml")
LANGUAGES = ["en", "fa"]
Expand Down
4 changes: 2 additions & 2 deletions config/layout/attribute/style/type.validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../module"))
)

from utils import error, load_yaml
from validation import validate_item_structure
from module.utils import error, load_yaml
from module.validation import validate_item_structure

FILE = "type.yaml"
LANGUAGES = ["en", "fa"]
Expand Down
4 changes: 2 additions & 2 deletions config/layout/attribute/style/value.validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
os.path.abspath(os.path.join(os.path.dirname(__file__), "../../../module"))
)

from utils import error, load_yaml
from validation import validate_item_structure
from module.utils import error, load_yaml
from module.validation import validate_item_structure

FILE = "value.yaml"
LANGUAGES = ["en", "fa"]
Expand Down
4 changes: 2 additions & 2 deletions config/layout/attribute/type.validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
os.path.abspath(os.path.join(os.path.dirname(__file__), "../..", "module"))
)

from utils import error, load_yaml
from validation import validate_item_structure
from module.utils import error, load_yaml
from module.validation import validate_item_structure

FILE = "type.yaml"
LANGUAGES = ["en", "fa"]
Expand Down
4 changes: 2 additions & 2 deletions config/layout/attribute/value.validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
os.path.abspath(os.path.join(os.path.dirname(__file__), "../..", "module"))
)

from utils import error, load_yaml
from validation import validate_item_structure
from module.utils import error, load_yaml
from module.validation import validate_item_structure

FILE = "value.yaml"
LANGUAGES = ["en", "fa"]
Expand Down
Empty file added config/layout/py.typed
Empty file.
4 changes: 2 additions & 2 deletions config/layout/type.validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "module"))
)

from utils import error, load_yaml
from validation import validate_item_structure
from module.utils import error, load_yaml
from module.validation import validate_item_structure

FILE = "type.yaml"
LANGUAGES = ["en", "fa"]
Expand Down
1 change: 0 additions & 1 deletion config/layout/type.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ items:
- box
fa:
- جعبه
attributes:
- descriptions: ''
examples: ''
generate_name: p
Expand Down
Empty file added config/module/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion config/module/validation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Dict, List

from utils import error
from .utils import error


def validate_item_structure(item: Dict[str, Any], languages: List[str]) -> None:
Expand Down

0 comments on commit be5eb25

Please sign in to comment.