Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoding issues #51

Merged
merged 2 commits into from
Nov 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion djangocms_blog/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.3.a1'
__version__ = '0.3.a2'
17 changes: 11 additions & 6 deletions djangocms_blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from django.core.urlresolvers import reverse
from django.db import models
from django.utils import timezone
from django.utils.encoding import force_text
from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.html import strip_tags, escape
from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _, get_language
from djangocms_text_ckeditor.fields import HTMLField
Expand All @@ -22,6 +23,7 @@
BLOG_CURRENT_POST_IDENTIFIER = 'djangocms_post_current'


@python_2_unicode_compatible
class BlogCategory(TranslatableModel):
"""
Blog category
Expand All @@ -47,7 +49,7 @@ class Meta:
def count(self):
return self.blog_posts.filter(publish=True).count()

def __unicode__(self):
def __str__(self):
return self.safe_translation_getter('name')

def save(self, *args, **kwargs):
Expand All @@ -59,6 +61,7 @@ def save(self, *args, **kwargs):
self.save_translations()


@python_2_unicode_compatible
class Post(ModelMeta, TranslatableModel):
"""
Blog post
Expand Down Expand Up @@ -155,7 +158,7 @@ def get_description(self):
description = self.safe_translation_getter('meta_description', any_language=True)
if not description:
description = self.safe_translation_getter('abstract', any_language=True)
return description.strip()
return escape(strip_tags(description)).strip()

def get_image_full_url(self):
if self.main_image:
Expand All @@ -175,7 +178,7 @@ class Meta:
ordering = ('-date_published', '-date_created')
get_latest_by = 'date_published'

def __unicode__(self):
def __str__(self):
return self.safe_translation_getter('title')

def save(self, *args, **kwargs):
Expand Down Expand Up @@ -211,6 +214,7 @@ def get_full_url(self):
return self.make_full_url(self.get_absolute_url())


@python_2_unicode_compatible
class LatestPostsPlugin(CMSPlugin):

latest_posts = models.IntegerField(_(u'Articles'), default=get_setting('LATEST_POSTS'),
Expand All @@ -220,7 +224,7 @@ class LatestPostsPlugin(CMSPlugin):
categories = models.ManyToManyField('BlogCategory', blank=True,
help_text=_('Show only the blog articles tagged with chosen categories.'))

def __unicode__(self):
def __str__(self):
return u'%s latest articles by tag' % self.latest_posts

def copy_relations(self, oldinstance):
Expand All @@ -234,6 +238,7 @@ def get_posts(self):
return posts[:self.latest_posts]


@python_2_unicode_compatible
class AuthorEntriesPlugin(CMSPlugin):
authors = models.ManyToManyField(
dj_settings.AUTH_USER_MODEL, verbose_name=_('Authors'),
Expand All @@ -244,7 +249,7 @@ class AuthorEntriesPlugin(CMSPlugin):
help_text=_('The number of author articles to be displayed.')
)

def __unicode__(self):
def __str__(self):
return u'%s latest articles by author' % self.latest_posts

def copy_relations(self, oldinstance):
Expand Down