From 70bf6eab1113383a047f3a23cd67484141d183ee Mon Sep 17 00:00:00 2001 From: Merlin Buczek Date: Sun, 2 Jun 2019 11:48:54 +0200 Subject: [PATCH] News styling --- mpicms/base/templatetags/__init__.py | 0 mpicms/base/templatetags/url_tags.py | 11 ++++ mpicms/news/models.py | 20 ++++++ mpicms/static/css/custom.css | 32 ++++++++-- .../templates/base/components/pagination.html | 61 +++++++++++++++++++ mpicms/templates/news/components/cards.html | 2 +- .../templates/news/components/news_list.html | 2 +- .../news/components/news_preview.html | 2 +- mpicms/templates/news/news_page.html | 18 ++++-- 9 files changed, 134 insertions(+), 14 deletions(-) create mode 100644 mpicms/base/templatetags/__init__.py create mode 100644 mpicms/base/templatetags/url_tags.py create mode 100644 mpicms/templates/base/components/pagination.html diff --git a/mpicms/base/templatetags/__init__.py b/mpicms/base/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mpicms/base/templatetags/url_tags.py b/mpicms/base/templatetags/url_tags.py new file mode 100644 index 0000000..230f164 --- /dev/null +++ b/mpicms/base/templatetags/url_tags.py @@ -0,0 +1,11 @@ +from django import template + + +register = template.Library() + + +@register.simple_tag +def url_replace(request, field, value): + dict_ = request.GET.copy() + dict_[field] = value + return dict_.urlencode() diff --git a/mpicms/news/models.py b/mpicms/news/models.py index af456af..8f7835a 100644 --- a/mpicms/news/models.py +++ b/mpicms/news/models.py @@ -1,5 +1,6 @@ from django.db import models from django.utils.translation import gettext as _ +from django.core.paginator import EmptyPage, PageNotAnInteger, Paginator from wagtail.core.models import Page from wagtail.core.fields import RichTextField @@ -17,6 +18,24 @@ class NewsPage(CategoryMixin, Page): parent_page_types = ['base.CategoryPage', 'base.HomePage'] subpage_types = ['NewsEntry'] show_in_menus_default = False + paginated_by = 2 + + def get_context(self, request, *args, **kwargs): + context = super().get_context(request, *args, **kwargs) + + paginator = Paginator(self.news_items, self.paginated_by) + + page = request.GET.get("page") + try: + posts = paginator.page(page) + except PageNotAnInteger: + posts = paginator.page(1) + except EmptyPage: + posts = paginator.page(paginator.num_pages) + + context['paginator'] = paginator + context["news_items"] = posts + return context @property def news_items(self): @@ -43,5 +62,6 @@ class NewsEntry(CategoryMixin, Page): parent_page_types = ['NewsPage'] class Meta: # noqa + ordering = ['-date'] verbose_name = _("news entry") verbose_name_plural = _("news entries") diff --git a/mpicms/static/css/custom.css b/mpicms/static/css/custom.css index 1b5fa78..50b9506 100644 --- a/mpicms/static/css/custom.css +++ b/mpicms/static/css/custom.css @@ -177,13 +177,24 @@ select, input { } .card { - margin: 1rem; + margin: 1rem 2rem 1rem 0; flex-grow: 1; - flex-basis: 18rem; width: inherit; flex-shrink: 0; } +.is-preview { + flex-basis: 18rem; +} + +.category-label { + float: right; + font-size: 90%; + font-weight: bold; + text-transform: uppercase; + color: grey; +} + .flex-align { display: flex !important; flex-wrap: nowrap; @@ -235,10 +246,6 @@ select, input { background: #eeeeee; } -.fa-chevron-right { - padding-left: 0.8rem; -} - .select:not(.is-multiple):not(.is-loading)::after { border-color: #006c66; } @@ -246,4 +253,17 @@ select, input { /* Full Calendar */ .fc-button { border-radius: 0 !important; +} + +/* Pagination */ +.is-current { + background-color: transparent !important; + border-color: #006c66 !important; + /* font-weight: bold; */ +} + +.pagination-link, .pagination-next, .pagination-previous { + border-radius: 0 !important; + color: black !important; + /* box-shadow: 1px 1px 0px 0px #eeeeee; */ } \ No newline at end of file diff --git a/mpicms/templates/base/components/pagination.html b/mpicms/templates/base/components/pagination.html new file mode 100644 index 0000000..e1635fd --- /dev/null +++ b/mpicms/templates/base/components/pagination.html @@ -0,0 +1,61 @@ +{% load url_tags %} + +{% firstof items.number '1' as current %} + + + + \ No newline at end of file diff --git a/mpicms/templates/news/components/cards.html b/mpicms/templates/news/components/cards.html index 3bc0d7c..fec8594 100644 --- a/mpicms/templates/news/components/cards.html +++ b/mpicms/templates/news/components/cards.html @@ -2,7 +2,7 @@
{% for item in items|slice:3 %} -
+
{{ item.title }} diff --git a/mpicms/templates/news/components/news_list.html b/mpicms/templates/news/components/news_list.html index ce6dfc2..268273f 100644 --- a/mpicms/templates/news/components/news_list.html +++ b/mpicms/templates/news/components/news_list.html @@ -2,7 +2,7 @@ {% load wagtailcore_tags %} {% for news_page in news %} - {% with news_page.get_children.live as news_entries %} + {% with news_page.specific.news_items as news_entries %} {% if news_entries %}

{{ news_page.title }}