Browse Source

kolotoc

master
petr 4 years ago
parent
commit
905575159b
  1. BIN
      home/__pycache__/models.cpython-38.pyc
  2. 50
      home/migrations/0004_auto_20210318_1554.py
  3. BIN
      home/migrations/__pycache__/0004_auto_20210318_1554.cpython-38.pyc
  4. 48
      home/models.py
  5. 43
      home/templates/home/home_page.html
  6. BIN
      hvezda/__pycache__/api.cpython-38.pyc
  7. BIN
      hvezda/__pycache__/urls.cpython-38.pyc
  8. 15
      hvezda/api.py
  9. BIN
      hvezda/settings/__pycache__/base.cpython-38.pyc
  10. 15
      hvezda/settings/api.py
  11. 3
      hvezda/settings/base.py
  12. 19
      hvezda/templates/base.html
  13. BIN
      hvezda/templates/hvezda.png
  14. 3
      hvezda/urls.py
  15. BIN
      media/images/logo.max-165x165.png
  16. BIN
      media/original_images/logo.png

BIN
home/__pycache__/models.cpython-38.pyc

Binary file not shown.

50
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,
},
),
]

BIN
home/migrations/__pycache__/0004_auto_20210318_1554.cpython-38.pyc

Binary file not shown.

48
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'),
]

43
home/templates/home/home_page.html

@ -10,7 +10,50 @@
{% block content %}
{{ page.body|richtext }}
<p class="meta">Adresa. {{ page.address }}</p>
<p class="meta">Tel. {{ page.mobile }}</p>
<p class="meta">Email. {{ page.email }}</p>
<a class="meta">{{ page.map_link }}</a>
{% endblock content %}
(* block extra_js *)
<script>
$. getJSON("/api/v2/pages/3/?type=home.HomePage&fields=carousel_images")
.done (function(data) {
console . log(data);
let images = [];
for (let index = 0; index < data.carousel_images. length; index++) {
const item = data.carousel_images[index];
console.log(item.caption);
console. log(item.image. meta.download_url),
images. push({
src: item.image.meta.download_url,
title: item.caption
});
}
let kolotoc = document.queryselector("muj-kolotoc");
kolotoc.images = images;
})
.fail(function() {
alert("Chyba pri dotazu do API.");
});
</script>

BIN
hvezda/__pycache__/api.cpython-38.pyc

Binary file not shown.

BIN
hvezda/__pycache__/urls.cpython-38.pyc

Binary file not shown.

15
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)

BIN
hvezda/settings/__pycache__/base.cpython-38.pyc

Binary file not shown.

15
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)

3
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',

19
hvezda/templates/base.html

@ -19,6 +19,7 @@
{# Global stylesheets #}
<link rel="stylesheet" type="text/css" href="{% static 'css/hvezda.css' %}">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-eOJMYsd53ii+scO/bJGFsiCZc+5NDVN2yr8+0RDqr0Ql0h+rP48ckxlpbzKgwra6" crossorigin="anonymous">
{% block extra_css %}
{# Override this in templates to add extra stylesheets #}
@ -26,12 +27,30 @@
</head>
<body class="{% block body_class %}{% endblock %}">
<nav class="navbar navbar-light" style="background-color: #e3f2fd;">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="./hvezda.png" alt="" width="30" height="24" class="d-inline-block align-text-top">
Bootstrap
</a>
</div>
</nav>
{% wagtailuserbar %}
<main class="container">
<div class="p-4 p-md-5 mb-4 text-white rounded bg-dark">
{% block content %}{% endblock %}
</div>
</main>
{# Global javascript #}
<script type="text/javascript" src="{% static 'js/hvezda.js' %}"></script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="{% static 'js/hvezda.js' %}"></script>
{% block extra_js %}
{# Override this in templates to add extra javascript #}

BIN
hvezda/templates/hvezda.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

3
hvezda/urls.py

@ -8,8 +8,11 @@ from wagtail.documents import urls as wagtaildocs_urls
from search import views as search_views
from .api import api_router
urlpatterns = [
path('django-admin/', admin.site.urls),
path('api/v2/', api_router.urls),
path('admin/', include(wagtailadmin_urls)),
path('documents/', include(wagtaildocs_urls)),

BIN
media/images/logo.max-165x165.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 KiB

BIN
media/original_images/logo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Loading…
Cancel
Save