From aeb7aa24fe3f4f66f1657120bcb9c0d2ba14cd4a Mon Sep 17 00:00:00 2001 From: Fasand Date: Fri, 30 Aug 2024 11:25:30 +0200 Subject: [PATCH] #649: replace json_constants with django-solo, rewrite all occurrences and add translations --- Seeder/core/admin.py | 6 ++ Seeder/core/forms.py | 29 ++------ Seeder/core/json_constants.py | 85 ---------------------- Seeder/core/migrations/0001_initial.py | 28 +++++++ Seeder/core/migrations/__init__.py | 0 Seeder/core/models.py | 27 ++++++- Seeder/core/templatetags/core.py | 9 +++ Seeder/core/templatetags/json_constants.py | 12 --- Seeder/core/urls.py | 4 +- Seeder/core/views.py | 30 ++++---- Seeder/locale/cs/LC_MESSAGES/django.po | 77 ++++++++++---------- Seeder/locale/en_US/LC_MESSAGES/django.po | 77 ++++++++++---------- Seeder/settings/base.py | 4 +- Seeder/templates/base.html | 8 +- Seeder/www/forms.py | 4 +- Seeder/www/templates/base_www.html | 8 +- Seeder/www/templates/index.html | 7 +- requirements.txt | 1 + 18 files changed, 186 insertions(+), 230 deletions(-) create mode 100644 Seeder/core/admin.py delete mode 100644 Seeder/core/json_constants.py create mode 100644 Seeder/core/migrations/0001_initial.py create mode 100644 Seeder/core/migrations/__init__.py delete mode 100644 Seeder/core/templatetags/json_constants.py diff --git a/Seeder/core/admin.py b/Seeder/core/admin.py new file mode 100644 index 00000000..4db0999e --- /dev/null +++ b/Seeder/core/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from solo.admin import SingletonModelAdmin +from core.models import SiteConfiguration + + +admin.site.register(SiteConfiguration, SingletonModelAdmin) \ No newline at end of file diff --git a/Seeder/core/forms.py b/Seeder/core/forms.py index c5f443a5..8062b303 100644 --- a/Seeder/core/forms.py +++ b/Seeder/core/forms.py @@ -1,9 +1,8 @@ from django import forms from django.contrib.auth.models import User from django.utils.translation import ugettext_lazy as _ -from ckeditor.widgets import CKEditorWidget -from .json_constants import FieldType, load_constants, get_type_for_key +from . import models class UserForm(forms.ModelForm): @@ -27,25 +26,7 @@ def save(self, commit=True): return self.instance.delete() return super().save() - -class UpdateJsonConstantsForm(forms.Form): - - def __init__(self, *args, **kwargs): - super().__init__(*args, **kwargs) - # Dynamically create a field for each available constant - for key, value in load_constants().items(): - field_type = get_type_for_key(key) - if field_type == FieldType.BOOL: - self.fields[key] = forms.BooleanField( - label=key, initial=value, required=False) - elif field_type == FieldType.LONG: - self.fields[key] = forms.CharField( - label=key, initial=value, required=True, - widget=forms.Textarea()) - elif field_type == FieldType.RICH: - self.fields[key] = forms.CharField( - label=key, initial=value, required=True, - widget=CKEditorWidget(config_name="json_constants")) - else: # SHORT - self.fields[key] = forms.CharField( - max_length=128, required=True, label=key, initial=value) +class SiteConfigurationForm(forms.ModelForm): + class Meta: + model = models.SiteConfiguration + fields = "__all__" diff --git a/Seeder/core/json_constants.py b/Seeder/core/json_constants.py deleted file mode 100644 index 1403e51b..00000000 --- a/Seeder/core/json_constants.py +++ /dev/null @@ -1,85 +0,0 @@ -import json -import os -from django.conf import settings - - -CONSTANTS_PATH = os.path.join(settings.BASE_DIR, "settings", "constants.json") - -TYPE_BOOL = "bool" -TYPE_SHORT = "short" -TYPE_LONG = "long" - - -class FieldType: - BOOL = "bool" # BooleanField - SHORT = "short" # CharField - LONG = "long" # TextField - RICH = "rich" # TextField using CKEditor - - -""" Constant field definition with defaults """ -FIELDS = { - "webarchive_size": { - "type": FieldType.SHORT, - "default": "409 TB", - }, - "wayback_maintenance": { - "type": FieldType.BOOL, - "default": False, - }, - "wayback_maintenance_text_cs": { - "type": FieldType.RICH, - "default": """ -

