diff --git a/README.md b/README.md index 8621ad7..25d5f03 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,11 @@ __Gawa: MIT Licensed, see LICENSE__ | Database stuff | `libpq-devel` | | Database stuff | `mariadb` | +## Deployment + +* `git submodule init && git submodule update` ++ `docker compose up -d && docker compose logs -f` + ## Security - [ ] Do something about the files in the blog dir diff --git a/gawa/blog/models.py b/gawa/blog/models.py index 99e1cd2..c5fc165 100644 --- a/gawa/blog/models.py +++ b/gawa/blog/models.py @@ -255,7 +255,7 @@ class BlogPost(models.Model): # logger.name = logger.name + ".sync_with_fs" # delete all existing objects - BlogPost.objects.all().delete() + cls.objects.all().delete() # check if the DATA_DIR is OK data_dir = pathlib.Path(cls.DATA_DIR) diff --git a/gawa/locale/de/LC_MESSAGES/django.po b/gawa/locale/de/LC_MESSAGES/django.po index a8eaba0..366257e 100644 --- a/gawa/locale/de/LC_MESSAGES/django.po +++ b/gawa/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-02-09 22:46+0100\n" +"POT-Creation-Date: 2024-03-03 19:27+0100\n" "PO-Revision-Date: 2023-10-08 21:03+0200\n" "Last-Translator: \n" "Language-Team: LANGUAGE \n" @@ -163,7 +163,7 @@ msgstr "Deutsch" msgid "English" msgstr "Englisch" -#: start/admin.py:8 +#: start/admin.py:10 msgid "Regenerate traits" msgstr "Eigenschaften regenerieren" diff --git a/gawa/locale/en/LC_MESSAGES/django.po b/gawa/locale/en/LC_MESSAGES/django.po index d29077a..e4dd211 100644 --- a/gawa/locale/en/LC_MESSAGES/django.po +++ b/gawa/locale/en/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-02-09 22:46+0100\n" +"POT-Creation-Date: 2024-03-03 19:27+0100\n" "PO-Revision-Date: 2023-10-08 15:18+0200\n" "Last-Translator: \n" "Language-Team: \n" @@ -151,7 +151,7 @@ msgstr "" msgid "English" msgstr "" -#: start/admin.py:8 +#: start/admin.py:10 msgid "Regenerate traits" msgstr "" diff --git a/gawa/start/admin.py b/gawa/start/admin.py index 15b5e57..69802ac 100644 --- a/gawa/start/admin.py +++ b/gawa/start/admin.py @@ -1,4 +1,6 @@ from django.contrib import admin +from django.http.response import HttpResponseRedirect +from django.urls import path from django.db.models import CASCADE, AutoField, OneToOneField from django.views.generic import View from django.utils.translation import gettext as _ @@ -27,3 +29,15 @@ class LinkAdmin(admin.ModelAdmin): list_display = ["title_en", "title_de", "url", "favicon", "personal"] ordering = ['title_de', 'title_en'] actions = [regenerate] + change_list_template = "admin/links.html" + + def get_urls(self): + urls = super().get_urls() + my_urls = [ + path('sync/', self.sync_with_fs), + ] + return my_urls + urls + + def sync_with_fs(self, request): + Link.sync_with_fs() + return HttpResponseRedirect("../") diff --git a/gawa/start/models.py b/gawa/start/models.py index 6c82755..e33fd5c 100644 --- a/gawa/start/models.py +++ b/gawa/start/models.py @@ -1,6 +1,11 @@ import random import favicon import requests +import toml +import ast +import re +import os +import pathlib from django.db import models from django.db.models.options import override from django.utils.translation import gettext as _ @@ -33,6 +38,7 @@ class Link(models.Model): """ FAVICON_DIR: str = "img/links/favicons" + LINKS_FILE = "/app/start/data/links.toml" # the actual link url = models.URLField(unique=True, null=False, primary_key=True) @@ -50,6 +56,18 @@ class Link(models.Model): def __str__(self): return f"{{<{self.__class__.__name__}>\"{self.title_en}\"}}" + @ classmethod + def sync_with_fs(cls): + """ + Sync all Links with the filesystem. + + Caution: Will delete all Links + """ + # delete all existing objects + cls.objects.all().delete() + # TODO: load links from links.toml + raise NotImplementedError("loading from links.toml not implemented") + def regenerate(self): """ regenerate a object diff --git a/gawa/start/templates/admin/links.html b/gawa/start/templates/admin/links.html new file mode 100644 index 0000000..750d46d --- /dev/null +++ b/gawa/start/templates/admin/links.html @@ -0,0 +1,6 @@ +{% extends 'admin/change_list.html' %} {% block object-tools %} +
+ {% csrf_token %} + +
+{{ block.super }} {% endblock %}