diff --git a/djangocms_blog/admin.py b/djangocms_blog/admin.py index 46d55c6..33e824c 100755 --- a/djangocms_blog/admin.py +++ b/djangocms_blog/admin.py @@ -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 diff --git a/djangocms_blog/cms_toolbar.py b/djangocms_blog/cms_toolbar.py index 73a34ea..115d750 100644 --- a/djangocms_blog/cms_toolbar.py +++ b/djangocms_blog/cms_toolbar.py @@ -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 diff --git a/djangocms_blog/fields.py b/djangocms_blog/fields.py index 41241ca..545df47 100644 --- a/djangocms_blog/fields.py +++ b/djangocms_blog/fields.py @@ -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"]) diff --git a/djangocms_blog/forms.py b/djangocms_blog/forms.py index 37dcb70..96f8838 100644 --- a/djangocms_blog/forms.py +++ b/djangocms_blog/forms.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- from django import forms from django.conf import settings - import django_select2 diff --git a/djangocms_blog/managers.py b/djangocms_blog/managers.py index dd61ab1..f4edc5f 100644 --- a/djangocms_blog/managers.py +++ b/djangocms_blog/managers.py @@ -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) diff --git a/djangocms_blog/migrations/0001_initial.py b/djangocms_blog/migrations/0001_initial.py index ac5d495..06510c9 100644 --- a/djangocms_blog/migrations/0001_initial.py +++ b/djangocms_blog/migrations/0001_initial.py @@ -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'] \ No newline at end of file + complete_apps = ['djangocms_blog'] diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index b1de252..63ab542 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -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 diff --git a/djangocms_blog/settings.py b/djangocms_blog/settings.py index 05dbd71..b2ffae7 100644 --- a/djangocms_blog/settings.py +++ b/djangocms_blog/settings.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from django.utils.translation import ugettext_lazy as _ BLOG_IMAGE_THUMBNAIL_SIZE = { 'size': '120x120', diff --git a/djangocms_blog/templates/admin/djangocms_blog/post_change_form.html b/djangocms_blog/templates/admin/djangocms_blog/post_change_form.html index d6569bf..4a8e0f4 100644 --- a/djangocms_blog/templates/admin/djangocms_blog/post_change_form.html +++ b/djangocms_blog/templates/admin/djangocms_blog/post_change_form.html @@ -1,4 +1,4 @@ -{% extends "admin/hvad/change_form.html" %} +{% extends "admin/parler/change_form.html" %} {% load static %} {% block extrahead %} diff --git a/djangocms_blog/templates/djangocms_blog/base.html b/djangocms_blog/templates/djangocms_blog/base.html index db08d48..2e68808 100644 --- a/djangocms_blog/templates/djangocms_blog/base.html +++ b/djangocms_blog/templates/djangocms_blog/base.html @@ -1,6 +1,6 @@ -{% extends "interne.html" %} +{% extends "base.html" %} -{% block contenuto %} +{% block application %}