SWitch to parler for multilingual support.

Fix templates
This commit is contained in:
Iacopo Spalletti 2014-01-09 08:51:03 +01:00
parent 086dde879d
commit 958ed651f2
16 changed files with 76 additions and 47 deletions

View file

@ -2,7 +2,7 @@
from admin_enhancer.admin import EnhancedModelAdminMixin from admin_enhancer.admin import EnhancedModelAdminMixin
from cms.admin.placeholderadmin import PlaceholderAdmin, FrontendEditableAdmin from cms.admin.placeholderadmin import PlaceholderAdmin, FrontendEditableAdmin
from django.contrib import admin from django.contrib import admin
from hvad.admin import TranslatableAdmin from parler.admin import TranslatableAdmin
from .models import Post, BlogCategory from .models import Post, BlogCategory
@ -32,6 +32,9 @@ class PostAdmin(EnhancedModelAdminMixin, FrontendEditableAdmin,
}), }),
] ]
def get_prepopulated_fields(self, request, obj=None):
return {"slug": ("title",)}
def save_model(self, request, obj, form, change): def save_model(self, request, obj, form, change):
if not obj.author_id: if not obj.author_id:
obj.author = request.user obj.author = request.user

View file

@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from cms.toolbar_base import CMSToolbar
from cms.toolbar_pool import toolbar_pool
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from cms.toolbar_base import CMSToolbar
from cms.toolbar_pool import toolbar_pool
@toolbar_pool.register @toolbar_pool.register

View file

@ -1,9 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.db import models from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
from south.modelsinspector import add_introspection_rules from south.modelsinspector import add_introspection_rules
add_introspection_rules([], ["^djangocms_blog\.fields\.UsersWithPermsManyToManyField"]) add_introspection_rules([], ["^djangocms_blog\.fields\.UsersWithPermsManyToManyField"])

View file

@ -1,7 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django import forms from django import forms
from django.conf import settings from django.conf import settings
import django_select2 import django_select2

View file

@ -4,7 +4,7 @@ import datetime
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from hvad.manager import TranslationManager from parler.managers import TranslationManager
from .settings import BLOG_TAGCLOUD_MIN, BLOG_TAGCLOUD_MAX from .settings import BLOG_TAGCLOUD_MIN, BLOG_TAGCLOUD_MAX
@ -62,7 +62,7 @@ class TaggedFilterItem(object):
if len(count) > 0: if len(count) > 0:
weight_fun = get_weight_fun(BLOG_TAGCLOUD_MIN, weight_fun = get_weight_fun(BLOG_TAGCLOUD_MIN,
BLOG_TAGCLOUD_MAX, BLOG_TAGCLOUD_MAX,
min(count), max(count)) min(count), BLOG_TAGCLOUD_MAX)
tagquery = tagquery.order_by('name') tagquery = tagquery.order_by('name')
for tag in tagquery: for tag in tagquery:
tag.weight = weight_fun(tag.count) tag.weight = weight_fun(tag.count)

View file

