From e339985e02eac1e7db5f00659c24ac9d1dee2fe8 Mon Sep 17 00:00:00 2001 From: Merlin Buczek Date: Wed, 5 Jun 2019 17:27:50 +0200 Subject: [PATCH] Styling and Banner --- README.md | 9 +- .../migrations/0008_categorypage_preview.py | 18 ++++ .../migrations/0009_auto_20190605_1200.py | 23 +++++ .../migrations/0010_auto_20190605_1313.py | 32 +++++++ mpicms/base/models.py | 42 +++++++-- mpicms/base/translation.py | 11 ++- mpicms/events/models.py | 28 ++++-- .../migrations/0006_auto_20190605_1200.py | 17 ++++ mpicms/static/css/custom.css | 85 ++++++++++++++++++- mpicms/templates/base/category_page.html | 2 + mpicms/templates/base/home_page.html | 57 ++++++++++++- mpicms/templates/base/page_wide.html | 8 ++ .../events/components/event_list.html | 2 - mpicms/templates/events/event.html | 26 +++++- mpicms/templates/events/event_index.html | 2 +- mpicms/templates/menus/side.html | 7 -- mpicms/templates/news/news_page.html | 42 ++++----- 17 files changed, 351 insertions(+), 60 deletions(-) create mode 100644 mpicms/base/migrations/0008_categorypage_preview.py create mode 100644 mpicms/base/migrations/0009_auto_20190605_1200.py create mode 100644 mpicms/base/migrations/0010_auto_20190605_1313.py create mode 100644 mpicms/news/migrations/0006_auto_20190605_1200.py create mode 100644 mpicms/templates/base/page_wide.html diff --git a/README.md b/README.md index 53d2d87..ad68812 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,11 @@ For Django related variables see [Django's documentation](https://docs.djangopro ### LDAP - `LDAP_SERVER_URI` -## Run Migrations +## Run database migrations - `python manage.py migrate --no-input`. See [Django docs](https://docs.djangoproject.com/en/2.2/ref/django-admin/#django-admin-migrate). -- `python manage.py update_translation_fields`. See [wagtail-modeltranslation docs](https://wagtail-modeltranslation.readthedocs.io/en/latest/management%20commands.html#the-update-translation-fields-command). \ No newline at end of file + +## Update translation fields +- `python manage.py update_translation_fields`. See [wagtail-modeltranslation docs](https://wagtail-modeltranslation.readthedocs.io/en/latest/management%20commands.html#the-update-translation-fields-command). + +## Update search index +- `python manage.py update_index`. See [Wagtail docs](https://docs.wagtail.io/en/latest/reference/management_commands.html#update-index) \ No newline at end of file diff --git a/mpicms/base/migrations/0008_categorypage_preview.py b/mpicms/base/migrations/0008_categorypage_preview.py new file mode 100644 index 0000000..ad1f8f9 --- /dev/null +++ b/mpicms/base/migrations/0008_categorypage_preview.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.1 on 2019-06-05 10:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0007_remove_wikipage_date'), + ] + + operations = [ + migrations.AddField( + model_name='categorypage', + name='preview', + field=models.TextField(blank=True, verbose_name='preview'), + ), + ] diff --git a/mpicms/base/migrations/0009_auto_20190605_1200.py b/mpicms/base/migrations/0009_auto_20190605_1200.py new file mode 100644 index 0000000..3d872da --- /dev/null +++ b/mpicms/base/migrations/0009_auto_20190605_1200.py @@ -0,0 +1,23 @@ +# Generated by Django 2.2.1 on 2019-06-05 10:00 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0008_categorypage_preview'), + ] + + operations = [ + migrations.AddField( + model_name='categorypage', + name='preview_de', + field=models.TextField(blank=True, null=True, verbose_name='preview'), + ), + migrations.AddField( + model_name='categorypage', + name='preview_en', + field=models.TextField(blank=True, null=True, verbose_name='preview'), + ), + ] diff --git a/mpicms/base/migrations/0010_auto_20190605_1313.py b/mpicms/base/migrations/0010_auto_20190605_1313.py new file mode 100644 index 0000000..feada4e --- /dev/null +++ b/mpicms/base/migrations/0010_auto_20190605_1313.py @@ -0,0 +1,32 @@ +# Generated by Django 2.2.1 on 2019-06-05 11:13 + +from django.db import migrations, models +import django.db.models.deletion +import wagtail.core.fields + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0009_auto_20190605_1200'), + ] + + operations = [ + migrations.CreateModel( + name='Banner', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('title_en', models.CharField(max_length=200, null=True)), + ('title_de', models.CharField(max_length=200, null=True)), + ('text', wagtail.core.fields.RichTextField()), + ('text_en', wagtail.core.fields.RichTextField(null=True)), + ('text_de', wagtail.core.fields.RichTextField(null=True)), + ], + ), + migrations.AddField( + model_name='homepage', + name='banner', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='base.Banner'), + ), + ] diff --git a/mpicms/base/models.py b/mpicms/base/models.py index 415d5ed..69cca8e 100644 --- a/mpicms/base/models.py +++ b/mpicms/base/models.py @@ -16,10 +16,26 @@ from mpicms.news.mixins import NewsMixin from mpicms.events.models import Event +from wagtail.snippets.models import register_snippet + Page.show_in_menus_default = True +@register_snippet +class Banner(models.Model): + title = models.CharField(max_length=200, blank=True) + text = RichTextField(features=['bold', 'italic', 'link', 'document-link']) + + panels = [ + FieldPanel('title'), + FieldPanel('text'), + ] + + def __str__(self): + return self.title + + class Contacts(Orderable, models.Model): """ This defines the relationship between the `People` within the `personal` @@ -49,9 +65,23 @@ class Meta: # noqa class HomePage(NewsMixin, Page): + banner = models.ForeignKey( + 'Banner', + null=True, + blank=True, + on_delete=models.SET_NULL, + related_name='+' + ) + parent_page_types = ['wagtailcore.Page'] # Restrict parent to be root - content_panels = Page.content_panels + content_panels = Page.content_panels + [ + SnippetChooserPanel('banner'), + ] + + @property + def categories(self): + return self.get_children().type(CategoryPage).live() def get_context(self, request, *args, **kwargs): context = super().get_context(request, *args, **kwargs) @@ -59,13 +89,7 @@ def get_context(self, request, *args, **kwargs): # Events events = [] for event in Event.objects.live(): - events.append({ - 'title': event.title, - 'start': event.start.isoformat(), - 'end': event.end.isoformat(), - 'url': event.get_url(request=request), - 'color': '#006c66' - }) + events.append(event.get_dict(request)) context["events"] = json.dumps(events) @@ -77,6 +101,7 @@ class Meta: # noqa class CategoryPage(NewsMixin, Page): + preview = models.TextField(_("preview"), blank=True) body = RichTextField(_("content"), blank=True) side_content = RichTextField( _("sidebar content"), blank=True, @@ -86,6 +111,7 @@ class CategoryPage(NewsMixin, Page): content_panels = Page.content_panels + [ FieldPanel('body', classname="full"), + FieldPanel('preview'), FieldPanel('side_content'), InlinePanel( 'contacts', label="Contacts", diff --git a/mpicms/base/translation.py b/mpicms/base/translation.py index d7f80fc..d53405b 100644 --- a/mpicms/base/translation.py +++ b/mpicms/base/translation.py @@ -7,7 +7,15 @@ from modeltranslation.translator import TranslationOptions from modeltranslation.decorators import register -from .models import WikiPage, HomePage, CategoryPage +from .models import WikiPage, HomePage, CategoryPage, Banner + + +@register(Banner) +class BannerTR(TranslationOptions): + fields = ( + 'title', + 'text' + ) @register(HomePage) @@ -19,6 +27,7 @@ class HomePageTR(TranslationOptions): class CategoryPageTR(TranslationOptions): fields = ( 'body', + 'preview' ) diff --git a/mpicms/events/models.py b/mpicms/events/models.py index 0fb891c..5f7665e 100644 --- a/mpicms/events/models.py +++ b/mpicms/events/models.py @@ -57,6 +57,15 @@ def end(self): return datetime.combine(self.end_date, self.end_time) return self.end_date + def get_dict(self, request): + return { + 'title': self.title, + 'start': self.start.isoformat(), + 'end': self.end.isoformat() if self.end else None, + 'url': self.get_url(request=request), + 'color': '#006c66' + } + def clean(self): """Clean the model fields, if end_date is before start_date raise a ValidationError.""" super().clean() @@ -64,6 +73,17 @@ def clean(self): if self.end_date and self.end_date < self.start_date: raise ValidationError({'end_date': 'The end date cannot be before the start date.'}) + def get_context(self, request, *args, **kwargs): + context = super().get_context(request, *args, **kwargs) + + events = [] + for child in self.get_parent().get_children().type(Event).live().specific(): + events.append(child.get_dict(request)) + + context["events"] = json.dumps(events) + + return context + class Meta(object): # noqa ordering = ['start_date'] @@ -89,13 +109,7 @@ def get_context(self, request, *args, **kwargs): events = [] for child in self.get_children().type(Event).live().specific(): - events.append({ - 'title': child.title, - 'start': child.start.isoformat(), - 'end': child.end.isoformat(), - 'url': child.get_url(request=request), - 'color': '#006c66' - }) + events.append(child.get_dict(request)) context["events"] = json.dumps(events) diff --git a/mpicms/news/migrations/0006_auto_20190605_1200.py b/mpicms/news/migrations/0006_auto_20190605_1200.py new file mode 100644 index 0000000..d16c71f --- /dev/null +++ b/mpicms/news/migrations/0006_auto_20190605_1200.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2.1 on 2019-06-05 10:00 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('news', '0005_newspage_show_all'), + ] + + operations = [ + migrations.AlterModelOptions( + name='newsentry', + options={'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 595f569..abfe76f 100644 --- a/mpicms/static/css/custom.css +++ b/mpicms/static/css/custom.css @@ -13,6 +13,23 @@ select, input { border-radius: 0 !important; } +.message { + margin-bottom: 4rem !important; +} + +.message, .message * { + border-radius: 0; +} + +.message-header { + background-color: #006c66; +} + +.column { + display: flex; + flex-direction: column; +} + .content .fa-chevron-right { padding-left: 1em; } @@ -31,7 +48,7 @@ select, input { letter-spacing: 0.2em; } -.title.is-2 { +.title.is-2, .title.is-3 { font-family: "Merriweather Sans", sans-serif; } @@ -118,7 +135,7 @@ select, input { } .sidebar > div { - flex: 0 0 100%; + /* flex: 0 0 100%; */ } .sidebar time { @@ -142,6 +159,10 @@ select, input { color: #006c66 !important; } +.menu { + width: 100%; +} + .menu-item { border: 1px solid #dbdbdb; border-radius: 0 !important; @@ -175,13 +196,49 @@ select, input { font-size: 1.2rem; } +/* .menu-list a { + color: #006c66; + font-weight: 400; +} */ + +.card-list { + margin-left: 0 !important; + margin-right: 0 !important; + margin-bottom: 0 !important; + margin-top: 1rem; + line-height: 1.5; + display: flex; + flex-wrap: wrap; +} + +.card-list li { + width: 50%; + list-style: none; + margin: 0 !important; +} + + +.card-list a { + color: #006c66; + font-weight: 400; + /* border-top: none; + border-left: none; + border-right: none; + margin: 0; */ +} + +/* .card-list li:last-child .menu-item { + border: none; +} */ + .is-current { background: #eeeeee; font-weight: 400; } .card { - margin: 1rem 2rem 1rem 0; + /* margin: 1rem 2rem 1rem 0; */ + margin: 1rem; flex-grow: 1; width: inherit; flex-shrink: 0; @@ -191,6 +248,10 @@ select, input { flex-basis: 18rem; } +.is-preview-wide { + flex-basis: 30rem; +} + .category-label { float: right; font-size: 90%; @@ -251,6 +312,7 @@ select, input { .section-button { display: flex; + margin-top: auto; align-items: center; justify-content: center; padding: 1rem 0; @@ -273,11 +335,28 @@ select, input { border: 1px solid grey; } +.tag .fa { + padding-right: 0.8em; +} + /* Full Calendar */ .fc-button { border-radius: 0 !important; } +.fc-scroller { + max-height: 30rem; + height: fit-content !important; +} + +.fc-toolbar.fc-header-toolbar { + margin-bottom: 0 !important; +} + +.fc { + padding: 1rem; +} + /* Pagination */ .is-current { background-color: transparent !important; diff --git a/mpicms/templates/base/category_page.html b/mpicms/templates/base/category_page.html index 6afd8ed..bb20ff9 100644 --- a/mpicms/templates/base/category_page.html +++ b/mpicms/templates/base/category_page.html @@ -12,6 +12,8 @@

