News on frontpage

This commit is contained in:
Oleg Lavrovsky 2017-07-26 12:42:06 +02:00
parent 2fef42bfc2
commit ad930a18b6
4 changed files with 39 additions and 9 deletions

View file

@ -16,6 +16,8 @@ from wagtail.wagtailimages.edit_handlers import ImageChooserPanel
from wagtail.wagtailsearch import index
from puput.models import EntryPage, BlogPage
from feedler.models import Entry
from itertools import chain
from ..util import TranslatedField
@ -193,11 +195,6 @@ class HomePage(Page):
'infos_fr',
)
# news_home_de = models.ForeignKey(
# 'puput.EntryPage',
# null=True, blank=True, on_delete=models.SET_NULL,
# )
content_panels = Page.content_panels + [
MultiFieldPanel([
FieldPanel('intro_de', classname="full"),
@ -227,10 +224,12 @@ class HomePage(Page):
if not curlang in ['de', 'fr']: curlang = 'de' # Default language
parent = BlogPage.objects.filter(slug='news-%s' % curlang)
if not parent: return []
entries = EntryPage.objects.live().descendant_of(parent[0])
posts = EntryPage.objects.live().descendant_of(parent[0])
# Order by most recent date first
entries = entries.order_by('-date')
return entries[:6]
posts = posts.order_by('-date')
# Get news entries
entries = Entry.objects.all().order_by('-published')
return list(chain(entries[:3], posts[:3]))
def get_context(self, request):
# Update template context

View file

@ -1,10 +1,13 @@
{% load wagtailcore_tags wagtailimages_tags puput_tags %}
<!-- Front page news -->
<section id="news">
<div class="container">
<div class="row">
{% for entry in blogentries %}
<div class="col-md-4 col-sm-6 col-xs-12">
{% if entry.body %}
<!-- Blog post {{ entry.id }} -->
<div class="col-md-4 col-sm-6 col-xs-12 blog-entry">
<div class="panel panel-default">
{% if entry.header_image %}
{% image entry.header_image fill-360x270 %}
@ -23,6 +26,26 @@
<a href="{% pageurl entry %}" class="fill"></a>
</div>
</div>
{% else %}
<!-- News entry {{ entry.id }} -->
<div class="col-md-4 col-sm-6 col-xs-12 news-entry">
{% if entry.visual %}
<div class="panel panel-default">
<img src="{{ entry.visual }}">
{% else %}
<div class="panel panel-fulltext">
{% endif %}
<div class="panel-body">
<h3><span>{{ entry.title|striptags|truncatewords_html:10 }}</span></h3>
<p>
<em><small><span>{{ entry.author }}</span></small></em><br><br>
{{ entry.content|striptags|truncatewords_html:25 }}
</p>
</div>
<a href="{{ entry.link }}" target="_blank" class="fill"></a>
</div>
</div>
{% endif %}
{% empty %}
<!-- No news today -->
{% endfor %}

View file

@ -75,6 +75,12 @@
transform: rotateY(0);
}
}
.news-entry .panel-body {
background-color: #f0f0f0;
border: 2px solid rgba(38, 67, 169, 0.8);
*,a { color: black !important; }
}
}
// News detail article

View file

@ -10,5 +10,7 @@
<h1>Internal server error</h1>
<h2>Sorry, there seems to be an error. Please try again soon.</h2>
<p>In case of persistent issues, write to <b>info@datalets.ch</b></p>
</body>
</html>