initial doc generator works now

pull/2/head
mtyton 2023-05-21 21:30:16 +02:00
rodzic cabc144810
commit 0cfba0602b
10 zmienionych plików z 71 dodań i 1 usunięć

Plik binarny nie jest wyświetlany.

Wyświetl plik

@ -90,7 +90,6 @@ WSGI_APPLICATION = "artel.wsgi.application"
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
import dj_database_url as db_url
DATABASES = {
"default": db_url.parse(
os.environ.get("DATABASE_URL", "postgres://comfy:password@db/comfy_shop")

Wyświetl plik

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

Wyświetl plik

@ -0,0 +1,6 @@
from django.apps import AppConfig
class DocgeneratorConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'docgenerator'

Wyświetl plik

@ -0,0 +1,44 @@
from abc import (
ABC,
abstractmethod
)
from typing import (
Dict,
Any
)
from django.db.models import Model
from docxtpl import DocxTemplate
class DocumentGeneratorInterface(ABC):
@abstractmethod
def load_template(self, path: str):
...
@abstractmethod
def get_extra_context(self) -> Dict[str, Any]:
...
@abstractmethod
def generate_file(self, context: Dict[str, Any] = None):
...
class BaseDocumentGenerator(DocumentGeneratorInterface):
def __init__(self, instance: Model) -> None:
super().__init__()
self.instance = instance
def load_template(self, path: str):
return DocxTemplate(path)
def get_extra_context(self):
return {}
class PdfFromDocGenerator(BaseDocumentGenerator):
def generate_file(self, context: Dict[str, Any] = None):
template = self.load_template()
context.update(self.get_extra_context())

Wyświetl plik

@ -0,0 +1,10 @@
from django.db import models
from django.core.files.storage import Storage
class DocumentTemplate(models.Model):
name = models.CharField(max_length=255)
file = models.FileField(upload_to="doc_templates/", )
def __str__(self) -> str:
return self.name

Wyświetl plik

@ -0,0 +1,5 @@
from django.test import TestCase
class PdfFromDocGeneratorTestCase(TestCase):
...

Wyświetl plik

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.