From 1994a48ec67f888b34ca152387157cb31cd949fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bedna=C5=99=C3=ADk?= <jan.bednarik@gmail.com> Date: Mon, 8 Feb 2021 15:56:19 +0100 Subject: [PATCH] district: Refactor and update --- district/migrations/0002_auto_20210205_1514.py | 18 ++++++++++++++++++ district/models.py | 6 ++---- district/templates/district/base.html | 13 ++++++++----- .../district_article_page.html} | 5 +---- ...ticles.html => district_articles_page.html} | 0 ...contact.html => district_contact_page.html} | 2 +- .../district_people_page.html} | 0 .../district_person_page.html} | 0 ...trict_tags.html => district_tags_page.html} | 0 shared/models.py | 12 ++++++------ shared/templates/shared/article_preview.html | 2 +- 11 files changed, 37 insertions(+), 21 deletions(-) create mode 100644 district/migrations/0002_auto_20210205_1514.py rename district/templates/{shared/article.html => district/district_article_page.html} (94%) rename district/templates/district/{district_articles.html => district_articles_page.html} (100%) rename district/templates/district/{district_contact.html => district_contact_page.html} (98%) rename district/templates/{shared/people_page.html => district/district_people_page.html} (100%) rename district/templates/{shared/person_page.html => district/district_person_page.html} (100%) rename district/templates/district/{district_tags.html => district_tags_page.html} (100%) diff --git a/district/migrations/0002_auto_20210205_1514.py b/district/migrations/0002_auto_20210205_1514.py new file mode 100644 index 00000000..0c9ccd22 --- /dev/null +++ b/district/migrations/0002_auto_20210205_1514.py @@ -0,0 +1,18 @@ +# Generated by Django 3.1.3 on 2021-02-05 14:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("district", "0001_initial"), + ] + + operations = [ + migrations.AlterField( + model_name="districtarticlepage", + name="perex", + field=models.TextField(verbose_name="perex"), + ), + ] diff --git a/district/models.py b/district/models.py index 25dcf9fe..89852ad4 100644 --- a/district/models.py +++ b/district/models.py @@ -176,9 +176,7 @@ class DistrictArticlePage(ArticleMixin, SubpageMixin, MetadataPageMixin, Page): class DistrictArticlesPage(SubpageMixin, MetadataPageMixin, Page): ### FIELDS - max_items = models.IntegerField( - "Maximalni pocet prvku na strance", blank=True, null=True - ) + max_items = models.IntegerField("Počet článků na stránce", default=12) ### PANELS @@ -202,7 +200,7 @@ class DistrictArticlesPage(SubpageMixin, MetadataPageMixin, Page): context = super().get_context(request) context["articles"] = Paginator( self.get_children().live().specific(), - self.max_items or 5, + self.max_items, ).get_page(request.GET.get("page")) return context diff --git a/district/templates/district/base.html b/district/templates/district/base.html index 61a895a5..7b446481 100644 --- a/district/templates/district/base.html +++ b/district/templates/district/base.html @@ -24,8 +24,8 @@ } </style> - {% if page.matomo_id %} - {% include "shared/matomo_snippet.html" with matomo_id=page.matomo_id %} + {% if page.root_page.matomo_id %} + {% include "shared/matomo_snippet.html" with matomo_id=page.root_page.matomo_id %} {% endif %} </head> @@ -79,12 +79,12 @@ <div v-if="show || isLgScreenSize" class="navbar__main navbar__section navbar__section--expandable container-padding--zero lg:container-padding--auto"> <ul class="navbar-menu text-white"> - <li class="navbar-menu__item"><a href="{{ page.root_page.articles_page.url }}" class="navbar-menu__link">{{ page.root_page.articles_page }}</a></li> - <li class="navbar-menu__item"><a href="{{ page.root_page.people_page.url }}" class="navbar-menu__link">{{ page.root_page.people_page }}</a></li> + <li class="navbar-menu__item"><a href="{% pageurl page.root_page.articles_page %}" class="navbar-menu__link">{{ page.root_page.articles_page }}</a></li> + <li class="navbar-menu__item"><a href="{% pageurl page.root_page.people_page %}" class="navbar-menu__link">{{ page.root_page.people_page }}</a></li> {% comment %} <li class="navbar-menu__item"><a href="/komunalni-program/" class="navbar-menu__link">Komunální program</a></li> {% endcomment %} - <li class="navbar-menu__item"><a href="{{ page.root_page.contact_page.url }}" class="navbar-menu__link">{{ page.root_page.contact_page }}</a></li> + <li class="navbar-menu__item"><a href="{% pageurl page.root_page.contact_page %}" class="navbar-menu__link">{{ page.root_page.contact_page }}</a></li> </ul> </div> @@ -119,6 +119,8 @@ <nav class="subnav py-2"> <div class="container container--wide"> <div class="flex"> + + {% comment %} <button @click="toggleView('regions')" class="btn btn--condensed btn--grey-500 btn--hoveractive btn--to-white text-sm mr-2 px-0" :class="{'btn--activated': isCurrentView('regions')}"> <div class="btn__body py-2"> <span>Piráti v dalších krajích</span> @@ -132,6 +134,7 @@ <span class="hidden md:block">Krajský kalendář</span> </div> </button> + {% endcomment %} {% if page.root_page.facebook %} <a href="{{ page.root_page.facebook }}" target="_blank" rel="noopener noreferrer" class="btn btn--inline-icon btn--condensed btn--hoveractive btn--grey-500 btn--to-brands-facebook text-sm ml-2 px-0"> diff --git a/district/templates/shared/article.html b/district/templates/district/district_article_page.html similarity index 94% rename from district/templates/shared/article.html rename to district/templates/district/district_article_page.html index 632a69ad..3fb3e61d 100644 --- a/district/templates/shared/article.html +++ b/district/templates/district/district_article_page.html @@ -19,9 +19,7 @@ <div class="inline-flex divide-x flex-grow"> <span class="pr-2">{{ page.date|date:"SHORT_DATE_FORMAT" }}</span> <span class="pl-2" itemprop="author" itemtype="http://schema.org/Person" itemscope=""> - <span itemprop="name"> - <a href="{{ page.author.url }}">{{ page.author.name }}</a> - </span> + <span itemprop="name">{{ page.author }}</span> </span> </div> @@ -44,7 +42,6 @@ <div class="lg:w-2/3"> <div itemprop="description" class="w-full content-block"> - <p><strong>{{ page.perex }}</strong></p> {{ page.text|richtext }} </div> </div> diff --git a/district/templates/district/district_articles.html b/district/templates/district/district_articles_page.html similarity index 100% rename from district/templates/district/district_articles.html rename to district/templates/district/district_articles_page.html diff --git a/district/templates/district/district_contact.html b/district/templates/district/district_contact_page.html similarity index 98% rename from district/templates/district/district_contact.html rename to district/templates/district/district_contact_page.html index b36d00c1..a5bd3d0b 100644 --- a/district/templates/district/district_contact.html +++ b/district/templates/district/district_contact_page.html @@ -13,7 +13,7 @@ <h1 itemprop="headline" class="head-alt-md md:head-alt-lg max-w-5xl mb-8">{{ page.title }}</h1> </header> - {% for item in page.contact_persons %} + {% for item in page.contact_people %} <div> <h2 class="head-heavy-sm mb-2 lg:mb-4 mt-4">{{ item.value.name }}</h2> diff --git a/district/templates/shared/people_page.html b/district/templates/district/district_people_page.html similarity index 100% rename from district/templates/shared/people_page.html rename to district/templates/district/district_people_page.html diff --git a/district/templates/shared/person_page.html b/district/templates/district/district_person_page.html similarity index 100% rename from district/templates/shared/person_page.html rename to district/templates/district/district_person_page.html diff --git a/district/templates/district/district_tags.html b/district/templates/district/district_tags_page.html similarity index 100% rename from district/templates/district/district_tags.html rename to district/templates/district/district_tags_page.html diff --git a/shared/models.py b/shared/models.py index 4007fae3..5eeeef30 100644 --- a/shared/models.py +++ b/shared/models.py @@ -22,7 +22,7 @@ class SubpageMixin: class ArticleMixin(models.Model): - """ Spolecna pole vsech clanku """ + """Common fields for articles""" RICH_TEXT_FEATURES = [ "h2", @@ -38,9 +38,10 @@ class ArticleMixin(models.Model): ### FIELDS - perex = models.CharField("perex", max_length=250, blank=True) - text = RichTextField("text článku", blank=True, features=RICH_TEXT_FEATURES) - date = models.DateField("datum článku", blank=False, default=timezone.now) + date = models.DateField("datum", default=timezone.now) + perex = models.TextField("perex") + text = RichTextField("článek", blank=True, features=RICH_TEXT_FEATURES) + author = models.CharField("autor", max_length=250, blank=True, null=True) image = models.ForeignKey( "wagtailimages.Image", on_delete=models.PROTECT, @@ -48,13 +49,12 @@ class ArticleMixin(models.Model): null=True, verbose_name="obrázek", ) - author = models.CharField("autor", max_length=250, blank=True, null=True) ### PANELS content_panels = Page.content_panels + [ - FieldPanel("perex"), FieldPanel("date"), + FieldPanel("perex"), FieldPanel("text"), FieldPanel("author"), ImageChooserPanel("image"), diff --git a/shared/templates/shared/article_preview.html b/shared/templates/shared/article_preview.html index d584cb22..5227cf33 100644 --- a/shared/templates/shared/article_preview.html +++ b/shared/templates/shared/article_preview.html @@ -33,7 +33,7 @@ <meta itemprop="datePublished" content="{{ article.last_published_at }}" /> </span> <span class="article-card-meta__item" itemprop="author" itemtype="http://schema.org/Person" itemscope=""> - <span itemprop="name">{{ article.author.name }}</span> + <span itemprop="name">{{ article.author }}</span> </span> </div> -- GitLab