SWitch to parler for multilingual support.
Fix templates
This commit is contained in:
parent
086dde879d
commit
958ed651f2
16 changed files with 76 additions and 47 deletions
|
@ -2,7 +2,7 @@
|
|||
from admin_enhancer.admin import EnhancedModelAdminMixin
|
||||
from cms.admin.placeholderadmin import PlaceholderAdmin, FrontendEditableAdmin
|
||||
from django.contrib import admin
|
||||
from hvad.admin import TranslatableAdmin
|
||||
from parler.admin import TranslatableAdmin
|
||||
|
||||
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):
|
||||
if not obj.author_id:
|
||||
obj.author = request.user
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from cms.toolbar_base import CMSToolbar
|
||||
from cms.toolbar_pool import toolbar_pool
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from cms.toolbar_base import CMSToolbar
|
||||
from cms.toolbar_pool import toolbar_pool
|
||||
|
||||
|
||||
@toolbar_pool.register
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from south.modelsinspector import add_introspection_rules
|
||||
add_introspection_rules([], ["^djangocms_blog\.fields\.UsersWithPermsManyToManyField"])
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
|
||||
import django_select2
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import datetime
|
|||
|
||||
from django.db import models
|
||||
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
|
||||
|
||||
|
@ -62,7 +62,7 @@ class TaggedFilterItem(object):
|
|||
if len(count) > 0:
|
||||
weight_fun = get_weight_fun(BLOG_TAGCLOUD_MIN,
|
||||
BLOG_TAGCLOUD_MAX,
|
||||
min(count), max(count))
|
||||
min(count), BLOG_TAGCLOUD_MAX)
|
||||
tagquery = tagquery.order_by('name')
|
||||
for tag in tagquery:
|
||||
tag.weight = weight_fun(tag.count)
|
||||
|
|
|
@ -11,9 +11,9 @@ class Migration(SchemaMigration):
|
|||
# Adding model 'BlogCategoryTranslation'
|
||||
db.create_table(u'djangocms_blog_blogcategory_translation', (
|
||||
(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)),
|
||||
('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'])),
|
||||
))
|
||||
db.send_create_signal(u'djangocms_blog', ['BlogCategoryTranslation'])
|
||||
|
@ -33,10 +33,10 @@ class Migration(SchemaMigration):
|
|||
# Adding model 'PostTranslation'
|
||||
db.create_table(u'djangocms_blog_post_translation', (
|
||||
(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)),
|
||||
('slug', self.gf('django.db.models.fields.SlugField')(max_length=50, blank=True)),
|
||||
('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'])),
|
||||
))
|
||||
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'])
|
||||
|
||||
# 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'
|
||||
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)),
|
||||
|
@ -130,6 +139,9 @@ class Migration(SchemaMigration):
|
|||
# Removing M2M table for field tags on 'LatestPostsPlugin'
|
||||
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'
|
||||
db.delete_table(u'cmsplugin_authorentriesplugin')
|
||||
|
||||
|
@ -227,6 +239,7 @@ class Migration(SchemaMigration):
|
|||
},
|
||||
u'djangocms_blog.latestpostsplugin': {
|
||||
'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'}),
|
||||
'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'})
|
||||
|
@ -276,14 +289,14 @@ class Migration(SchemaMigration):
|
|||
'Meta': {'ordering': "('name',)", 'unique_together': "(('parent', 'name'),)", 'object_name': 'Folder'},
|
||||
'created_at': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
|
||||
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
|
||||
'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
|
||||
'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
|
||||
u'level': ('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'}),
|
||||
'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']"}),
|
||||
'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'}),
|
||||
'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
|
||||
u'rght': ('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'})
|
||||
},
|
||||
'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'}),
|
||||
'must_always_publish_author_credit': ('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'})
|
||||
},
|
||||
u'taggit.tag': {
|
||||
|
@ -308,4 +320,4 @@ class Migration(SchemaMigration):
|
|||
}
|
||||
}
|
||||
|
||||
complete_apps = ['djangocms_blog']
|
||||
complete_apps = ['djangocms_blog']
|
||||
|
|
|
@ -10,7 +10,7 @@ from django.utils.text import slugify
|
|||
from django.utils.translation import ugettext_lazy as _
|
||||
from djangocms_text_ckeditor.fields import HTMLField
|
||||
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 .managers import GenericDateTaggedManager
|
||||
|
@ -40,15 +40,15 @@ class BlogCategory(TranslatableModel):
|
|||
return self.blog_posts.count()
|
||||
|
||||
def __unicode__(self):
|
||||
return self.lazy_translation_getter('name')
|
||||
return self.safe_translation_getter('name')
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(BlogCategory, self).save(*args, **kwargs)
|
||||
for item in self._meta.translations_model.objects.filter(master__pk=self.pk):
|
||||
title = getattr(item, "name", False)
|
||||
if title and not item.slug:
|
||||
item.slug = slugify(title)
|
||||
item.save()
|
||||
for lang in self.get_available_languages():
|
||||
self.set_current_language(lang)
|
||||
if not self.slug and self.name:
|
||||
self.slug = slugify(self.name)
|
||||
self.save_translations()
|
||||
|
||||
|
||||
class Post(TranslatableModel):
|
||||
|
@ -90,15 +90,15 @@ class Post(TranslatableModel):
|
|||
verbose_name_plural = _('blog post')
|
||||
|
||||
def __unicode__(self):
|
||||
return self.lazy_translation_getter('title')
|
||||
return self.safe_translation_getter('title')
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(Post, self).save(*args, **kwargs)
|
||||
for item in self._meta.translations_model.objects.filter(master__pk=self.pk):
|
||||
title = getattr(item, "title", False)
|
||||
if title and not item.slug:
|
||||
item.slug = slugify(title)
|
||||
item.save()
|
||||
for lang in self.get_available_languages():
|
||||
self.set_current_language(lang)
|
||||
if not self.slug and self.title:
|
||||
self.slug = slugify(self.title)
|
||||
self.save_translations()
|
||||
|
||||
def get_absolute_url(self):
|
||||
kwargs = {'year': self.date_published.year,
|
||||
|
@ -120,7 +120,6 @@ class Post(TranslatableModel):
|
|||
else:
|
||||
return "http://%s%s" % (s.domain, self.get_absolute_url())
|
||||
|
||||
|
||||
def full_image_options(self):
|
||||
if self.main_image_fulll_id:
|
||||
return self.main_image_full.as_dict
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
BLOG_IMAGE_THUMBNAIL_SIZE = {
|
||||
'size': '120x120',
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% extends "admin/hvad/change_form.html" %}
|
||||
{% extends "admin/parler/change_form.html" %}
|
||||
{% load static %}
|
||||
|
||||
{% block extrahead %}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{% extends "interne.html" %}
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block contenuto %}
|
||||
{% block application %}
|
||||
<div class="app app-blog">
|
||||
{% block content_blog %}{% endblock %}
|
||||
</div>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
{% load i18n thumbnail cms_tags nephila_django %}
|
||||
{% load i18n thumbnail cms_tags %}
|
||||
{% load url from future %}
|
||||
|
||||
<article id="post-{{ post.slug }}" class="post-item">
|
||||
<header>
|
||||
<h3><a href="{{ post.get_absolute_url }}">{% show_editable_model post "title" %}</a></h3>
|
||||
{% 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>
|
||||
{% if post.tags.exists %}
|
||||
<nav class="blog-tags">
|
||||
|
|
|
@ -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>
|
|
@ -1,7 +1,10 @@
|
|||
{% load i18n %}
|
||||
<div class="plugin plugin-blog">
|
||||
<div class="blog-latest-entries">
|
||||
{% for post in post_list %}
|
||||
{% include "djangocms_blog/includes/blog_item.html" with post=instance.get_posts %}
|
||||
{% for post in instance.get_posts %}
|
||||
{% include "djangocms_blog/includes/blog_item.html" with post=post %}
|
||||
{% empty %}
|
||||
<p class="blog-empty">{% trans "No post found." %}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
|
@ -1,14 +1,14 @@
|
|||
{% extends "djangocms_blog/base.html" %}
|
||||
{% load i18n thumbnail cms_tags nephila_django %}
|
||||
{% load i18n thumbnail cms_tags %}
|
||||
{% load url from future %}
|
||||
|
||||
{% block content_blog %}
|
||||
<article id="post-{{ post.slug }}" class="post-item post-detail">
|
||||
<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 %}
|
||||
<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>
|
||||
{% if post.tags.exists %}
|
||||
<nav class="blog-tags">
|
||||
|
|
|
@ -1,20 +1,19 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
from cms.utils import get_language_from_request
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from django.core.urlresolvers import resolve
|
||||
from django.db.models import Count
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.views.generic import ListView, DetailView
|
||||
from hvad.admin import TranslatableModelAdminMixin
|
||||
|
||||
from .models import Post, BlogCategory
|
||||
|
||||
|
||||
class BaseBlogView(TranslatableModelAdminMixin):
|
||||
class BaseBlogView(object):
|
||||
|
||||
def get_queryset(self):
|
||||
language = self._language(self.request)
|
||||
language = get_language_from_request(self.request)
|
||||
manager = self.model._default_manager.language(language)
|
||||
if not self.request.user.is_staff:
|
||||
manager = manager.filter(publish=True)
|
||||
|
@ -35,6 +34,7 @@ class PostDetailView(BaseBlogView, DetailView):
|
|||
model = Post
|
||||
context_object_name = 'post'
|
||||
template_name = "djangocms_blog/post_detail.html"
|
||||
slug_field = 'translations__slug'
|
||||
|
||||
|
||||
class PostArchiveView(BaseBlogView, ListView):
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
django-hvad
|
||||
https://github.com/edoburu/django-parler/archive/master.zip
|
||||
django-taggit
|
||||
django-selects2
|
||||
django-filer
|
||||
django-cms>=3.0
|
||||
django-select2
|
||||
pytz
|
||||
django-taggit-templatetags
|
||||
django-taggit-autosuggest
|
||||
django-admin-enhancer
|
||||
|
|
Loading…
Reference in a new issue