load links from file interface

This commit is contained in:
Christoph J. Scherr 2024-03-03 19:35:22 +01:00
parent 45b0f4dca0
commit 0ed70bbae9
Signed by: PlexSheep
GPG Key ID: 7CDD0B14851A08EF
7 changed files with 48 additions and 5 deletions

View File

@ -29,6 +29,11 @@ __Gawa: MIT Licensed, see LICENSE__
| Database stuff | `libpq-devel` | | Database stuff | `libpq-devel` |
| Database stuff | `mariadb` | | Database stuff | `mariadb` |
## Deployment
* `git submodule init && git submodule update`
+ `docker compose up -d && docker compose logs -f`
## Security ## Security
- [ ] Do something about the files in the blog dir - [ ] Do something about the files in the blog dir

View File

@ -255,7 +255,7 @@ class BlogPost(models.Model):
# logger.name = logger.name + ".sync_with_fs" # logger.name = logger.name + ".sync_with_fs"
# delete all existing objects # delete all existing objects
BlogPost.objects.all().delete() cls.objects.all().delete()
# check if the DATA_DIR is OK # check if the DATA_DIR is OK
data_dir = pathlib.Path(cls.DATA_DIR) data_dir = pathlib.Path(cls.DATA_DIR)

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: 2023-10-08 21:03+0200\n"
"Last-Translator: <software@cscherr.de>\n" "Last-Translator: <software@cscherr.de>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -163,7 +163,7 @@ msgstr "Deutsch"
msgid "English" msgid "English"
msgstr "Englisch" msgstr "Englisch"
#: start/admin.py:8 #: start/admin.py:10
msgid "Regenerate traits" msgid "Regenerate traits"
msgstr "Eigenschaften regenerieren" msgstr "Eigenschaften regenerieren"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: 2023-10-08 15:18+0200\n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
@ -151,7 +151,7 @@ msgstr ""
msgid "English" msgid "English"
msgstr "" msgstr ""
#: start/admin.py:8 #: start/admin.py:10
msgid "Regenerate traits" msgid "Regenerate traits"
msgstr "" msgstr ""

View File

@ -1,4 +1,6 @@
from django.contrib import admin 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.db.models import CASCADE, AutoField, OneToOneField
from django.views.generic import View from django.views.generic import View
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
@ -27,3 +29,15 @@ class LinkAdmin(admin.ModelAdmin):
list_display = ["title_en", "title_de", "url", "favicon", "personal"] list_display = ["title_en", "title_de", "url", "favicon", "personal"]
ordering = ['title_de', 'title_en'] ordering = ['title_de', 'title_en']
actions = [regenerate] 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("../")

View File

@ -1,6 +1,11 @@
import random import random
import favicon import favicon
import requests import requests
import toml
import ast
import re
import os
import pathlib
from django.db import models from django.db import models
from django.db.models.options import override from django.db.models.options import override
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
@ -33,6 +38,7 @@ class Link(models.Model):
""" """
FAVICON_DIR: str = "img/links/favicons" FAVICON_DIR: str = "img/links/favicons"
LINKS_FILE = "/app/start/data/links.toml"
# the actual link # the actual link
url = models.URLField(unique=True, null=False, primary_key=True) url = models.URLField(unique=True, null=False, primary_key=True)
@ -50,6 +56,18 @@ class Link(models.Model):
def __str__(self): def __str__(self):
return f"{{<{self.__class__.__name__}>\"{self.title_en}\"}}" 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): def regenerate(self):
""" """
regenerate a object regenerate a object

View File

@ -0,0 +1,6 @@
{% extends 'admin/change_list.html' %} {% block object-tools %}
<form action="sync" method="POST">
{% csrf_token %}
<button type="submit" class="button" style="padding: 4px">Sync with FS</button>
</form>
{{ block.super }} {% endblock %}