From b128ce691588bf0b860b5672e4ce7dbf0cf6741d Mon Sep 17 00:00:00 2001 From: Amir Date: Wed, 19 Feb 2025 16:09:42 +0100 Subject: [PATCH 1/5] Dodata opcija da yaml template da moze da koristi html i django template --- .../management/commands/import_template.py | 2 +- backend/core/templates/document.html | 34 ++--------- backend/core/views.py | 58 +++++++++++++++---- document_template.yml | 53 ++++++----------- 4 files changed, 70 insertions(+), 77 deletions(-) diff --git a/backend/core/management/commands/import_template.py b/backend/core/management/commands/import_template.py index d055293..20074f8 100644 --- a/backend/core/management/commands/import_template.py +++ b/backend/core/management/commands/import_template.py @@ -1,5 +1,6 @@ import yaml from django.core.management.base import BaseCommand +from django.template import Template, Context from backend.core.models import DocumentTemplate class Command(BaseCommand): @@ -13,7 +14,6 @@ class Command(BaseCommand): with open(yaml_file_path, 'r') as file: content = file.read() - yaml_data = yaml.safe_load(content) DocumentTemplate.objects.update_or_create( name="Default Template", diff --git a/backend/core/templates/document.html b/backend/core/templates/document.html index f1ec85c..1fa2cc1 100644 --- a/backend/core/templates/document.html +++ b/backend/core/templates/document.html @@ -2,35 +2,13 @@ {% block content %}
-
-

{{ organization.name }}

-
-

Created: {{ document.created_at|date:"F j, Y" }}

-

Last modified: {{ document.modified_at|date:"F j, Y" }}

-
-
- -
- {% for segment in segments %} - {% if segment.segment_type == 'title' %} -

{{ segment.content }}

- {% elif segment.segment_type == 'subtitle' %} -

{{ segment.content }}

- {% elif segment.segment_type == 'h1' %} -

{{ segment.content }}

- {% elif segment.segment_type == 'h2' %} -

{{ segment.content }}

- {% elif segment.segment_type == 'h3' %} -

{{ segment.content }}

- {% elif segment.segment_type == 'quote' %} -
{{ segment.content }}
- {% else %} -

{{ segment.content }}

- {% endif %} - {% endfor %} -
-
+ {% if error %} +

{{ error }}

+ {% endif %} +
+ {{ rendered_html|safe }} +