Pokud vidíte tuto stránku, probíhá údržba dat a v archivu nelze nyní vyhledávat. Některé linky vrátí chybu.

-

Prosím zkuste načíst Webarchiv později.

-""", - }, - "wayback_maintenance_text_en": { - "type": FieldType.RICH, - "default": """ -

If you see this page, we are currently doing maintenance and it is not possible to search the archive. Some links may return an error.

-

Please, try to load Webarchiv again later.

-""" - } -} - - -def get_defaults(): - """ Retrieve only field key and default value, not the type """ - return {key: field["default"] for key, field in FIELDS.items()} - - -def get_type_for_key(key): - """ Retrieve field's preset type or default to SHORT """ - return FIELDS.get(key, {}).get("type", FieldType.SHORT) - - -def load_constants(): - """ Return the DEFAULTS extended by saved constants """ - data = get_defaults() - try: - with open(CONSTANTS_PATH, "r") as f: - loaded = json.load(f) - # Only overwrite already present keys with loaded constants - for key in data.keys(): - data[key] = loaded.get(key, data[key]) - except: - pass - return data - - -def store_constants(data): - """ Store {key: value} pairs """ - with open(CONSTANTS_PATH, "w") as f: - json.dump(data, f) - - -def update_constant(key, value): - data = load_constants() - data[key] = value - store_constants(data) - - -def get_constant(key): - data = load_constants() # this includes defaults - return data.get(key, None) diff --git a/Seeder/core/migrations/0001_initial.py b/Seeder/core/migrations/0001_initial.py new file mode 100644 index 00000000..3bb5dfcd --- /dev/null +++ b/Seeder/core/migrations/0001_initial.py @@ -0,0 +1,28 @@ +# Generated by Django 2.2.28 on 2024-08-29 14:18 + +import ckeditor.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='SiteConfiguration', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('webarchive_size', models.CharField(default='595 TB', max_length=128)), + ('wayback_maintenance', models.BooleanField(default=False)), + ('wayback_maintenance_text_cs', ckeditor.fields.RichTextField(default='\n

Pokud vidíte tuto stránku, probíhá údržba dat a v archivu nelze nyní vyhledávat. Některé linky vrátí chybu.

\n

Prosím zkuste načíst Webarchiv později.

\n')), + ('wayback_maintenance_text_en', ckeditor.fields.RichTextField(default='\n

If you see this page, we are currently doing maintenance and it is not possible to search the archive. Some links may return an error.

\n

Please, try to load Webarchiv again later.

\n')), + ], + options={ + 'verbose_name': 'Site Configuration', + }, + ), + ] diff --git a/Seeder/core/migrations/__init__.py b/Seeder/core/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Seeder/core/models.py b/Seeder/core/models.py index 44e681b2..147a9605 100644 --- a/Seeder/core/models.py +++ b/Seeder/core/models.py @@ -1,7 +1,9 @@ from django.db import models from django import forms from django.utils import timezone -from django.forms.widgets import DateTimeInput, SplitDateTimeWidget +from django.utils.translation import gettext_lazy as _ +from ckeditor.fields import RichTextField +from solo.models import SingletonModel from core import widgets @@ -41,3 +43,26 @@ class BaseModel(models.Model): class Meta: abstract = True ordering = ('-last_changed', ) + +class SiteConfiguration(SingletonModel): + """ Singleton model for Site Configuration """ + webarchive_size = models.CharField(max_length=128, default="595 TB") + wayback_maintenance = models.BooleanField(default=False) + wayback_maintenance_text_cs = RichTextField( + config_name='site_configuration', + default=""" +

