From a3788f3b1bca9466f2ec0fd01ef7c763f2f4c993 Mon Sep 17 00:00:00 2001 From: petr Date: Sat, 28 Nov 2020 14:50:20 +0100 Subject: [PATCH] konecne upravy --- tip/__init__.py | 0 tip/admin.py | 3 + tip/apps.py | 5 ++ tip/models.py | 92 +++++++++++++++++++++++++++ tip/templates/tip/tip_index_page.html | 38 +++++++++++ tip/templates/tip/tip_page.html | 35 ++++++++++ tip/tests.py | 3 + tip/views.py | 3 + ubytovani/settings/base.py | 1 + ubytovani/static/css/ubytovani.css | 7 +- ubytovani/templates/base.html | 6 +- 11 files changed, 189 insertions(+), 4 deletions(-) create mode 100644 tip/__init__.py create mode 100644 tip/admin.py create mode 100644 tip/apps.py create mode 100644 tip/models.py create mode 100644 tip/templates/tip/tip_index_page.html create mode 100644 tip/templates/tip/tip_page.html create mode 100644 tip/tests.py create mode 100644 tip/views.py diff --git a/tip/__init__.py b/tip/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tip/admin.py b/tip/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/tip/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/tip/apps.py b/tip/apps.py new file mode 100644 index 0000000..98f4ba5 --- /dev/null +++ b/tip/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class TipConfig(AppConfig): + name = 'tip' diff --git a/tip/models.py b/tip/models.py new file mode 100644 index 0000000..bfd75a3 --- /dev/null +++ b/tip/models.py @@ -0,0 +1,92 @@ +from django.db import models + +from modelcluster.fields import ParentalKey + +from wagtail.core.models import Page, Orderable +from wagtail.core.fields import RichTextField +from wagtail.admin.edit_handlers import FieldPanel, InlinePanel +from wagtail.images.edit_handlers import ImageChooserPanel +from wagtail.search import index + + +class TipIndexPage(Page): + intro = RichTextField(blank=True) + + content_panels = Page.content_panels + [ + FieldPanel('intro', classname="full") + ] + + +class TipPage(Page): + date = models.DateField("Post date") + intro = models.CharField(max_length=250) + body = RichTextField(blank=True) + + def main_image(self): + gallery_item = self.gallery_images.first() + if gallery_item: + return gallery_item.image + else: + return None + + search_fields = Page.search_fields + [ + index.SearchField('intro'), + index.SearchField('body'), + ] + + content_panels = Page.content_panels + [ + FieldPanel('date'), + FieldPanel('intro'), + FieldPanel('body', classname="full"), + InlinePanel('gallery_images', label="Obrázky"), + ] + + +class TipPageGalleryImage(Orderable): + page = ParentalKey(TipPage, on_delete=models.CASCADE, related_name='gallery_images') + image = models.ForeignKey( + 'wagtailimages.Image', on_delete=models.CASCADE, related_name='+' + ) + caption = models.CharField(blank=True, max_length=250) + + panels = [ + ImageChooserPanel('image'), + FieldPanel('caption'), + ] + +class TipPage(Page): + date = models.DateField("Post date") + intro = models.CharField(max_length=250) + body = RichTextField(blank=True) + + def main_image(self): + gallery_item = self.gallery_images.first() + if gallery_item: + return gallery_item.image + else: + return None + + search_fields = Page.search_fields + [ + index.SearchField('intro'), + index.SearchField('body'), + ] + + content_panels = Page.content_panels + [ + FieldPanel('date'), + FieldPanel('intro'), + FieldPanel('body', classname="full"), + InlinePanel('gallery_images', label="Obrázky"), + ] + + +class TipPageGalleryImage(Orderable): + page = ParentalKey(TipPage, on_delete=models.CASCADE, related_name='gallery_images') + image = models.ForeignKey( + 'wagtailimages.Image', on_delete=models.CASCADE, related_name='+' + ) + caption = models.CharField(blank=True, max_length=250) + + panels = [ + ImageChooserPanel('image'), + FieldPanel('caption'), + ] diff --git a/tip/templates/tip/tip_index_page.html b/tip/templates/tip/tip_index_page.html new file mode 100644 index 0000000..3009422 --- /dev/null +++ b/tip/templates/tip/tip_index_page.html @@ -0,0 +1,38 @@ +{% extends "base.html" %} + +{% load wagtailcore_tags wagtailimages_tags static %} + +{% block body_class %}template-blogindexpage{% endblock %} + +{% block content %} + +

{{ page.title }}

+ +
{{ page.intro|richtext }}
+ + {% for post in page.get_children %} + {% with post=post.specific %} +
+
+
+ {% with post.main_image as main_image %} + {% if main_image %} + {% image main_image class="card-img" fill-400x150 %} + {% else %} + blank image + {% endif %} + {% endwith %} +
+
+
+
{{ post.title }}
+

{{ post.intro }}

+

{{ post.date }}

+
+
+
+
+ {% endwith %} + {% endfor %} + +{% endblock %} diff --git a/tip/templates/tip/tip_page.html b/tip/templates/tip/tip_page.html new file mode 100644 index 0000000..880333e --- /dev/null +++ b/tip/templates/tip/tip_page.html @@ -0,0 +1,35 @@ +{% extends "base.html" %} + +{% load wagtailcore_tags wagtailimages_tags %} + +{% block body_class %}template-blogpage{% endblock %} + +{% block content %} +

{{ page.title }}

+
+
+
+ {% for item in page.gallery_images.all %} +
+ {% image item.image fill-320x240 %} +

{{ item.caption }}

+
+ {% endfor %} +
+
+
+ + +
{{ page.intro }}
+ + {{ page.body|richtext }} +

{{ page.date }}

+
+
+
+
+ + +

Return to blog

+ +{% endblock %} \ No newline at end of file diff --git a/tip/tests.py b/tip/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/tip/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/tip/views.py b/tip/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/tip/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/ubytovani/settings/base.py b/ubytovani/settings/base.py index 19ac10d..0212f04 100644 --- a/ubytovani/settings/base.py +++ b/ubytovani/settings/base.py @@ -50,6 +50,7 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'stranky', 'galeri', + 'tip', ] MIDDLEWARE = [ diff --git a/ubytovani/static/css/ubytovani.css b/ubytovani/static/css/ubytovani.css index e53ac34..61d7153 100644 --- a/ubytovani/static/css/ubytovani.css +++ b/ubytovani/static/css/ubytovani.css @@ -3,7 +3,7 @@ main > .container { } .footer { - background-color: #f5f5f5; + background-color: #f5f5f5d8; } .footer > .container { @@ -13,4 +13,9 @@ main > .container { code { font-size: 80%; + } + + img{ + width: 400px; + height: 300px; } \ No newline at end of file diff --git a/ubytovani/templates/base.html b/ubytovani/templates/base.html index ebf3aad..92d1aa2 100644 --- a/ubytovani/templates/base.html +++ b/ubytovani/templates/base.html @@ -40,13 +40,13 @@