@ -11,9 +11,9 @@ class Migration(SchemaMigration):
# Adding model 'BlogCategoryTranslation' # Adding model 'BlogCategoryTranslation'
db.create_table(u'djangocms_blog_blogcategory_translation', ( db.create_table(u'djangocms_blog_blogcategory_translation', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('language_code', self.gf('django.db.models.fields.CharField')(max_length=15, db_index=True)),
('name', self.gf('django.db.models.fields.CharField')(max_length=255)), ('name', self.gf('django.db.models.fields.CharField')(max_length=255)),
('slug', self.gf('django.db.models.fields.SlugField')(max_length=50, blank=True)), ('slug', self.gf('django.db.models.fields.SlugField')(max_length=50, blank=True)),
('language_code', self.gf('django.db.models.fields.CharField')(max_length=15, db_index=True)),
('master', self.gf('django.db.models.fields.related.ForeignKey')(related_name='translations', null=True, to=orm['djangocms_blog.BlogCategory'])), ('master', self.gf('django.db.models.fields.related.ForeignKey')(related_name='translations', null=True, to=orm['djangocms_blog.BlogCategory'])),
)) ))
db.send_create_signal(u'djangocms_blog', ['BlogCategoryTranslation']) db.send_create_signal(u'djangocms_blog', ['BlogCategoryTranslation'])
@ -33,10 +33,10 @@ class Migration(SchemaMigration):
# Adding model 'PostTranslation' # Adding model 'PostTranslation'
db.create_table(u'djangocms_blog_post_translation', ( db.create_table(u'djangocms_blog_post_translation', (
(u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('language_code', self.gf('django.db.models.fields.CharField')(max_length=15, db_index=True)),
('title', self.gf('django.db.models.fields.CharField')(max_length=255)), ('title', self.gf('django.db.models.fields.CharField')(max_length=255)),
('slug', self.gf('django.db.models.fields.SlugField')(max_length=50, blank=True)), ('slug', self.gf('django.db.models.fields.SlugField')(max_length=50, blank=True)),
('abstract', self.gf('djangocms_text_ckeditor.fields.HTMLField')()), ('abstract', self.gf('djangocms_text_ckeditor.fields.HTMLField')()),
('language_code', self.gf('django.db.models.fields.CharField')(max_length=15, db_index=True)),
('master', self.gf('django.db.models.fields.related.ForeignKey')(related_name='translations', null=True, to=orm['djangocms_blog.Post'])), ('master', self.gf('django.db.models.fields.related.ForeignKey')(related_name='translations', null=True, to=orm['djangocms_blog.Post'])),
)) ))
db.send_create_signal(u'djangocms_blog', ['PostTranslation']) db.send_create_signal(u'djangocms_blog', ['PostTranslation'])
@ -85,6 +85,15 @@ class Migration(SchemaMigration):
)) ))
db.create_unique(m2m_table_name, ['latestpostsplugin_id', 'tag_id']) db.create_unique(m2m_table_name, ['latestpostsplugin_id', 'tag_id'])
# Adding M2M table for field categories on 'LatestPostsPlugin'
m2m_table_name = db.shorten_name(u'djangocms_blog_latestpostsplugin_categories')
db.create_table(m2m_table_name, (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('latestpostsplugin', models.ForeignKey(orm[u'djangocms_blog.latestpostsplugin'], null=False)),
('blogcategory', models.ForeignKey(orm[u'djangocms_blog.blogcategory'], null=False))
))
db.create_unique(m2m_table_name, ['latestpostsplugin_id', 'blogcategory_id'])
# Adding model 'AuthorEntriesPlugin' # Adding model 'AuthorEntriesPlugin'
db.create_table(u'cmsplugin_authorentriesplugin', ( db.create_table(u'cmsplugin_authorentriesplugin', (
(u'cmsplugin_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['cms.CMSPlugin'], unique=True, primary_key=True)), (u'cmsplugin_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['cms.CMSPlugin'], unique=True, primary_key=True)),
@ -130,6 +139,9 @@ class Migration(SchemaMigration):
# Removing M2M table for field tags on 'LatestPostsPlugin' # Removing M2M table for field tags on 'LatestPostsPlugin'
db.delete_table(db.shorten_name(u'djangocms_blog_latestpostsplugin_tags')) db.delete_table(db.shorten_name(u'djangocms_blog_latestpostsplugin_tags'))
# Removing M2M table for field categories on 'LatestPostsPlugin'
db.delete_table(db.shorten_name(u'djangocms_blog_latestpostsplugin_categories'))
# Deleting model 'AuthorEntriesPlugin' # Deleting model 'AuthorEntriesPlugin'
db.delete_table(u'cmsplugin_authorentriesplugin') db.delete_table(u'cmsplugin_authorentriesplugin')
@ -227,6 +239,7 @@ class Migration(SchemaMigration):
}, },
u'djangocms_blog.latestpostsplugin': { u'djangocms_blog.latestpostsplugin': {
'Meta': {'object_name': 'LatestPostsPlugin', 'db_table': "u'cmsplugin_latestpostsplugin'", '_ormbases': ['cms.CMSPlugin']}, 'Meta': {'object_name': 'LatestPostsPlugin', 'db_table': "u'cmsplugin_latestpostsplugin'", '_ormbases': ['cms.CMSPlugin']},
'categories': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['djangocms_blog.BlogCategory']", 'symmetrical': 'False', 'blank': 'True'}),
u'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}), u'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
'latest_posts': ('django.db.models.fields.IntegerField', [], {'default': '5'}), 'latest_posts': ('django.db.models.fields.IntegerField', [], {'default': '5'}),
'tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['taggit.Tag']", 'symmetrical': 'False', 'blank': 'True'}) 'tags': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['taggit.Tag']", 'symmetrical': 'False', 'blank': 'True'})
@ -276,14 +289,14 @@ class Migration(SchemaMigration):
'Meta': {'ordering': "('name',)", 'unique_together': "(('parent', 'name'),)", 'object_name': 'Folder'}, 'Meta': {'ordering': "('name',)", 'unique_together': "(('parent', 'name'),)", 'object_name': 'Folder'},
'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), 'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), u'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), u'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'modified_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), 'modified_at': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'filer_owned_folders'", 'null': 'True', 'to': u"orm['auth.User']"}), 'owner': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'filer_owned_folders'", 'null': 'True', 'to': u"orm['auth.User']"}),
'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['filer.Folder']"}), 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['filer.Folder']"}),
'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), u'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), u'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}) 'uploaded_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'})
}, },
'filer.image': { 'filer.image': {
@ -297,7 +310,6 @@ class Migration(SchemaMigration):
u'file_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['filer.File']", 'unique': 'True', 'primary_key': 'True'}), u'file_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['filer.File']", 'unique': 'True', 'primary_key': 'True'}),
'must_always_publish_author_credit': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'must_always_publish_author_credit': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'must_always_publish_copyright': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'must_always_publish_copyright': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'related_url': ('django.db.models.fields.CharField', [], {'max_length': '250', 'null': 'True', 'blank': 'True'}),
'subject_location': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '64', 'null': 'True', 'blank': 'True'}) 'subject_location': ('django.db.models.fields.CharField', [], {'default': 'None', 'max_length': '64', 'null': 'True', 'blank': 'True'})
}, },
u'taggit.tag': { u'taggit.tag': {

View file

@ -10,7 +10,7 @@ from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from djangocms_text_ckeditor.fields import HTMLField from djangocms_text_ckeditor.fields import HTMLField
from filer.fields.image import FilerImageField from filer.fields.image import FilerImageField
from hvad.models import TranslatableModel, TranslatedFields from parler.models import TranslatableModel, TranslatedFields
from taggit_autosuggest.managers import TaggableManager from taggit_autosuggest.managers import TaggableManager
from .managers import GenericDateTaggedManager from .managers import GenericDateTaggedManager
@ -40,15 +40,15 @@ class BlogCategory(TranslatableModel):
return self.blog_posts.count() return self.blog_posts.count()
def __unicode__(self): def __unicode__(self):
return self.lazy_translation_getter('name') return self.safe_translation_getter('name')
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
super(BlogCategory, self).save(*args, **kwargs) super(BlogCategory, self).save(*args, **kwargs)
for item in self._meta.translations_model.objects.filter(master__pk=self.pk): for lang in self.get_available_languages():
title = getattr(item, "name", False) self.set_current_language(lang)
if title and not item.slug: if not self.slug and self.name:
item.slug = slugify(title) self.slug = slugify(self.name)
item.save() self.save_translations()
class Post(TranslatableModel): class Post(TranslatableModel):
@ -90,15 +90,15 @@ class Post(TranslatableModel):
verbose_name_plural = _('blog post') verbose_name_plural = _('blog post')
def __unicode__(self): def __unicode__(self):
return self.lazy_translation_getter('title') return self.safe_translation_getter('title')
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
super(Post, self).save(*args, **kwargs) super(Post, self).save(*args, **kwargs)
for item in self._meta.translations_model.objects.filter(master__pk=self.pk): for lang in self.get_available_languages():
title = getattr(item, "title", False) self.set_current_language(lang)
if title and not item.slug: if not self.slug and self.title:
item.slug = slugify(title) self.slug = slugify(self.title)
item.save() self.save_translations()
def get_absolute_url(self): def get_absolute_url(self):
kwargs = {'year': self.date_published.year, kwargs = {'year': self.date_published.year,
@ -120,7 +120,6 @@ class Post(TranslatableModel):
else: else:
return "http://%s%s" % (s.domain, self.get_absolute_url()) return "http://%s%s" % (s.domain, self.get_absolute_url())
def full_image_options(self): def full_image_options(self):
if self.main_image_fulll_id: if self.main_image_fulll_id:
return self.main_image_full.as_dict return self.main_image_full.as_dict

View file

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.utils.translation import ugettext_lazy as _
BLOG_IMAGE_THUMBNAIL_SIZE = { BLOG_IMAGE_THUMBNAIL_SIZE = {
'size': '120x120', 'size': '120x120',

View file

@ -1,4 +1,4 @@
{% extends "admin/hvad/change_form.html" %} {% extends "admin/parler/change_form.html" %}
{% load static %} {% load static %}
{% block extrahead %} {% block extrahead %}

View file

@ -1,6 +1,6 @@
{% extends "interne.html" %} {% extends "base.html" %}
{% block contenuto %} {% block application %}
<div class="app app-blog"> <div class="app app-blog">
{% block content_blog %}{% endblock %} {% block content_blog %}{% endblock %}
</div> </div>

View file

@ -1,11 +1,11 @@
{% load i18n thumbnail cms_tags nephila_django %} {% load i18n thumbnail cms_tags %}
{% load url from future %} {% load url from future %}
<article id="post-{{ post.slug }}" class="post-item"> <article id="post-{{ post.slug }}" class="post-item">
<header> <header>
<h3><a href="{{ post.get_absolute_url }}">{% show_editable_model post "title" %}</a></h3> <h3><a href="{{ post.get_absolute_url }}">{% show_editable_model post "title" %}</a></h3>
{% block blog_meta %} {% block blog_meta %}
{% html5time post.date_published "d F Y" "blog-date" %} {{ post.date_published|date:"d F Y" }}
<div class="blog-author">{% trans "by" %} <a href="{% url 'djangocms_blog:author-posts' post.author.username %}">{{ post.author }}</a></div> <div class="blog-author">{% trans "by" %} <a href="{% url 'djangocms_blog:author-posts' post.author.username %}">{{ post.author }}</a></div>
{% if post.tags.exists %} {% if post.tags.exists %}
<nav class="blog-tags"> <nav class="blog-tags">

View file

@ -0,0 +1,13 @@
{% load i18n %}
{% load url from future %}
<div class="plugin plugin-blog">
<h3>{% trans "Categories" %}</h3>
<ul class="blog-categories">
{% for category in categories %}
<li><a href="{% url 'djangocms_blog:category-posts' category=category.slug %}" class="blog-categories-{{ category.count }}">{{ category.name }} <span>({{ category.count }} {% trans "articles" %})</span></a></li>
{% empty %}
<li class="blog-empty"><p>{% trans "No entry found." %}</p></li>
{% endfor %}
</ul>
</div>

View file

@ -1,7 +1,10 @@
{% load i18n %}
<div class="plugin plugin-blog"> <div class="plugin plugin-blog">
<div class="blog-latest-entries"> <div class="blog-latest-entries">
{% for post in post_list %} {% for post in instance.get_posts %}
{% include "djangocms_blog/includes/blog_item.html" with post=instance.get_posts %} {% include "djangocms_blog/includes/blog_item.html" with post=post %}
{% empty %} {% empty %}
<p class="blog-empty">{% trans "No post found." %}</p>
{% endfor %}
</div> </div>
</div> </div>

View file

@ -1,14 +1,14 @@
{% extends "djangocms_blog/base.html" %} {% extends "djangocms_blog/base.html" %}
{% load i18n thumbnail cms_tags nephila_django %} {% load i18n thumbnail cms_tags %}
{% load url from future %} {% load url from future %}
{% block content_blog %} {% block content_blog %}
<article id="post-{{ post.slug }}" class="post-item post-detail"> <article id="post-{{ post.slug }}" class="post-item post-detail">
<header> <header>
<h2><a href="{{ post.get_absolute_url }}">{% show_editable_model post "title" %}</a></h2> <h2>{% show_editable_model post "title" %}</h2>
{% block blog_meta %} {% block blog_meta %}
<div class="blog-meta"> <div class="blog-meta">
{% html5time post.date_published "d F Y" "blog-date" %} {{ post.date_published|date:"d F Y" }}
<div class="blog-author">{% trans "by" %} <a href="{% url 'djangocms_blog:author-posts' post.author.username %}">{{ post.author }}</a></div> <div class="blog-author">{% trans "by" %} <a href="{% url 'djangocms_blog:author-posts' post.author.username %}">{{ post.author }}</a></div>
{% if post.tags.exists %} {% if post.tags.exists %}
<nav class="blog-tags"> <nav class="blog-tags">

View file

@ -1,20 +1,19 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import datetime import datetime
from cms.utils import get_language_from_request
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.urlresolvers import resolve from django.core.urlresolvers import resolve
from django.db.models import Count from django.db.models import Count
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.generic import ListView, DetailView from django.views.generic import ListView, DetailView
from hvad.admin import TranslatableModelAdminMixin
from .models import Post, BlogCategory from .models import Post, BlogCategory
class BaseBlogView(TranslatableModelAdminMixin): class BaseBlogView(object):
def get_queryset(self): def get_queryset(self):
language = self._language(self.request) language = get_language_from_request(self.request)
manager = self.model._default_manager.language(language) manager = self.model._default_manager.language(language)
if not self.request.user.is_staff: if not self.request.user.is_staff:
manager = manager.filter(publish=True) manager = manager.filter(publish=True)
@ -35,6 +34,7 @@ class PostDetailView(BaseBlogView, DetailView):
model = Post model = Post
context_object_name = 'post' context_object_name = 'post'
template_name = "djangocms_blog/post_detail.html" template_name = "djangocms_blog/post_detail.html"
slug_field = 'translations__slug'
class PostArchiveView(BaseBlogView, ListView): class PostArchiveView(BaseBlogView, ListView):

View file

@ -1,6 +1,9 @@
django-hvad https://github.com/edoburu/django-parler/archive/master.zip
django-taggit django-taggit
django-selects2 django-filer
django-cms>=3.0
django-select2
pytz
django-taggit-templatetags django-taggit-templatetags
django-taggit-autosuggest django-taggit-autosuggest
django-admin-enhancer django-admin-enhancer