Newer
Older
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.utils.translation import ugettext_lazy as _, ungettext_lazy
from django.utils import six
from django.utils.encoding import python_2_unicode_compatible
from django.db import models
from cms.models.pluginmodel import CMSPlugin
from cms.models.fields import PageField, PlaceholderField
from djangocms_text_ckeditor.fields import HTMLField
from newsbox.models import NewsboxModelBase
def newsboxcms_mcls_processor(mcls, class_name, class_bases, class_attrs, base, newsbox_opts):
class_attrs['newsbox_summary'] = HTMLField(
verbose_name=_('summary'))
newsbox_opts['trans_fieldnames'].append('newsbox_summary')
class_attrs['newsbox_body'] = PlaceholderField(
'newsbox_body',
verbose_name=_('body'))
if 'newsbox_body' in newsbox_opts['trans_fieldnames']:
newsbox_opts['trans_fieldnames'].remove('newsbox_body')
@python_2_unicode_compatible
class NewsboxPluginBase(CMSPlugin):
title = models.CharField(
verbose_name=_('Title'),
max_length=255, blank=True, null=True,
help_text=_('Title to display before the list'))
numitems = models.PositiveSmallIntegerField(
verbose_name=_('Number of news'),
default=2,
help_text=_('Number of news to display. '
with_pager = models.BooleanField(
verbose_name=_('Display a pager'),
default=False)
null=True, blank=True,
help_text=_('Page displaying all news'))
def __str__(self):
if self.numitems > 0:
return six.text_type(ungettext_lazy(
'Display of a news',
'Display of %(nb)d news',
self.numitems
return six.text_type(_('Display of all news'))
class Meta:
abstract = True
class NewsboxCMSBase(six.with_metaclass(NewsboxModelBase, models.Model)):
class Meta:
abstract = True
newsbox_metaclass_base_processor = 'newsboxcms_mcls_processor'