Commit 362b0a84 authored by mohammed.shibili's avatar mohammed.shibili

asterisk

parents
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPackageRequirementsInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<value>
<list size="2">
<item index="0" class="java.lang.String" itemvalue="SQLAlchemy" />
<item index="1" class="java.lang.String" itemvalue="psycopg2-binary" />
</list>
</value>
</option>
</inspection_tool>
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N801" />
</list>
</option>
</inspection_tool>
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="list.discard" />
<option value="Sheet_name" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (add astics logic)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/add astics logic.iml" filepath="$PROJECT_DIR$/.idea/add astics logic.iml" />
</modules>
</component>
</project>
\ No newline at end of file
import copy
import json
from typing import Any
from fastapi import FastAPI, UploadFile, HTTPException
import chardet
from logics import Logics
app = FastAPI()
def add_logic_json(data: Any) -> Any:
main_component = data.get("components", "")
if not main_component:
return "invalid file format"
new_section = []
for section in main_component:
if section.get("type", "") == "table":
section_rows = section.get("rows", "")
if section_rows:
new_rows = []
for rows in section_rows:
new_column = []
for columns in rows:
"""new changes"""
"""FYI"""
new_column_component = []
for column_components in columns["components"]:
if column_components.get("type", "") in ["select", "textfield", "textarea",
"button-group", "number"]:
if column_components.get("logic", "") or column_components["validate"].get(
"required", ""):
current_key = column_components.get("key")
logic_to_add = copy.deepcopy(Logics.not_required)
logic_to_add["trigger"]["javascript"] = f'result = data.{current_key}'
if column_components.get("logic", ""):
column_components["logic"].append(logic_to_add)
else:
column_components["logic"] = [logic_to_add]
new_column_component.append(column_components)
new_column.append({"components": new_column_component})
new_rows.append(new_column)
section["rows"] = new_rows
new_section.append(section)
data["components"] = new_section
return data
@app.post("/add_logic")
async def add_logic(file: UploadFile = UploadFile(...)):
try:
content = await file.read()
encoding_result = chardet.detect(content)
file_encoding = encoding_result['encoding']
json_data = json.loads(content.decode(file_encoding))
updated_json = add_logic_json(json_data)
return updated_json
except json.JSONDecodeError:
raise HTTPException(status_code=400, detail="Invalid JSON format in the uploaded file.")
class Logics:
not_required = {
"name": "Required",
"trigger": {
"type": "javascript",
"javascript": ""
},
"actions": [
{
"name": "Not required",
"type": "property",
"property": {
"label": "Required",
"value": "validate.required",
"type": "boolean"
},
"state": False
}
]
}
import uvicorn
if __name__ == "__main__":
uvicorn.run("add logic:app", port=8000, reload=True)
\ No newline at end of file
uvicorn~=0.25.0
chardet~=5.2.0
fastapi~=0.108.0
python-multipart~=0.0.6
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment