diff --git a/core/admin.py b/core/admin.py index 37344a7..5173fdb 100644 --- a/core/admin.py +++ b/core/admin.py @@ -1,6 +1,5 @@ -from django.apps import apps as _apps from django.contrib import admin -from django.contrib.admin.sites import AlreadyRegistered +from django.utils.safestring import mark_safe from .models import * from admin_ordering.admin import OrderableAdmin @@ -8,47 +7,44 @@ from admin_ordering.admin import OrderableAdmin # Register your models here. -@admin.register(Button) +@admin.register(Button, UpperButton) class ButtonModelAdmin(OrderableAdmin, admin.ModelAdmin): - list_display = ['__str__', 'published', 'ordering'] - list_editable = ['ordering'] + list_display = ["__str__", "published", "ordering"] + list_editable = ["ordering"] ordering_field_hide_input = True - exclude = ['ordering'] + exclude = ["ordering"] - -@admin.register(UpperButton) -class UpperButtonModelAdmin(OrderableAdmin, admin.ModelAdmin): - list_display = ['__str__', 'published', 'ordering'] - list_editable = ['ordering'] +@admin.register(AdditionalPagePost) +class AdditionalPagePostModelAdmin(OrderableAdmin, admin.ModelAdmin): + list_display = ["__str__", "published", "ordering"] + list_editable = ["ordering"] ordering_field_hide_input = True - exclude = ['ordering'] + exclude = ["ordering"] -apps = [ - 'main', - 'administration', - 'league', - 'calendar', - 'gpb', - 'tournaments', - 'membership', - 'youth', - 'atu', - 'mbkb', - 'core' -] - -for app in [app for name, app in _apps.app_configs.items() if name in apps]: - app_models = app.get_models() - for model in app_models: - try: - admin.site.register(model) - except AlreadyRegistered: - pass +# @admin.register(AdditionalPagePost) +class AdditionalPagePostInline(OrderableAdmin, admin.TabularInline): + model = AdditionalPagePost + list_editable = ["ordering"] + ordering_field_hide_input = True + fields = ["title", "ordering"] + show_change_link = True + extra = 0 -admin.site.site_header = 'labs' -admin.site.site_title = 'labs' -admin.site.index_title = 'Panel administracyjny' -admin.site.site_url = '/' -admin.site.enable_nav_sidebar = False +@admin.register(AdditionalPage) +class AdditionalPageModelAdmin(OrderableAdmin, admin.ModelAdmin): + list_display = ["__str__", "published"] + readonly_fields = ["posts"] + inlines = [AdditionalPagePostInline] + + @admin.display(description="Opublikowane posty") + def posts(self, obj): + return mark_safe(''.join([f'{p.title}
' for p in obj.posts.filter(published=True)])) + + +admin.site.site_header = "ŁABS" +admin.site.site_title = "ŁABS" +admin.site.index_title = "Panel administracyjny" +admin.site.site_url = "/" +admin.site.enable_nav_sidebar = True diff --git a/core/context_processors.py b/core/context_processors.py index 6bdce49..f012cb4 100644 --- a/core/context_processors.py +++ b/core/context_processors.py @@ -1,7 +1,6 @@ from .models import * from db.main.models import * -from db.youth.models import * def load_config(request): @@ -12,5 +11,4 @@ def load_config(request): 'middle_posts': MiddlePost.Published(), 'right_posts': RightPost.Published(), 'banner': Banner.Get(), - 'youth': Youth.Published(), } diff --git a/db/youth/migrations/0001_initial.py b/core/migrations/0002_additionalpage_additionalpagepost.py similarity index 70% rename from db/youth/migrations/0001_initial.py rename to core/migrations/0002_additionalpage_additionalpagepost.py index 0425aed..9895cf1 100644 --- a/db/youth/migrations/0001_initial.py +++ b/core/migrations/0002_additionalpage_additionalpagepost.py @@ -1,19 +1,31 @@ -# Generated by Django 5.0 on 2023-12-26 02:49 +# Generated by Django 5.0 on 2023-12-30 02:33 +import django.db.models.deletion import tinymce.models from django.db import migrations, models class Migration(migrations.Migration): - initial = True - dependencies = [ + ('core', '0001_initial'), ] operations = [ migrations.CreateModel( - name='Youth', + name='AdditionalPage', + fields=[ + ('published', models.BooleanField(default=False, verbose_name='Wpis opublikowany')), + ('slug', models.SlugField(max_length=255, primary_key=True, serialize=False, unique=True)), + ('title', models.CharField(max_length=255)), + ], + options={ + 'verbose_name': 'Dodatkowa zakładka', + 'verbose_name_plural': 'Dodatkowe zakładki', + }, + ), + migrations.CreateModel( + name='AdditionalPagePost', fields=[ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('ordering', models.IntegerField(default=0, verbose_name='Kolejność')), @@ -23,10 +35,11 @@ class Migration(migrations.Migration): ('content', tinymce.models.HTMLField(blank=True, default='', verbose_name='Treść')), ('buttons', models.TextField(blank=True, default='', help_text='Tutaj można wpisać dowolną ilość przycisków w następującym formacie:

tekst1 -> link
teskt2 | link
...

Symbol -> oznacza, że link będzie otwarty w nowej karcie
Symbol | oznacza, że link będzie otwarty w tej samej karcie
Na przykład:

