diff --git a/home/__pycache__/models.cpython-38.pyc b/home/__pycache__/models.cpython-38.pyc index a7da3d9..25505a0 100644 Binary files a/home/__pycache__/models.cpython-38.pyc and b/home/__pycache__/models.cpython-38.pyc differ diff --git a/home/migrations/0004_auto_20210318_1554.py b/home/migrations/0004_auto_20210318_1554.py new file mode 100644 index 0000000..b8e2866 --- /dev/null +++ b/home/migrations/0004_auto_20210318_1554.py @@ -0,0 +1,50 @@ +# Generated by Django 3.1.7 on 2021-03-18 14:54 + +from django.db import migrations, models +import django.db.models.deletion +import modelcluster.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('wagtailimages', '0023_add_choose_permissions'), + ('home', '0003_homepage_body'), + ] + + operations = [ + migrations.AddField( + model_name='homepage', + name='address', + field=models.CharField(blank=True, default='', max_length=255, verbose_name='Adresa'), + ), + migrations.AddField( + model_name='homepage', + name='email', + field=models.EmailField(blank=True, max_length=64, null=True, verbose_name='E-mail'), + ), + migrations.AddField( + model_name='homepage', + name='map_link', + field=models.URLField(blank=True, default='', max_length=128, verbose_name='Odkaz na mapu'), + ), + migrations.AddField( + model_name='homepage', + name='mobile', + field=models.CharField(blank=True, default='', max_length=24, verbose_name='Mobil'), + ), + migrations.CreateModel( + name='CarouselImage', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('sort_order', models.IntegerField(blank=True, editable=False, null=True)), + ('caption', models.CharField(blank=True, max_length=250)), + ('image', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='+', to='wagtailimages.image')), + ('page', modelcluster.fields.ParentalKey(on_delete=django.db.models.deletion.CASCADE, related_name='carousel_images', to='home.homepage')), + ], + options={ + 'ordering': ['sort_order'], + 'abstract': False, + }, + ), + ] diff --git a/home/migrations/__pycache__/0004_auto_20210318_1554.cpython-38.pyc b/home/migrations/__pycache__/0004_auto_20210318_1554.cpython-38.pyc new file mode 100644 index 0000000..70eeead Binary files /dev/null and b/home/migrations/__pycache__/0004_auto_20210318_1554.cpython-38.pyc differ diff --git a/home/models.py b/home/models.py index af7b579..fc94612 100644 --- a/home/models.py +++ b/home/models.py @@ -1,7 +1,51 @@ from django.db import models -from wagtail.core.models import Page +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 +from wagtail.api import APIField class HomePage(Page): - pass + body = RichTextField(blank=True) + address = models.CharField(max_length=255, verbose_name="Adresa", blank=True, default='') + mobile = models.CharField(max_length=24, verbose_name="Mobil", blank=True, default='') + email = models.EmailField(max_length=64, verbose_name="E-mail", blank=True, null=True) + map_link = models.URLField(max_length=128, verbose_name="Odkaz na mapu", blank=True, default='') + + content_panels = Page.content_panels + [ + FieldPanel('body', classname="full"), + FieldPanel('address'), + FieldPanel('mobile'), + FieldPanel('email'), + FieldPanel('map_link'), + InlinePanel('carousel_images', label="Obrázky"), + ] + + search_fields = Page.search_fields + [ + index.SearchField('body'), + ] + + api_fields = [ + APIField('carousel_images'), + ] + + +class CarouselImage(Orderable): + page = ParentalKey(HomePage, on_delete=models.CASCADE, related_name='carousel_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'), + ] + + api_fields = [ + APIField('image'), + APIField('caption'), + ] \ No newline at end of file diff --git a/home/templates/home/home_page.html b/home/templates/home/home_page.html index ac266f2..83fa124 100644 --- a/home/templates/home/home_page.html +++ b/home/templates/home/home_page.html @@ -10,7 +10,50 @@ {% block content %} {{ page.body|richtext }} +
+ + + {{ page.map_link }} + + + + + + + + {% endblock content %} + +(* block extra_js *) + + + + + + + + diff --git a/hvezda/__pycache__/api.cpython-38.pyc b/hvezda/__pycache__/api.cpython-38.pyc new file mode 100644 index 0000000..aaf5d67 Binary files /dev/null and b/hvezda/__pycache__/api.cpython-38.pyc differ diff --git a/hvezda/__pycache__/urls.cpython-38.pyc b/hvezda/__pycache__/urls.cpython-38.pyc index 7a0c5d2..3cc2ad7 100644 Binary files a/hvezda/__pycache__/urls.cpython-38.pyc and b/hvezda/__pycache__/urls.cpython-38.pyc differ diff --git a/hvezda/api.py b/hvezda/api.py new file mode 100644 index 0000000..9ff53df --- /dev/null +++ b/hvezda/api.py @@ -0,0 +1,15 @@ +from wagtail.api.v2.views import PagesAPIViewSet +from wagtail.api.v2.router import WagtailAPIRouter +from wagtail.images.api.v2.views import ImagesAPIViewSet +from wagtail.documents.api.v2.views import DocumentsAPIViewSet + +# Create the router. "wagtailapi" is the URL namespace +api_router = WagtailAPIRouter('wagtailapi') + +# Add the three endpoints using the "register_endpoint" method. +# The first parameter is the name of the endpoint (eg. pages, images). This +# is used in the URL of the endpoint +# The second parameter is the endpoint class that handles the requests +api_router.register_endpoint('pages', PagesAPIViewSet) +api_router.register_endpoint('images', ImagesAPIViewSet) +api_router.register_endpoint('documents', DocumentsAPIViewSet) \ No newline at end of file diff --git a/hvezda/settings/__pycache__/base.cpython-38.pyc b/hvezda/settings/__pycache__/base.cpython-38.pyc index 2d599f6..9260efb 100644 Binary files a/hvezda/settings/__pycache__/base.cpython-38.pyc and b/hvezda/settings/__pycache__/base.cpython-38.pyc differ diff --git a/hvezda/settings/api.py b/hvezda/settings/api.py new file mode 100644 index 0000000..9ff53df --- /dev/null +++ b/hvezda/settings/api.py @@ -0,0 +1,15 @@ +from wagtail.api.v2.views import PagesAPIViewSet +from wagtail.api.v2.router import WagtailAPIRouter +from wagtail.images.api.v2.views import ImagesAPIViewSet +from wagtail.documents.api.v2.views import DocumentsAPIViewSet + +# Create the router. "wagtailapi" is the URL namespace +api_router = WagtailAPIRouter('wagtailapi') + +# Add the three endpoints using the "register_endpoint" method. +# The first parameter is the name of the endpoint (eg. pages, images). This +# is used in the URL of the endpoint +# The second parameter is the endpoint class that handles the requests +api_router.register_endpoint('pages', PagesAPIViewSet) +api_router.register_endpoint('images', ImagesAPIViewSet) +api_router.register_endpoint('documents', DocumentsAPIViewSet) \ No newline at end of file diff --git a/hvezda/settings/base.py b/hvezda/settings/base.py index bb1c465..4417471 100644 --- a/hvezda/settings/base.py +++ b/hvezda/settings/base.py @@ -37,8 +37,9 @@ INSTALLED_APPS = [ 'wagtail.images', 'wagtail.search', 'wagtail.admin', + 'rest_framework', + 'wagtail.api.v2', 'wagtail.core', - 'modelcluster', 'taggit', diff --git a/hvezda/templates/base.html b/hvezda/templates/base.html index 9fbf28a..c29781e 100644 --- a/hvezda/templates/base.html +++ b/hvezda/templates/base.html @@ -19,6 +19,7 @@ {# Global stylesheets #} + {% block extra_css %} {# Override this in templates to add extra stylesheets #} @@ -26,12 +27,30 @@ + + {% wagtailuserbar %} - {% block content %}{% endblock %} +