Fix error in models

This commit is contained in:
Iacopo Spalletti 2014-06-09 00:06:12 +02:00
parent a393653d3c
commit c34fd11139

View file

@ -6,6 +6,7 @@ from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
from django.utils.encoding import force_text
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _, get_language from django.utils.translation import ugettext_lazy as _, get_language
from djangocms_text_ckeditor.fields import HTMLField from djangocms_text_ckeditor.fields import HTMLField
@ -54,7 +55,7 @@ class BlogCategory(TranslatableModel):
for lang in self.get_available_languages(): for lang in self.get_available_languages():
self.set_current_language(lang) self.set_current_language(lang)
if not self.slug and self.name: if not self.slug and self.name:
self.slug = slugify(self.name) self.slug = slugify(force_text(self.name))
self.save_translations() self.save_translations()
@ -85,7 +86,7 @@ class Post(ModelMeta, TranslatableModel):
related_name='djangocms_blog_post_full', related_name='djangocms_blog_post_full',
blank=True, null=True) blank=True, null=True)
enable_comments = models.BooleanField( enable_comments = models.BooleanField(
verbose_name = _(u'Enable comments on post'), verbose_name=_(u'Enable comments on post'),
default=settings.BLOG_ENABLE_COMMENTS default=settings.BLOG_ENABLE_COMMENTS
) )
@ -133,12 +134,12 @@ class Post(ModelMeta, TranslatableModel):
} }
def get_keywords(self): def get_keywords(self):
return self.safe_translation_getter('meta_keywords', language_code=get_language()).strip().split(",") return self.safe_translation_getter('meta_keywords').strip().split(",")
def get_description(self): def get_description(self):
description = self.safe_translation_getter('meta_description', language_code=get_language()) description = self.safe_translation_getter('meta_description', any_language=True)
if not description: if not description:
description = self.safe_translation_getter('abstract', language_code=get_language()) description = self.safe_translation_getter('abstract', any_language=True)
return description.strip() return description.strip()
def get_image_url(self): def get_image_url(self):
@ -172,7 +173,7 @@ class Post(ModelMeta, TranslatableModel):
kwargs = {'year': self.date_published.year, kwargs = {'year': self.date_published.year,
'month': self.date_published.month, 'month': self.date_published.month,
'day': self.date_published.day, 'day': self.date_published.day,
'slug': self.safe_translation_getter('slug', language_code=get_language())} 'slug': self.safe_translation_getter('slug', any_language=True)}
return reverse('djangocms_blog:post-detail', kwargs=kwargs) return reverse('djangocms_blog:post-detail', kwargs=kwargs)
def thumbnail_options(self): def thumbnail_options(self):
@ -182,7 +183,7 @@ class Post(ModelMeta, TranslatableModel):
return settings.BLOG_IMAGE_THUMBNAIL_SIZE return settings.BLOG_IMAGE_THUMBNAIL_SIZE
def full_image_options(self): def full_image_options(self):
if self.main_image_fulll_id: if self.main_image_full_id:
return self.main_image_full.as_dict return self.main_image_full.as_dict
else: else:
return settings.BLOG_IMAGE_FULL_SIZE return settings.BLOG_IMAGE_FULL_SIZE