From 0b270a76ad73162f894285c360a0ee87fa84e536 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 12 Mar 2024 10:00:44 +0100 Subject: [PATCH] Hidden infopages. --- src/infopages/admin.py | 2 +- ...05_infopage_findable_infopage_published.py | 25 ++++++++++++++++ src/infopages/models.py | 5 ++++ .../templates/infopages/infopage.html | 29 ++++++++++++------- src/infopages/views.py | 5 +++- src/search/views.py | 2 ++ 6 files changed, 55 insertions(+), 13 deletions(-) create mode 100644 src/infopages/migrations/0005_infopage_findable_infopage_published.py diff --git a/src/infopages/admin.py b/src/infopages/admin.py index b8001a625..e681445a3 100644 --- a/src/infopages/admin.py +++ b/src/infopages/admin.py @@ -8,6 +8,6 @@ from infopages.models import InfoPage class InfoPageAdmin(TranslationAdmin): - list_display = ('title', 'slug') + list_display = ('title', 'slug', 'published', 'findable') admin.site.register(InfoPage, InfoPageAdmin) diff --git a/src/infopages/migrations/0005_infopage_findable_infopage_published.py b/src/infopages/migrations/0005_infopage_findable_infopage_published.py new file mode 100644 index 000000000..8e1e47ad9 --- /dev/null +++ b/src/infopages/migrations/0005_infopage_findable_infopage_published.py @@ -0,0 +1,25 @@ +# Generated by Django 4.0.8 on 2024-03-12 08:50 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('infopages', '0004_alter_infopage_options_alter_infopage_left_column_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='infopage', + name='findable', + field=models.BooleanField(default=True, verbose_name='wyszukiwalna'), + preserve_default=False, + ), + migrations.AddField( + model_name='infopage', + name='published', + field=models.BooleanField(default=True, help_text='Nieopublikowane strony są widoczne tylko dla administratorów.', verbose_name='opublikowana'), + preserve_default=False, + ), + ] diff --git a/src/infopages/models.py b/src/infopages/models.py index d398c75a5..d273b54a1 100644 --- a/src/infopages/models.py +++ b/src/infopages/models.py @@ -10,6 +10,11 @@ class InfoPage(models.Model): slug = models.SlugField('slug', max_length=120, unique=True, db_index=True) title = models.CharField('tytuł', max_length=120, blank=True) + published = models.BooleanField( + 'opublikowana', + help_text='Nieopublikowane strony są widoczne tylko dla administratorów.' + ) + findable = models.BooleanField('wyszukiwalna') left_column = models.TextField('lewa kolumna', blank=True) right_column = models.TextField('prawa kolumna', blank=True) diff --git a/src/infopages/templates/infopages/infopage.html b/src/infopages/templates/infopages/infopage.html index 5c6da3510..7bd5faa60 100644 --- a/src/infopages/templates/infopages/infopage.html +++ b/src/infopages/templates/infopages/infopage.html @@ -7,17 +7,24 @@ {% block main %} -
-

{{ page.title }}

+ {% if not page.published %} +
+ (Strona nie opublikowana, podgląd tylko dla zespołu.)
-
-
-
- {{ left_column }} -
-
- {{ right_column }} -
+ + {% endif %} + +
+

{{ page.title }}

+
+
+
+
+ {{ left_column }}
-
+
+ {{ right_column }} +
+
+
{% endblock %} diff --git a/src/infopages/views.py b/src/infopages/views.py index a32131024..3d1749f67 100644 --- a/src/infopages/views.py +++ b/src/infopages/views.py @@ -8,7 +8,10 @@ from infopages.models import InfoPage def infopage(request, slug): - page = get_object_or_404(InfoPage, slug=slug) + if request.user.is_staff: + page = get_object_or_404(InfoPage, slug=slug) + else: + page = get_object_or_404(InfoPage, slug=slug, published=True) rc = RequestContext(request) try: diff --git a/src/search/views.py b/src/search/views.py index 2f9adab36..dc7559fc9 100644 --- a/src/search/views.py +++ b/src/search/views.py @@ -116,6 +116,8 @@ def hint(request, mozhint=False, param='term'): ]) if len(data) < limit: infos = infopages.models.InfoPage.objects.filter( + published=True, + findable=True, title_pl__iregex='\m' + prefix).only('title', 'id', 'slug') data.extend([ { -- 2.20.1