pzbs -> https://pzbs.pl
fotogaleria | https://galeria.podlaskizbs.pl
cezar -> https://www.msc.com.pl/cezar

PZBS i Cezar zostaną otwarte w nowej karcie
UWAGA !!
Gdy nie podamy tekstu przyciku, nie pokaże on się, można to wykorzystać w taki sposób:

-> link do wyników
fotogaleria -> link do fotogalerii

Wtedy pokaże się tylko przycisk fotogalerii
', verbose_name='Przyciski')), ('created_at', models.DateTimeField(auto_now_add=True)), + ('page', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='core.additionalpage')), ], options={ - 'verbose_name': 'Post młodzieżowy', - 'verbose_name_plural': 'Posty młodzieżowe', + 'verbose_name': 'Post na stronie', + 'verbose_name_plural': 'Posty na stronie', 'ordering': ['ordering'], 'abstract': False, }, diff --git a/core/models.py b/core/models.py index 9b478db..6ba9023 100644 --- a/core/models.py +++ b/core/models.py @@ -1,38 +1,77 @@ from django.db import models +from django.db.models import signals from admin_ordering.models import OrderableModel from filebrowser.fields import FileBrowseField +from .utils import PostableModel, PublishableModel # Create your models here. -class Button(OrderableModel): - published = models.BooleanField('Przycisk opublikowany', default=True) - title = models.CharField('Tekst na przycisku', max_length=50) - href = models.CharField('Link', max_length=50) - blank = models.BooleanField('Otwórz w nowej karcie') + +class AdditionalPage(PublishableModel): + published = models.BooleanField('Strona opublikowana', default=False) + slug = models.SlugField('Link', max_length=255, unique=True, primary_key=True) + title = models.CharField('Nazwa', max_length=255) def __str__(self): - return self.title or '-' + return self.title + + class Meta: + verbose_name = "Dodatkowa zakładka" + verbose_name_plural = "Dodatkowe zakładki" + + +class AdditionalPagePost(PostableModel): + page = models.ForeignKey(AdditionalPage, on_delete=models.CASCADE, related_name='posts', verbose_name='Strona') + reverse_href = "post-reverse" + + class Meta(OrderableModel.Meta): + verbose_name = "Post na stronie" + verbose_name_plural = "Posty na stronie" + + +class Button(OrderableModel): + published = models.BooleanField("Przycisk opublikowany", default=True) + title = models.CharField("Tekst na przycisku", max_length=50) + href = models.CharField("Link", max_length=50) + blank = models.BooleanField("Otwórz w nowej karcie") + + def __str__(self): + return self.title or "-" @property def link(self): return self.href class Meta(OrderableModel.Meta): - verbose_name = 'Przycisk nawigacji (zielony)' - verbose_name_plural = 'Przyciski nawigacji (zielone)' + verbose_name = "Przycisk nawigacji (zielony)" + verbose_name_plural = "Przyciski nawigacji (zielone)" class UpperButton(OrderableModel): - published = models.BooleanField('Przycisk opublikowany', default=True) - title = models.CharField('Tytuł przycisku', max_length=50) + published = models.BooleanField("Przycisk opublikowany", default=True) + title = models.CharField("Tytuł przycisku", max_length=50) photo = FileBrowseField( - 'Ikona', directory='gorneprzyciski/', max_length=200, blank=True) - href = models.CharField('Link', max_length=50) - blank = models.BooleanField('Otwórz w nowej karcie') + "Ikona", directory="gorneprzyciski/", max_length=200, blank=True + ) + href = models.CharField("Link", max_length=50) + blank = models.BooleanField("Otwórz w nowej karcie") def __str__(self): - return self.title or '-' + return self.title or "-" class Meta(OrderableModel.Meta): - verbose_name = 'Przycisk górny (łabs, atu, itd...)' - verbose_name_plural = 'Przyciski górne (łabs, atu, itd...)' + verbose_name = "Przycisk górny (łabs, atu, itd...)" + verbose_name_plural = "Przyciski górne (łabs, atu, itd...)" + + +def create_page_button(sender, instance, created, **kwargs): + if created: + Button.objects.create(href=instance.slug, title=instance.title, published=False, blank=False) + + +signals.post_save.connect( + create_page_button, + sender=AdditionalPage, + weak=False, + dispatch_uid="models.create_page_button", +) diff --git a/core/static/labs.png b/core/static/labs.png index e80ed5f..5845693 100644 Binary files a/core/static/labs.png and b/core/static/labs.png differ diff --git a/core/static/lomza.jpg b/core/static/lomza.jpg new file mode 100644 index 0000000..a8bcff7 Binary files /dev/null and b/core/static/lomza.jpg differ diff --git a/core/static/msit.png b/core/static/msit.png new file mode 100644 index 0000000..1349e75 Binary files /dev/null and b/core/static/msit.png differ diff --git a/core/static/podlaskie.jpg b/core/static/podlaskie.jpg new file mode 100644 index 0000000..e75b361 Binary files /dev/null and b/core/static/podlaskie.jpg differ diff --git a/core/templates/base.html b/core/templates/base.html index 67c98b3..e70929f 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -2,7 +2,7 @@ {% load static wysiwyg tailwind_tags %} - + @@ -32,8 +32,8 @@ {% tailwind_css %} - -
+ +
-
+
    {% content banner %} +
    + {% buttons banner.buttons %} +
{% block content %}{% endblock %}
-