Merge pull request #14 from loleg/news-prelaunch

Multilingual news
This commit is contained in:
khashashin 2017-09-05 09:48:00 +02:00 committed by GitHub
commit caa629ad3b
10 changed files with 117 additions and 21 deletions

View file

@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from datetime import datetime
from guess_language import guess_language
def parse(obj, raw, stream):
"""
@ -47,6 +48,9 @@ def parse(obj, raw, stream):
else:
obj.content = ''
# Detect language
obj.lang = guess_language(obj.content) or ''
# Collect tags
tags = []
if 'tags' in obj.raw:

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2017-09-04 20:33
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('feedler', '0002_feedpage'),
]
operations = [
migrations.AddField(
model_name='entry',
name='lang',
field=models.CharField(blank=True, default='', max_length=2),
),
]

View file

@ -61,5 +61,7 @@ def handle_save_settings(sender, instance, *args, **kwargs):
except Entry.DoesNotExist:
logger.info("Adding entry '%s'" % eid)
entry = Entry()
# Parse the Feedly object
entry = feedparser.parse(entry, raw_entry, stream)
# Persist resulting object
entry.save()

View file

@ -6,6 +6,8 @@ from wagtail.wagtailcore.models import Page, Orderable
from wagtail.wagtailadmin.edit_handlers import FieldPanel
from wagtail.wagtailcore.fields import RichTextField
from django.utils import translation
class Stream(models.Model):
title = models.CharField(max_length=255)
ident = models.CharField(max_length=255)
@ -13,6 +15,14 @@ class Stream(models.Model):
def __str__(self):
return self.title
LANGUAGE_CHOICES = (
('de', 'Deutsch'),
('fr', 'Français'),
('it', 'Italiano'),
('en', 'English'),
('', ' * * * '),
)
class Entry(models.Model):
"""Implementation of the Entry from the feedly API as generic Django model
"""
@ -25,7 +35,7 @@ class Entry(models.Model):
author = models.CharField(max_length=255, blank=True)
link = models.URLField()
visual = models.URLField(blank=True)
lang = models.CharField(max_length=2, blank=True, default='', choices=LANGUAGE_CHOICES)
content = models.TextField()
tags = models.TextField(blank=True)
@ -53,6 +63,12 @@ class FeedPage(Page):
entries = Entry.objects.filter(stream=self.stream)
else:
entries = Entry.objects.all()
# Filter out by chosen language
curlang = translation.get_language()
if curlang in ['de']:
entries = entries.exclude(lang='fr')
elif curlang in ['fr']:
entries = entries.exclude(lang='de')
# Order by most recent date first
entries = entries.order_by('-published')
return entries[:10]

View file

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.4 on 2017-09-04 20:33
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('home', '0019_auto_20170703_1244'),
]
operations = [
migrations.AlterField(
model_name='contactformfield',
name='field_type',
field=models.CharField(choices=[('singleline', 'Single line text'), ('multiline', 'Multi-line text'), ('email', 'Email'), ('number', 'Number'), ('url', 'URL'), ('checkbox', 'Checkbox'), ('checkboxes', 'Checkboxes'), ('dropdown', 'Drop down'), ('multiselect', 'Multiple select'), ('radio', 'Radio buttons'), ('date', 'Date'), ('datetime', 'Date/time')], max_length=16, verbose_name='field type'),
),
]

View file

@ -227,15 +227,26 @@ class HomePage(Page):
posts = EntryPage.objects.live().descendant_of(parent[0])
# Order by most recent date first
posts = posts.order_by('-date')
# Get news entries
return posts[:3]
@property
def newsentries(self):
# Get the last few news entries
entries = Entry.objects.all().order_by('-published')
return list(chain(entries[:3], posts[:3]))
# Filter out by current language
curlang = translation.get_language()
if curlang in ['de']:
entries = entries.exclude(lang='fr')
elif curlang in ['fr']:
entries = entries.exclude(lang='de')
return entries[:6]
def get_context(self, request):
# Update template context
context = super(HomePage, self).get_context(request)
context['featured'] = self.featured
context['blogentries'] = self.blogentries
context['newsentries'] = self.newsentries
return context
parent_page_types = ['wagtailcore.Page']

View file

@ -5,7 +5,6 @@
<div class="container">
<div class="row">
{% for entry in blogentries %}
{% 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">
@ -21,12 +20,16 @@
{{ entry.body|striptags|truncatewords_html:40 }}
{% endif %}
</p>
<a href="{% pageurl entry %}" class="btn btn-default btn-xs">Mehr erfahren</a>
<a href="{% pageurl entry %}" class="btn btn-default btn-xs"> ... </a>
</div>
<a href="{% pageurl entry %}" class="fill"></a>
</div>
</div>
{% else %}
{% empty %}
<!-- No blogs today -->
{% endfor %}
<h4 class="partner-news"><a href="/aktuelles/">Partner news</a></h4>
{% for entry in newsentries %}
<!-- News entry {{ entry.id }} -->
<div class="col-md-4 col-sm-6 col-xs-12 news-entry">
{% if entry.visual %}
@ -38,14 +41,12 @@
<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 }}
<em><small><span>{{ entry.author }}</span></small></em>
</p>
</div>
<a href="{{ entry.link }}" target="_blank" class="fill"></a>
</div>
</div>
{% endif %}
{% empty %}
<!-- No news today -->
{% endfor %}

View file

@ -132,6 +132,10 @@ PASSWORD_REQUIRED_TEMPLATE = 'password.html'
# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGES = (
('de', u'Deutsch'),
('fr', u'Français'),
)
LANGUAGE_CODE = 'de' # default language
TIME_ZONE = 'Europe/Zurich'

View file

@ -76,11 +76,28 @@
}
}
.news-entry .panel-body {
.news-entry {
height: 8em;
.panel {
background: none;
box-shadow: none;
border: none;
}
.panel-body {
height: 50%;
background-color: #f0f0f0;
border: 2px solid rgba(38, 67, 169, 0.8);
border-radius: 4px;
border-top: 3px solid $brand-primary;
// border: 2px solid rgba(38, 67, 169, 0.8);
*,a { color: black !important; }
}
}
.partner-news {
text-align: center;
margin-top: 2em;
margin-bottom: 1em;
}
}
// News detail article

View file

@ -1,15 +1,16 @@
# Updated: 5.7.2017
# Updated: 4.9.2017
# Core
wagtail==1.11
Django==1.11.3
wagtail==1.12.1
Django==1.11.4
# Database
psycopg2==2.7.1
psycopg2==2.7.3.1
dj-database-url==0.4.2
# Addons
puput==0.8
# Content
puput==0.9
guess-language-spirit==0.5.3
# Search
elasticsearch>=2.0.0,<3.0.0
@ -20,7 +21,7 @@ django-redis==4.8.0
# Frontend
django-libsass==0.7
libsass==0.13.2
Pillow==4.2.0
Pillow==4.2.1
# Development tools
stellar==0.4.3
@ -29,4 +30,4 @@ stellar==0.4.3
gunicorn==19.7.1
whitenoise==3.3.0
ConcurrentLogHandler==0.9.1
django-anymail==0.10
django-anymail==0.11.1