mirror of
https://github.com/hay-kot/mealie.git
synced 2025-08-22 14:33:33 -07:00
type() to isinstance()
This commit is contained in:
parent
65c86f5dc5
commit
e86894c0ca
2 changed files with 9 additions and 53 deletions
|
@ -44,7 +44,7 @@ class Cleaner:
|
|||
|
||||
@staticmethod
|
||||
def category(category: str):
|
||||
if type(category) == type(str):
|
||||
if isinstance(category, str):
|
||||
return [category]
|
||||
else:
|
||||
return []
|
||||
|
@ -58,11 +58,11 @@ class Cleaner:
|
|||
def image(image=None) -> str:
|
||||
if not image:
|
||||
return "no image"
|
||||
if type(image) == list:
|
||||
if isinstance(image, list):
|
||||
return image[0]
|
||||
elif type(image) == dict:
|
||||
elif isinstance(image, dict):
|
||||
return image["url"]
|
||||
elif type(image) == str:
|
||||
elif isinstance(image, str):
|
||||
return image
|
||||
else:
|
||||
raise Exception(f"Unrecognised image URL format: {image}")
|
||||
|
@ -77,11 +77,11 @@ class Cleaner:
|
|||
return [{"text": Cleaner._instruction(line)} for line in instructions.splitlines() if line]
|
||||
|
||||
# Plain strings in a list
|
||||
elif type(instructions) == list and type(instructions[0]) == str:
|
||||
elif isinstance(instructions, list) and isinstance(instructions[0], list):
|
||||
return [{"text": Cleaner._instruction(step)} for step in instructions]
|
||||
|
||||
# Dictionaries (let's assume it's a HowToStep) in a list
|
||||
elif type(instructions) == list and type(instructions[0]) == dict:
|
||||
elif isinstance(instructions, list) and isinstance(instructions[0], dict):
|
||||
# Try List of Dictionary without "@type" or "type"
|
||||
if not instructions[0].get("@type", False) and not instructions[0].get("type", False):
|
||||
return [{"text": Cleaner._instruction(step["text"])} for step in instructions]
|
||||
|
@ -134,7 +134,7 @@ class Cleaner:
|
|||
|
||||
@staticmethod
|
||||
def yield_amount(yld) -> str:
|
||||
if type(yld) == list:
|
||||
if isinstance(yld, list):
|
||||
return yld[-1]
|
||||
else:
|
||||
return yld
|
||||
|
@ -143,9 +143,9 @@ class Cleaner:
|
|||
def time(time_entry):
|
||||
if time_entry is None:
|
||||
return None
|
||||
elif type(time_entry) == datetime:
|
||||
elif isinstance(time_entry, datetime):
|
||||
print(time_entry)
|
||||
elif type(time_entry) != str:
|
||||
elif isinstance(time_entry, str):
|
||||
return str(time_entry)
|
||||
else:
|
||||
return time_entry
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
import json
|
||||
|
||||
from mealie.app import app
|
||||
from mealie.core.config import DATA_DIR
|
||||
|
||||
"""Script to export the ReDoc documentation page into a standalone HTML file."""
|
||||
|
||||
HTML_TEMPLATE = """<!-- Custom HTML site displayed as the Home chapter -->
|
||||
{% extends "main.html" %}
|
||||
{% block tabs %}
|
||||
{{ super() }}
|
||||
|
||||
<style>
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
||||
<div id="redoc-container"></div>
|
||||
<script src="https://cdn.jsdelivr.net/npm/redoc/bundles/redoc.standalone.js"> </script>
|
||||
<script>
|
||||
var spec = MY_SPECIFIC_TEXT;
|
||||
Redoc.init(spec, {}, document.getElementById("redoc-container"));
|
||||
</script>
|
||||
|
||||
|
||||
{% endblock %}
|
||||
{% block content %}{% endblock %}
|
||||
{% block footer %}{% endblock %}
|
||||
"""
|
||||
|
||||
HTML_PATH = DATA_DIR.parent.parent.joinpath("docs/docs/overrides/api.html")
|
||||
|
||||
|
||||
def generate_api_docs(my_app):
|
||||
with open(HTML_PATH, "w") as fd:
|
||||
text = HTML_TEMPLATE.replace("MY_SPECIFIC_TEXT", json.dumps(my_app.openapi()))
|
||||
fd.write(text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
generate_api_docs(app)
|
Loading…
Add table
Add a link
Reference in a new issue