{{ page.title }}

{% include 'news/components/news_preview.html' with news=page.news %} + +

Content

{% for child in page.get_children.live %}
diff --git a/mpicms/templates/base/home_page.html b/mpicms/templates/base/home_page.html index ad34f5e..8e63637 100644 --- a/mpicms/templates/base/home_page.html +++ b/mpicms/templates/base/home_page.html @@ -1,11 +1,60 @@ -{% extends 'base/page.html' %} +{% extends 'base/page_wide.html' %} {% load i18n %} {% load wagtailcore_tags %} {% block page_content %} -
- {% include 'news/components/news_preview.html' with news=page.news %} -
+ + {% if page.banner %} +
+ {% if page.banner.title %} +
+

{{ page.banner.title }}

+
+ {% endif %} +
+ {{ page.banner.text|richtext }} +
+
+ {% endif %} + +
+ + +

Content

+
+ {% for item in page.categories %} +
+
+ {{ item.title }} +
+ {{ item.specific.preview|richtext }} + +
+
+
+ {% endfor %} +
+ + {% endblock %} \ No newline at end of file diff --git a/mpicms/templates/base/page_wide.html b/mpicms/templates/base/page_wide.html new file mode 100644 index 0000000..15bf56b --- /dev/null +++ b/mpicms/templates/base/page_wide.html @@ -0,0 +1,8 @@ +{% extends 'base.html' %} + +{% block content %} +
+ {% block page_content %} + {% endblock %} +
+{% endblock %} \ No newline at end of file diff --git a/mpicms/templates/events/components/event_list.html b/mpicms/templates/events/components/event_list.html index d9f48bf..2224500 100644 --- a/mpicms/templates/events/components/event_list.html +++ b/mpicms/templates/events/components/event_list.html @@ -1,5 +1,3 @@ -

Upcoming events

-