Skip to content

Commit

Permalink
Small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Sokolov committed Nov 22, 2011
1 parent a660644 commit 38ac189
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
22 changes: 19 additions & 3 deletions site/source/apps/techblog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@
from techblog.constants import GENDER_MALE, GENDER_FEMALE
from django.conf import settings


#class Language(models.Model):
# class Meta:
# verbose_name = u'Language'
# verbose_name_plural = u'Languages'
# ordering = ('title',)
#
# title = models.CharField(max_length=25, verbose_name=u'Title')
# slug = models.SlugField(max_length=64, default="", unique=True, db_index=True, verbose_name=u'Slug')
#
# def __unicode__(self):
# return self.title


class Category(models.Model):
class Meta:
verbose_name = u'Категория'
Expand All @@ -35,6 +49,7 @@ def get_categories_with_count():
categories = categories.annotate(count=Count('article__id')).filter(count__gt=0).order_by('-count')
return categories


class Article(models.Model):
class Meta:
verbose_name = u'статья'
Expand All @@ -50,6 +65,9 @@ def __unicode__(self):
date = models.DateTimeField(u'Время публикации', default=datetime.now())
is_public = models.BooleanField(u'Статья опубликована?', default=False)
notified_on_first_publish = models.BooleanField(default=False, editable=False)

# parent = models.ForeignKey('self', blank=True, null=True, verbose_name=u'Parent', help_text='The article, which directly is translated.')
# original = models.ForeignKey('self', blank=True, null=True, verbose_name=u'Original', help_text='The original article.')

MARKUP_HTML = u'html'
MARKUP_MARKDOWN = u'markdown'
Expand All @@ -73,10 +91,8 @@ def __unicode__(self):

def save(self, *args, **kwargs):

# TODO: Move to __init__
from techblog.services.articles import ArticleService
article_service = ArticleService()
rendered_article = article_service.render_markups(self)
rendered_article = ArticleService.render_markups(self)

self.short = rendered_article.short
self.description = rendered_article.description
Expand Down
7 changes: 4 additions & 3 deletions site/source/apps/techblog/services/articles.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,16 @@ def render_markup(markup, raw_data):
return data


def render_markups(self, article):
@classmethod
def render_markups(cls, article):

class RenderedArticle(object):
def __init__(self, short, description):
self.short = short
self.description = description

markup = article.markup
short = self.render_markup(markup, article.short_raw)
description = self.render_markup(markup, article.description_raw)
short = cls.render_markup(markup, article.short_raw)
description = cls.render_markup(markup, article.description_raw)

return RenderedArticle(short, description)

0 comments on commit 38ac189

Please sign in to comment.