From bbe16b2d135a600fbce945d28f66b099ac228634 Mon Sep 17 00:00:00 2001 From: Christian Berg Date: Fri, 14 Oct 2016 21:25:23 +0200 Subject: [PATCH] added localized deschription fields osed for the meta description tag on the page for SEO. --- src/content/admin.py | 6 +- .../migrations/0003_auto_20161012_2205.py | 60 ++++++++++ .../migrations/0004_auto_20161012_2206.py | 24 ++++ .../migrations/0005_auto_20161012_2236.py | 24 ++++ src/content/models.py | 113 ++++++++++++------ src/content/sitemaps.py | 7 +- 6 files changed, 194 insertions(+), 40 deletions(-) create mode 100644 src/content/migrations/0003_auto_20161012_2205.py create mode 100644 src/content/migrations/0004_auto_20161012_2206.py create mode 100644 src/content/migrations/0005_auto_20161012_2236.py diff --git a/src/content/admin.py b/src/content/admin.py index 39c1d14..4b90a76 100644 --- a/src/content/admin.py +++ b/src/content/admin.py @@ -37,11 +37,13 @@ class PageAdmin(admin.ModelAdmin): search_fields = ('menu_name_de', 'title_de',) fieldsets = ( ('Deutsch', { - 'fields': ('menu_name_de', 'title_de', 'pdf_de', 'content_de',), + 'fields': ('menu_name_de', 'title_de', 'description_de', 'pdf_de', + 'content_de',), 'classes': ('grp-collapse grp-open',), }), ('English', { - 'fields': ('menu_name_en', 'title_en', 'pdf_en', 'content_en'), + 'fields': ('menu_name_en', 'title_en', 'description_en', 'pdf_en', + 'content_en'), 'classes': ('grp-collapse grp-closed',), }), ('Meta Data', { diff --git a/src/content/migrations/0003_auto_20161012_2205.py b/src/content/migrations/0003_auto_20161012_2205.py new file mode 100644 index 0000000..d1d027f --- /dev/null +++ b/src/content/migrations/0003_auto_20161012_2205.py @@ -0,0 +1,60 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('content', '0002_auto_20150823_2232'), + ] + + operations = [ + migrations.AddField( + model_name='page', + name='date_created', + field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='first created at', editable=False, db_index=True), + ), + migrations.AddField( + model_name='page', + name='date_modified', + field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='latest updated at', editable=False), + ), + migrations.AlterField( + model_name='article', + name='date_created', + field=models.DateTimeField(auto_now_add=True, verbose_name='Erstellt'), + ), + migrations.AlterField( + model_name='page', + name='content_type', + field=models.IntegerField(verbose_name='Inhaltstyp', choices=[(0, 'Django View'), (1, 'HTML'), (2, 'PDF')]), + ), + migrations.AlterField( + model_name='page', + name='path', + field=models.CharField(verbose_name='Pfad', unique=True, max_length=255, editable=False, db_index=True), + ), + migrations.AlterField( + model_name='page', + name='slug', + field=models.SlugField(help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=100, verbose_name='Slug'), + ), + migrations.AlterField( + model_name='page', + name='template', + field=models.CharField(default=b'content/page.html', max_length=255, verbose_name='Vorlage'), + ), + migrations.AlterField( + model_name='page', + name='title_de', + field=models.CharField(help_text="The page title as you'd like it to be seen by the public", max_length=255, verbose_name=b'Titel'), + ), + migrations.AlterField( + model_name='page', + name='title_en', + field=models.CharField(help_text="The page title as you'd like it to be seen by the public", max_length=255, verbose_name=b'Title', blank=True), + ), + ] diff --git a/src/content/migrations/0004_auto_20161012_2206.py b/src/content/migrations/0004_auto_20161012_2206.py new file mode 100644 index 0000000..3849b81 --- /dev/null +++ b/src/content/migrations/0004_auto_20161012_2206.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('content', '0003_auto_20161012_2205'), + ] + + operations = [ + migrations.AlterField( + model_name='page', + name='date_created', + field=models.DateTimeField(auto_now_add=True, verbose_name='first created at', db_index=True), + ), + migrations.AlterField( + model_name='page', + name='date_modified', + field=models.DateTimeField(auto_now=True, verbose_name='latest updated at'), + ), + ] diff --git a/src/content/migrations/0005_auto_20161012_2236.py b/src/content/migrations/0005_auto_20161012_2236.py new file mode 100644 index 0000000..f52a2c2 --- /dev/null +++ b/src/content/migrations/0005_auto_20161012_2236.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('content', '0004_auto_20161012_2206'), + ] + + operations = [ + migrations.AddField( + model_name='page', + name='description_de', + field=models.TextField(verbose_name='search description', blank=True), + ), + migrations.AddField( + model_name='page', + name='description_en', + field=models.TextField(verbose_name='search description', blank=True), + ), + ] diff --git a/src/content/models.py b/src/content/models.py index b80590d..c80fc6b 100644 --- a/src/content/models.py +++ b/src/content/models.py @@ -1,20 +1,20 @@ # -*- coding: utf-8 -*- from os import path +from ckeditor.fields import RichTextField from django.conf import settings -from django.utils.timezone import now -from django.core.urlresolvers import reverse from django.core.cache import cache +from django.core.exceptions import ValidationError +from django.core.urlresolvers import reverse from django.db import models from django.template.defaultfilters import slugify +from django.utils import timezone from django.utils.safestring import mark_safe from django.utils.translation import get_language, ugettext as _ -from django.core.exceptions import ValidationError -from ckeditor.fields import RichTextField + from utils import STATUS_CHOICES, STATUS_WAITING, STATUS_PUBLISHED, \ cleaner - CONTENT_CHOICES = ( (0, u'Django View'), (1, u'HTML'), @@ -39,12 +39,12 @@ def get_upload_path(instance, filename): class ArticleManager(models.Manager): - def get_queryset(self): - return super(ArticleManager, self).get_queryset().select_related('author', 'category') + return super(ArticleManager, self).get_queryset().select_related( + 'author', 'category') def published(self): - return self.filter(status=STATUS_PUBLISHED, date_created__lte=now()) + return self.filter(status=STATUS_PUBLISHED, date_created__lte=timezone.now()) class Article(models.Model): @@ -60,7 +60,7 @@ class Article(models.Model): verbose_name=_('Author')) status = models.SmallIntegerField(_('Status'), choices=STATUS_CHOICES, default=STATUS_PUBLISHED) - date_created = models.DateTimeField(_('Created'), blank=True) + date_created = models.DateTimeField(_('Created'), auto_now_add=True) date_modified = models.DateTimeField(_('Modified'), auto_now=True) objects = ArticleManager() @@ -71,7 +71,7 @@ class Article(models.Model): def clean(self): if not self.date_created: - self.date_created = now() + self.date_created = timezone.now() if not self.slug: self.slug = slugify(self.headline_de)[:50] self.content_de = cleaner.clean_html(self.content_de) @@ -121,42 +121,83 @@ class Page(models.Model): angeboten. """ menu_name_de = models.CharField( - 'MenĂ¼ Name', max_length=255, + verbose_name='MenĂ¼ Name', help_text=_('The short name for the menu-entry of this page') ) menu_name_en = models.CharField( - 'Menu Name', max_length=255, blank=True, + verbose_name='Menu Name', help_text=_('The short name for the menu-entry of this page') ) - title_de = models.CharField('Titel', max_length=255, - help_text=_( - 'This title appears in the HTML header')) - title_en = models.CharField('Title', max_length=255, blank=True, - help_text=_( - 'This title appears in the HTML header')) - slug = models.SlugField(_('slug')) - path = models.CharField(_('Path'), max_length=100, db_index=True, - editable=False, unique=True) - - parent = models.ForeignKey('self', blank=True, null=True, - related_name='subpages', - on_delete=models.SET_NULL) - position = models.PositiveSmallIntegerField(_('Position'), - blank=True, null=True) - status = models.SmallIntegerField(_('status'), choices=STATUS_CHOICES, - default=STATUS_WAITING) - content_type = models.IntegerField(choices=CONTENT_CHOICES) - + title_de = models.CharField( + max_length=255, + verbose_name='Titel', + help_text=_("The page title as you'd like it to be seen by the public")) + title_en = models.CharField( + max_length=255, + blank=True, + verbose_name='Title', + help_text=_("The page title as you'd like it to be seen by the public")) + slug = models.SlugField( + verbose_name=_('slug'), + max_length=100, + help_text=_("The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/") + ) + path = models.CharField( + max_length=255, + db_index=True, + editable=False, + unique=True, + verbose_name=_('Path'), + ) + parent = models.ForeignKey( + 'self', + blank=True, + null=True, + related_name='subpages', + on_delete=models.SET_NULL + ) + position = models.PositiveSmallIntegerField( + blank=True, + null=True, + verbose_name=_('Position') + ) + status = models.SmallIntegerField( + choices=STATUS_CHOICES, + default=STATUS_WAITING, + verbose_name=_('status') + ) + description_de = models.TextField(verbose_name=_('search description'), blank=True) + description_en = models.TextField(verbose_name=_('search description'), blank=True) + content_type = models.IntegerField( + choices=CONTENT_CHOICES, + verbose_name=_('content type')) content_de = RichTextField('Inhalt', blank=True) content_en = RichTextField('Content', blank=True) - enable_comments = models.BooleanField(_('enable comments'), default=True) - template = models.CharField(_('Template'), max_length=100, - default="content/page.html") + enable_comments = models.BooleanField( + default=True, + verbose_name=_('enable comments') + ) + template = models.CharField( + max_length=255, + default="content/page.html", + verbose_name=_('Template'), + ) pdf_de = models.FileField(upload_to='pdf/de/', blank=True, null=True) pdf_en = models.FileField(upload_to='pdf/en/', blank=True, null=True) + date_created = models.DateTimeField( + auto_now_add=True, + db_index=True, + editable=False, + verbose_name=_('first created at'), + ) + date_modified = models.DateTimeField( + auto_now=True, + editable=False, + verbose_name=_('latest updated at'), + ) def __unicode__(self): return u'%s' % self.title @@ -170,6 +211,10 @@ class Page(models.Model): def css_class(self): return CONTENT_CHOICES[self.content_type][1].lower().replace(' ', '_') + @property + def description(self): + return getattr(self, "description_%s" % get_language()) or self.description_de + @property def menu_name(self): return getattr(self, diff --git a/src/content/sitemaps.py b/src/content/sitemaps.py index 9b82a47..c884ddf 100644 --- a/src/content/sitemaps.py +++ b/src/content/sitemaps.py @@ -4,7 +4,6 @@ from .models import Article, Page class ArticleSitemap(Sitemap): changefreq = "never" priority = 0.6 - protocol = 'https' def items(self): return Article.objects.published() @@ -16,10 +15,10 @@ class ArticleSitemap(Sitemap): class PageSitemap(Sitemap): changefreq = "monthly" priority = 0.4 - protocol = 'https' def items(self): return Page.objects.all() #filter(status__gt=0) - def location(self, page): - return page.get_absolute_url() + def lastmod(self, page): + return page.date_modified +