Pokud vidíte tuto stránku, probíhá údržba dat a v archivu nelze nyní vyhledávat. Některé linky vrátí chybu.

+

Prosím zkuste načíst Webarchiv později.

+""") + wayback_maintenance_text_en = RichTextField( + config_name='site_configuration', + default=""" +

If you see this page, we are currently doing maintenance and it is not possible to search the archive. Some links may return an error.

+

Please, try to load Webarchiv again later.

+""") + + def __str__(self): + return str(_("Site Configuration")) + + class Meta: + verbose_name = _("Site Configuration") \ No newline at end of file diff --git a/Seeder/core/templatetags/core.py b/Seeder/core/templatetags/core.py index f0f30036..0f124c92 100644 --- a/Seeder/core/templatetags/core.py +++ b/Seeder/core/templatetags/core.py @@ -1,6 +1,7 @@ from django import template from django.conf import settings from django.utils.html import format_html +from core.models import SiteConfiguration register = template.Library() @@ -32,3 +33,11 @@ def user_in_group(user, group): ''' Check the provided user belongs to the provided group; all lowered ''' return (str.lower(group) in map(str.lower, user.groups.values_list("name", flat=True))) + +@register.simple_tag +def config(key): + """ + Retrieve a saved constant - returns a default/None if key doesn't exist + """ + config = SiteConfiguration.get_solo() + return getattr(config, key) diff --git a/Seeder/core/templatetags/json_constants.py b/Seeder/core/templatetags/json_constants.py deleted file mode 100644 index a33e9015..00000000 --- a/Seeder/core/templatetags/json_constants.py +++ /dev/null @@ -1,12 +0,0 @@ -from django import template -from core.json_constants import get_constant - -register = template.Library() - - -@register.simple_tag -def json_constant(key): - """ - Retrieve a saved constant - returns a default/None if key doesn't exist - """ - return get_constant(key) diff --git a/Seeder/core/urls.py b/Seeder/core/urls.py index b807d05b..3638021c 100644 --- a/Seeder/core/urls.py +++ b/Seeder/core/urls.py @@ -10,8 +10,8 @@ path('profile', UserProfileEdit.as_view(), name='user_edit'), path('crash_test', CrashTestView.as_view(), name='crash_test'), path('dev', DevNotesView.as_view(), name='dev_notes'), - path('json_constants', EditJsonConstantsView.as_view(), - name='json_constants'), + path('site_configuration', EditSiteConfigurationView.as_view(), + name='site_configuration'), path('toggle-wayback-maintenance', ToggleWaybackMaintenanceView.as_view(), name='toggle_wayback_maintenance'), ] diff --git a/Seeder/core/views.py b/Seeder/core/views.py index 4eee42df..9c1435ce 100644 --- a/Seeder/core/views.py +++ b/Seeder/core/views.py @@ -1,6 +1,3 @@ -from .json_constants import store_constants -from . import forms - from django.http.response import HttpResponseRedirect from django.views.generic.base import RedirectView, TemplateView, View from django.utils.translation import ugettext_lazy as _ @@ -10,7 +7,7 @@ from django.utils import translation from django.views.generic.edit import FormView, UpdateView -from core.json_constants import get_constant, update_constant +from . import forms, models from .generic_views import LoginMixin, MessageView, SuperuserRequiredMixin from .dashboard_data import get_cards, cards_registry, REVERSE_SESSION @@ -115,27 +112,30 @@ class DevNotesView(LoginMixin, TemplateView): template_name = 'dev_notes.html' -class EditJsonConstantsView(SuperuserRequiredMixin, FormView, MessageView): +class EditSiteConfigurationView( + SuperuserRequiredMixin, UpdateView, MessageView): """ View for superusers where they can change constants accessed elsewhere in the application. e.g. "webarchive_size" on WWW Index """ - form_class = forms.UpdateJsonConstantsForm + form_class = forms.SiteConfigurationForm template_name = 'edit_form.html' - success_url = reverse_lazy('core:json_constants') - view_name = "json_constants" + success_url = reverse_lazy('core:site_configuration') + view_name = "site_configuration" + + def get_object(self): + return models.SiteConfiguration.get_solo() def get_context_data(self, **kwargs): ctx = super().get_context_data(**kwargs) # This will show up in the page title & header w/ edit_form.html - ctx["object"] = _("Constants") + ctx["object"] = _("Site Configuration") return ctx def form_valid(self, form): - # Fields are created using constants' keys, so just store everything - store_constants(form.cleaned_data) - self.add_message(_("Constants successfully updated"), messages.SUCCESS) + self.add_message(_("Site Configuration successfully updated"), + messages.SUCCESS) return super().form_valid(form) @@ -145,8 +145,10 @@ class ToggleWaybackMaintenanceView(LoginMixin, View, MessageView): """ def post(self, request, *args, **kwargs): - maintenance = get_constant("wayback_maintenance") - update_constant("wayback_maintenance", not maintenance) + config = models.SiteConfiguration.get_solo() + maintenance = config.wayback_maintenance + config.wayback_maintenance = not maintenance + config.save() # Based on the original value before update if maintenance: self.add_message(_('Wayback maintenance turned OFF'), diff --git a/Seeder/locale/cs/LC_MESSAGES/django.po b/Seeder/locale/cs/LC_MESSAGES/django.po index 2639e2ad..23d383df 100644 --- a/Seeder/locale/cs/LC_MESSAGES/django.po +++ b/Seeder/locale/cs/LC_MESSAGES/django.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Seeder\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-08-29 10:04+0000\n" +"POT-Creation-Date: 2024-08-30 09:19+0000\n" "PO-Revision-Date: 2018-04-16 13:40+0200\n" "Last-Translator: mariehaskovcova , 2017\n" "Language-Team: Czech (https://www.transifex.com/webarchivecz/teams/43032/" @@ -358,7 +358,7 @@ msgstr "Smazat" msgid "Proceed with deletion?" msgstr "Pokračovat se smazáním?" -#: contracts/templates/contract.html:140 harvests/templates/calendar.html:51 +#: contracts/templates/contract.html:140 harvests/templates/calendar.html:50 #: source/templates/edit_seed.html:28 source/templates/source.html:221 #: templates/base.html:204 msgid "Close" @@ -468,7 +468,7 @@ msgstr "Rozpracovaná kontrola kvality" msgid "Sources needing QA" msgstr "Zdroje ke kontrole" -#: core/forms.py:22 +#: core/forms.py:21 msgid "Check this to delete this object" msgstr "Potvrďte pro odstranění" @@ -485,39 +485,40 @@ msgstr "Akce {0} nepovolena." msgid "Changes successfully saved." msgstr "Změny uloženy." -#: core/views.py:20 templates/base.html:88 templates/card_detail.html:9 +#: core/models.py:65 core/models.py:68 core/views.py:133 +#: templates/base.html:142 +msgid "Site Configuration" +msgstr "Konfigurace Webu" + +#: core/views.py:17 templates/base.html:88 templates/card_detail.html:9 msgid "Dashboard" msgstr "Hlavní stránka" -#: core/views.py:77 +#: core/views.py:74 msgid "Change user information" msgstr "Změnit uživatelské informace" -#: core/views.py:85 +#: core/views.py:82 msgid "Profile changed." msgstr "Profil změněn." -#: core/views.py:95 +#: core/views.py:92 msgid "Password changed successfully." msgstr "Heslo bylo úspěšně změněno." -#: core/views.py:132 templates/base.html:142 -msgid "Constants" -msgstr "Konstanty" - -#: core/views.py:138 -msgid "Constants successfully updated" -msgstr "Konstanty byly úspěšně změněny" +#: core/views.py:137 +msgid "Site Configuration successfully updated" +msgstr "Konfigurace Webu byla úspěšně aktualizována" -#: core/views.py:152 +#: core/views.py:154 msgid "Wayback maintenance turned OFF" msgstr "Údržba Wayback byla vypnuta" -#: core/views.py:155 +#: core/views.py:157 msgid "Wayback maintenance turned ON" msgstr "Údržba Wayback byla zapnuta" -#: harvests/admin.py:54 harvests/forms.py:57 harvests/forms.py:141 +#: harvests/admin.py:60 harvests/forms.py:60 harvests/forms.py:144 msgid "dataLimit cannot be over 1TB" msgstr "dataLimit nesmí být přes 1TB" @@ -525,7 +526,7 @@ msgstr "dataLimit nesmí být přes 1TB" msgid "One URL per line" msgstr "Jedna URL na řádku" -#: harvests/forms.py:204 +#: harvests/forms.py:207 msgid "" "Provide a text file with one seed per line which will overwrite all " "custom_seeds. The original custom_seeds will be backed up to the media/seeds/" @@ -535,7 +536,7 @@ msgstr "" "mimosystémová semínka. Původní semínka budou zálohována do media/seeds/" "backup složky." -#: harvests/forms.py:225 +#: harvests/forms.py:228 msgid "" "Custom seeds field is disabled because there are too many seeds to be " "displayed in an HTML text field." @@ -634,11 +635,11 @@ msgstr "Manuals" msgid "Combined" msgstr "Combined" -#: harvests/models.py:282 harvests/views.py:383 +#: harvests/models.py:282 harvests/views.py:384 msgid "ArchiveIt" msgstr "ArchiveIt" -#: harvests/models.py:285 harvests/views.py:385 +#: harvests/models.py:285 harvests/views.py:386 msgid "Tests" msgstr "Tests" @@ -746,7 +747,7 @@ msgstr "pole" msgid "Harvest Configuration" msgstr "Konfigurace sklizní" -#: harvests/models.py:853 harvests/views.py:398 templates/base.html:127 +#: harvests/models.py:853 harvests/views.py:399 templates/base.html:127 msgid "Harvest Configurations" msgstr "Konfigurace sklizní" @@ -949,45 +950,45 @@ msgstr "Všechny zdroje jsou otevřené?" msgid "Seeds" msgstr "Semínka" -#: harvests/views.py:58 templates/base.html:122 +#: harvests/views.py:59 templates/base.html:122 msgid "Harvests" msgstr "Sklizně" -#: harvests/views.py:113 harvests/views.py:131 +#: harvests/views.py:114 harvests/views.py:132 msgid "Harvest contains no seeds!" msgstr "" "Sklizeň neobsahuje žádná semínka! Tím pádem nemůže být zmrazena (stav " "nastaven na 'Připraveno na sklízení')" -#: harvests/views.py:353 harvests/views.py:372 +#: harvests/views.py:354 harvests/views.py:373 msgid "Available URLs for date" msgstr "Seznam URL pro datum" -#: harvests/views.py:357 +#: harvests/views.py:358 msgid "All seeds for Harvest" msgstr "Všechna semínka pro sklizeň" -#: harvests/views.py:384 +#: harvests/views.py:385 msgid "VNC" msgstr "VNC: Výběrové custom" -#: harvests/views.py:386 +#: harvests/views.py:387 msgid "Totals" msgstr "Totals: Všechna semínka" -#: harvests/views.py:445 +#: harvests/views.py:446 msgid "TopicCollections" msgstr "Tematické kolekce" -#: harvests/views.py:455 +#: harvests/views.py:456 msgid "Add TopicCollection" msgstr "Přidat tematickou kolekci" -#: harvests/views.py:497 +#: harvests/views.py:503 msgid "Cannot decode file to UTF-8" msgstr "Nelze dekódovat soubor do UTF-8" -#: harvests/views.py:499 +#: harvests/views.py:505 #, python-format msgid "" "Original custom_seeds have been backed to: %(url)s" -#: harvests/views.py:503 +#: harvests/views.py:509 msgid "Uploaded custom seeds will not be paired automatically" msgstr "Nahraná mimosystémová semínka nebudou automaticky párována" -#: harvests/views.py:558 +#: harvests/views.py:577 msgid "ExternalTopicCollections" msgstr "Externí tematické kolekce" -#: harvests/views.py:568 +#: harvests/views.py:587 msgid "Add ExternalTopicCollection" msgstr "Přidat Externí tematickou kolekci" -#: harvests/views.py:652 +#: harvests/views.py:671 msgid "Topic collection published" msgstr "Tematická kolekce publikována" -#: harvests/views.py:654 +#: harvests/views.py:673 msgid "Topic collection unpublished" msgstr "Tematická kolekce nepublikována" -#: harvests/views.py:668 +#: harvests/views.py:687 msgid "URL slug successfully updated" msgstr "URL byla úspěšné změněna" diff --git a/Seeder/locale/en_US/LC_MESSAGES/django.po b/Seeder/locale/en_US/LC_MESSAGES/django.po index adb3aa14..24bc648f 100644 --- a/Seeder/locale/en_US/LC_MESSAGES/django.po +++ b/Seeder/locale/en_US/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Seeder\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-08-29 10:04+0000\n" +"POT-Creation-Date: 2024-08-30 09:19+0000\n" "PO-Revision-Date: 2017-11-07 12:38+0100\n" "Last-Translator: Visgean Skeloru , 2017\n" "Language-Team: English (United States) (https://www.transifex.com/" @@ -359,7 +359,7 @@ msgstr "Delete" msgid "Proceed with deletion?" msgstr "Proceed with deletion?" -#: contracts/templates/contract.html:140 harvests/templates/calendar.html:51 +#: contracts/templates/contract.html:140 harvests/templates/calendar.html:50 #: source/templates/edit_seed.html:28 source/templates/source.html:221 #: templates/base.html:204 msgid "Close" @@ -471,7 +471,7 @@ msgstr "Opened QAs" msgid "Sources needing QA" msgstr "Sources needing QA" -#: core/forms.py:22 +#: core/forms.py:21 msgid "Check this to delete this object" msgstr "Check this to delete this object" @@ -488,39 +488,40 @@ msgstr "Action {0} not allowed." msgid "Changes successfully saved." msgstr "Changes successfully saved." -#: core/views.py:20 templates/base.html:88 templates/card_detail.html:9 +#: core/models.py:65 core/models.py:68 core/views.py:133 +#: templates/base.html:142 +msgid "Site Configuration" +msgstr "Site Configuration" + +#: core/views.py:17 templates/base.html:88 templates/card_detail.html:9 msgid "Dashboard" msgstr "Dashboard" -#: core/views.py:77 +#: core/views.py:74 msgid "Change user information" msgstr "Change user information" -#: core/views.py:85 +#: core/views.py:82 msgid "Profile changed." msgstr "Profile changed." -#: core/views.py:95 +#: core/views.py:92 msgid "Password changed successfully." msgstr "Password changed successfully." -#: core/views.py:132 templates/base.html:142 -msgid "Constants" -msgstr "Constants" - -#: core/views.py:138 -msgid "Constants successfully updated" -msgstr "Constants successfully updated" +#: core/views.py:137 +msgid "Site Configuration successfully updated" +msgstr "Site Configuration successfully updated" -#: core/views.py:152 +#: core/views.py:154 msgid "Wayback maintenance turned OFF" msgstr "Wayback maintenance turned OFF" -#: core/views.py:155 +#: core/views.py:157 msgid "Wayback maintenance turned ON" msgstr "Wayback maintenance turned ON" -#: harvests/admin.py:54 harvests/forms.py:57 harvests/forms.py:141 +#: harvests/admin.py:60 harvests/forms.py:60 harvests/forms.py:144 msgid "dataLimit cannot be over 1TB" msgstr "dataLimit cannot be over 1TB" @@ -528,7 +529,7 @@ msgstr "dataLimit cannot be over 1TB" msgid "One URL per line" msgstr "One URL per line" -#: harvests/forms.py:204 +#: harvests/forms.py:207 msgid "" "Provide a text file with one seed per line which will overwrite all " "custom_seeds. The original custom_seeds will be backed up to the media/seeds/" @@ -538,7 +539,7 @@ msgstr "" "custom_seeds. The original custom_seeds will be backed up to the media/seeds/" "backup folder." -#: harvests/forms.py:225 +#: harvests/forms.py:228 msgid "" "Custom seeds field is disabled because there are too many seeds to be " "displayed in an HTML text field." @@ -637,11 +638,11 @@ msgstr "Manuals" msgid "Combined" msgstr "Combined" -#: harvests/models.py:282 harvests/views.py:383 +#: harvests/models.py:282 harvests/views.py:384 msgid "ArchiveIt" msgstr "ArchiveIt" -#: harvests/models.py:285 harvests/views.py:385 +#: harvests/models.py:285 harvests/views.py:386 msgid "Tests" msgstr "Tests" @@ -749,7 +750,7 @@ msgstr "file" msgid "Harvest Configuration" msgstr "Harvest Configuration" -#: harvests/models.py:853 harvests/views.py:398 templates/base.html:127 +#: harvests/models.py:853 harvests/views.py:399 templates/base.html:127 msgid "Harvest Configurations" msgstr "Harvest Configurations" @@ -952,45 +953,45 @@ msgstr "All sources are open?" msgid "Seeds" msgstr "Seeds" -#: harvests/views.py:58 templates/base.html:122 +#: harvests/views.py:59 templates/base.html:122 msgid "Harvests" msgstr "Harvests" -#: harvests/views.py:113 harvests/views.py:131 +#: harvests/views.py:114 harvests/views.py:132 msgid "Harvest contains no seeds!" msgstr "" "Harvest contains no seeds! This means it cannot be frozen (set as 'Ready to " "harvest')" -#: harvests/views.py:353 harvests/views.py:372 +#: harvests/views.py:354 harvests/views.py:373 msgid "Available URLs for date" msgstr "Available URLs for date" -#: harvests/views.py:357 +#: harvests/views.py:358 msgid "All seeds for Harvest" msgstr "All seeds for Harvest" -#: harvests/views.py:384 +#: harvests/views.py:385 msgid "VNC" msgstr "VNC: Custom seeds" -#: harvests/views.py:386 +#: harvests/views.py:387 msgid "Totals" msgstr "Totals: All seeds" -#: harvests/views.py:445 +#: harvests/views.py:446 msgid "TopicCollections" msgstr "Topic Collections" -#: harvests/views.py:455 +#: harvests/views.py:456 msgid "Add TopicCollection" msgstr "Add Topic Collection" -#: harvests/views.py:497 +#: harvests/views.py:503 msgid "Cannot decode file to UTF-8" msgstr "Cannot decode file to UTF-8" -#: harvests/views.py:499 +#: harvests/views.py:505 #, python-format msgid "" "Original custom_seeds have been backed to: %(url)s" -#: harvests/views.py:503 +#: harvests/views.py:509 msgid "Uploaded custom seeds will not be paired automatically" msgstr "Uploaded custom seeds will not be paired automatically" -#: harvests/views.py:558 +#: harvests/views.py:577 msgid "ExternalTopicCollections" msgstr "External Topic Collections" -#: harvests/views.py:568 +#: harvests/views.py:587 msgid "Add ExternalTopicCollection" msgstr "Add External Topic Collection" -#: harvests/views.py:652 +#: harvests/views.py:671 msgid "Topic collection published" msgstr "Topic collection published" -#: harvests/views.py:654 +#: harvests/views.py:673 msgid "Topic collection unpublished" msgstr "Topic collection unpublished" -#: harvests/views.py:668 +#: harvests/views.py:687 msgid "URL slug successfully updated" msgstr "URL slug successfully updated" diff --git a/Seeder/settings/base.py b/Seeder/settings/base.py index a343010d..117c5b5b 100755 --- a/Seeder/settings/base.py +++ b/Seeder/settings/base.py @@ -90,8 +90,8 @@ 'rest_framework.authtoken', 'captcha', 'ordered_model', + 'solo', # 'elasticstack', - 'core', 'publishers', 'source', @@ -235,7 +235,7 @@ 'width': 800, 'height': 100, }, - 'json_constants': { + 'site_configuration': { 'toolbar': 'Custom', 'toolbar_Custom': [ ['Bold', 'Italic', 'Underline', 'FontSize'], diff --git a/Seeder/templates/base.html b/Seeder/templates/base.html index a85caaea..18913854 100755 --- a/Seeder/templates/base.html +++ b/Seeder/templates/base.html @@ -1,5 +1,5 @@ -{% load bootstrap3 i18n raven core static json_constants %} -{% json_constant "wayback_maintenance" as wayback_maintenance%} +{% load bootstrap3 i18n raven core static %} +{% config "wayback_maintenance" as wayback_maintenance%} @@ -138,8 +138,8 @@ {% trans 'Search logs' %} {% if user.is_superuser %} -
  • - {% trans 'Constants' %} +
  • + {% trans 'Site Configuration' %}
  • {% endif %} diff --git a/Seeder/www/forms.py b/Seeder/www/forms.py index 83934ac2..32d2c5b3 100644 --- a/Seeder/www/forms.py +++ b/Seeder/www/forms.py @@ -4,7 +4,7 @@ from dal import autocomplete from . import models -from core.json_constants import get_constant +from core.models import SiteConfiguration class BigSearchForm(forms.Form): @@ -14,7 +14,7 @@ class BigSearchForm(forms.Form): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # If wayback maintenance is on, disable the search box - maintenance = get_constant("wayback_maintenance") or False + maintenance = SiteConfiguration.get_solo().wayback_maintenance or False self.fields["query"].disabled = maintenance if maintenance: self.fields["query"].widget.attrs["placeholder"] = _( diff --git a/Seeder/www/templates/base_www.html b/Seeder/www/templates/base_www.html index c53ef1dd..b44c3509 100644 --- a/Seeder/www/templates/base_www.html +++ b/Seeder/www/templates/base_www.html @@ -1,6 +1,6 @@ -{% load i18n raven core json_constants %} +{% load i18n raven core %} {% get_current_language as lang %} -{% json_constant "wayback_maintenance" as wayback_maintenance%} +{% config "wayback_maintenance" as wayback_maintenance%} @@ -110,9 +110,9 @@
    {% if lang == "cs" %} - {% json_constant "wayback_maintenance_text_cs" as text %} + {% config "wayback_maintenance_text_cs" as text %} {% else %} - {% json_constant "wayback_maintenance_text_en" as text %} + {% config "wayback_maintenance_text_en" as text %} {% endif %} {{ text|safe }}
    diff --git a/Seeder/www/templates/index.html b/Seeder/www/templates/index.html index 873500f1..d91b2ae3 100644 --- a/Seeder/www/templates/index.html +++ b/Seeder/www/templates/index.html @@ -1,6 +1,5 @@ {% extends "base_www.html" %} -{% load i18n %} -{% load json_constants %} +{% load i18n core %} {% get_current_language as lang %} @@ -143,14 +142,14 @@

    {{ news_article.source_2 } {% if lang == "cs" %}

    Webarchiv k {% now "SHORT_DATE_FORMAT" %} obsahuje {% json_constant "webarchive_size" %} dat. První dokument byl + class="h1-size">{% config "webarchive_size" %} dat. První dokument byl archivován 3. 9. 2001.



    Celkem jsme s autory uzavřeli {{ contract_count }} smluv. Poslední aktuální smlouvy:

    {% else %}

    Webarchiv contains to {% now "SHORT_DATE_FORMAT" %} {% json_constant "webarchive_size" %} data. The first website + class="h1-size">{% config "webarchive_size" %} data. The first website was harvested in 3. 9. 2001.



    We concluded {{ contract_count }} contracts with a publishers at the diff --git a/requirements.txt b/requirements.txt index 2fefc016..2156f0f8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,6 +24,7 @@ django-multiupload==0.5.2 django-ordered-model==3.3.0 django-recaptcha==1.3.1 django-reversion==3.0.2 +django-solo==2.0.0 django-tables2==2.0.0a3 Django==2.2.28 djangorestframework==3.11.2