Hidden infopages.
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 12 Mar 2024 09:00:44 +0000 (10:00 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 12 Mar 2024 09:00:44 +0000 (10:00 +0100)
src/infopages/admin.py
src/infopages/migrations/0005_infopage_findable_infopage_published.py [new file with mode: 0644]
src/infopages/models.py
src/infopages/templates/infopages/infopage.html
src/infopages/views.py
src/search/views.py

index b8001a6..e681445 100644 (file)
@@ -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 (file)
index 0000000..8e1e47a
--- /dev/null
@@ -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,
+        ),
+    ]
index d398c75..d273b54 100644 (file)
@@ -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)
 
index 5c6da35..7bd5faa 100644 (file)
@@ -7,17 +7,24 @@
 
 
 {% block main %}
-    <div class="l-article__title">
-      <h1>{{ page.title }}</h1>
+  {% if not page.published %}
+    <div class="l-container">
+      <strong>(Strona nie opublikowana, podgląd tylko dla zespołu.)</strong>
     </div>
-    <article class="l-article">
-      <div class="l-article__cols">
-        <div class="left-column">
-          {{ left_column }}
-        </div>
-        <div class="right-column">
-          {{ right_column }}
-        </div>
+
+  {% endif %}
+
+  <div class="l-article__title">
+    <h1>{{ page.title }}</h1>
+  </div>
+  <article class="l-article">
+    <div class="l-article__cols">
+      <div class="left-column">
+        {{ left_column }}
       </div>
-    </article>
+      <div class="right-column">
+        {{ right_column }}
+      </div>
+    </div>
+  </article>
 {% endblock %}
index a321310..3d1749f 100644 (file)
@@ -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:
index 2f9adab..dc7559f 100644 (file)
@@ -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([
             {