How to use the feincms.models.Base function in FeinCMS

To help you get started, we’ve selected a few FeinCMS examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github feincms / feincms / tests / testapp / models.py View on Github external
verbose_name_plural = "categories"

    def __str__(self):
        return self.name


class ExampleCMSBase(Base):
    pass


ExampleCMSBase.register_regions(
    ("region", "region title"), ("region2", "region2 title")
)


class ExampleCMSBase2(Base):
    pass


ExampleCMSBase2.register_regions(
    ("region", "region title"), ("region2", "region2 title")
)


class MyModel(create_base_model()):
    pass


MyModel.register_regions(("main", "Main region"))


unchanged = CustomContentType
github feincms / feincms / tests / testapp / models.py View on Github external
name = models.CharField(max_length=20)
    slug = models.SlugField()
    parent = models.ForeignKey(
        "self", blank=True, null=True, related_name="children", on_delete=models.CASCADE
    )

    class Meta:
        ordering = ["tree_id", "lft"]
        verbose_name = "category"
        verbose_name_plural = "categories"

    def __str__(self):
        return self.name


class ExampleCMSBase(Base):
    pass


ExampleCMSBase.register_regions(
    ("region", "region title"), ("region2", "region2 title")
)


class ExampleCMSBase2(Base):
    pass


ExampleCMSBase2.register_regions(
    ("region", "region title"), ("region2", "region2 title")
)
github matthiask / django-content-editor / feincms / tests.py View on Github external
def test_get_object(self):
        from feincms.utils import get_object

        self.assertRaises(AttributeError, lambda: get_object('feincms.does_not_exist'))
        self.assertRaises(ImportError, lambda: get_object('feincms.does_not_exist.fn'))

        self.assertEqual(get_object, get_object('feincms.utils.get_object'))

    def test_collect_dict_values(self):
        from feincms.utils import collect_dict_values

        self.assertEqual({'a': [1, 2], 'b': [3]},
            collect_dict_values([('a', 1), ('a', 2), ('b', 3)]))


class ExampleCMSBase(Base):
    pass

ExampleCMSBase.register_regions(('region', 'region title'), ('region2', 'region2 title'))

class CMSBaseTest(TestCase):
    def test_01_simple_content_type_creation(self):
        self.assertEqual(ExampleCMSBase.content_type_for(FileContent), None)

        ExampleCMSBase.create_content_type(ContactFormContent)
        ExampleCMSBase.create_content_type(FileContent, regions=('region2',))

        # no POSITION_CHOICES, should raise
        self.assertRaises(ImproperlyConfigured,
                          lambda: ExampleCMSBase.create_content_type(ImageContent))

        ExampleCMSBase.create_content_type(RawContent)
github feincms / feincms / feincms / tests.py View on Github external
def test_get_object(self):
        from feincms.utils import get_object

        self.assertRaises(AttributeError, lambda: get_object('feincms.does_not_exist'))
        self.assertRaises(ImportError, lambda: get_object('feincms.does_not_exist.fn'))

        self.assertEqual(get_object, get_object('feincms.utils.get_object'))

    def test_collect_dict_values(self):
        from feincms.utils import collect_dict_values

        self.assertEqual({'a': [1, 2], 'b': [3]},
            collect_dict_values([('a', 1), ('a', 2), ('b', 3)]))


class ExampleCMSBase(Base):
    pass

ExampleCMSBase.register_regions(('region', 'region title'), ('region2', 'region2 title'))

class CMSBaseTest(TestCase):
    def test_01_simple_content_type_creation(self):
        self.assertEqual(ExampleCMSBase.content_type_for(FileContent), None)

        ExampleCMSBase.create_content_type(ContactFormContent)
        ExampleCMSBase.create_content_type(FileContent, regions=('region2',))

        # no POSITION_CHOICES, should raise
        self.assertRaises(ImproperlyConfigured,
                          lambda: ExampleCMSBase.create_content_type(ImageContent))

        ExampleCMSBase.create_content_type(RawContent)
github django-leonardo / django-leonardo / leonardo / module / doc / models.py View on Github external
DOCUMENT_OUTPUTS = (
    ('html', _('Web page (HTML)')),
    ('eml', _('E-mail message (HTML)')),
    ('rml', _('Print format (PDF)')),
    ('odt', _('Print format (ODT)')),
)

class DocumentManager(models.Manager):
    def published(self):
        return self.filter(
            published__isnull=False,
            published_on__lte=datetime.now(),
        )

class Document(Base):
    title = models.CharField(_('title'), max_length=255)
    language = models.CharField(_('language'), max_length=10, choices=settings.LANGUAGES, default=settings.LANGUAGE_CODE)
    outputs = MultiSelectField(max_length=255, verbose_name=_('outputs'), choices=DOCUMENT_OUTPUTS)
    supplier = models.ForeignKey(Entity, verbose_name=_('supplier'), related_name='doc_supplier')
    client = models.ForeignKey(Entity, verbose_name=_('client'), related_name='doc_client')
    summary = HTMLField(_('description'), blank=True, null=True)
    published = models.BooleanField(_('published'), default=False)
    published_on = models.DateTimeField(_('published on'), blank=True, null=True,
        help_text=_('Will be set automatically once you set the `published` above.'))
    author = models.ForeignKey(User, verbose_name=_('author'), blank=True, null=True)

    class Meta:
        get_latest_by = 'published_on'
        ordering = ['-published_on']
        verbose_name = _('document')
        verbose_name_plural = _('documents')
github django-leonardo / django-leonardo / leonardo / module / web / models / widget.py View on Github external
'dbtemplates.Template', verbose_name=_('Base template'),
        related_name='base_templates', limit_choices_to={'name__startswith': "base/widget/"})

    style = models.TextField(verbose_name=_('Base style'), blank=True)

    def __str__(self):
        return self.label or smart_text(self._meta.verbose_name + ' %s' % self.pk)

    class Meta:
        verbose_name = _("Widget base theme")
        verbose_name_plural = _("Widget base themes")
        app_label = "web"


@python_2_unicode_compatible
class Widget(FeinCMSBase):

    feincms_item_editor_inline = WidgetInline

    enabled = models.NullBooleanField(
        verbose_name=_('Is visible?'), default=True)
    label = models.CharField(
        verbose_name=_("Title"), max_length=255, null=True, blank=True)
    base_theme = models.ForeignKey(
        WidgetBaseTheme, verbose_name=_('Base theme'),
        related_name="%(app_label)s_%(class)s_related")
    content_theme = models.ForeignKey(
        WidgetContentTheme, verbose_name=_('Content theme'),
        related_name="%(app_label)s_%(class)s_related")
    layout = models.CharField(
        verbose_name=_("Layout"), max_length=25,
        default='inline', choices=WIDGET_LAYOUT_CHOICES)
github glamkit / glamkit-feincmstools / feincmstools / base.py View on Github external
declared_types += (found_type,)

    return declared_types


# --- Lumpy models ------------------------------------------------------------

class LumpyContentBase(models.base.ModelBase):
    """ Metaclass which simply calls _register() for each new class. """
    def __new__(cls, name, bases, attrs):
        new_class = super(LumpyContentBase, cls).__new__(cls, name, bases, attrs)
        new_class._register()
        return new_class


class LumpyContent(Base):
    """ As opposed to FlatPage content -- can have FeinCMS content regions. """

    __metaclass__ = LumpyContentBase

    class Meta:
        abstract = True


    # Public API
    default_content_types = (default_types,) #FIXME: Should rename to `allowed_content_types` or `allowed_content_types` or `content_types` or `content_type_specs`, as they're not "default".
    template_specs = None #FIXME: Maybe rename to `available_templates`
    regions = None

    # Auto-register default regions and all available feincmstools content types
    DEFAULT_REGIONS = (('main', _('Main')),)
github feincms / feincms / feincms / module / blog / models.py View on Github external
from feincms.admin import item_editor
from feincms.models import Base


class EntryManager(models.Manager):
    def published(self):
        return self.filter(
            published=True,
            published_on__isnull=False,
            published_on__lte=timezone.now(),
        )


@python_2_unicode_compatible
class Entry(Base):
    published = models.BooleanField(_('published'), default=False)
    title = models.CharField(
        _('title'), max_length=100,
        help_text=_('This is used for the generated navigation too.'))
    slug = models.SlugField()

    published_on = models.DateTimeField(
        _('published on'), blank=True, null=True,
        help_text=_(
            'Will be set automatically once you tick the `published`'
            ' checkbox above.'))

    class Meta:
        get_latest_by = 'published_on'
        ordering = ['-published_on']
        verbose_name = _('entry')
github feinheit / zipfelchappe / zipfelchappe / models.py View on Github external
def funding(self):
        return self.online().filter(end__gte=now)

    def billable(self):
        """ Returns a list of projects that are successfully financed
            (payments can be collected) """
        ending = self.filter(end__lte=now())
        return list([project for project in ending if project.is_financed])


def teaser_img_upload_to(instance, filename):
    return (u'projects/%s/%s' % (instance.slug, filename)).lower()


class Project(Base, TranslatedMixin):
    """ The heart of zipfelchappe. Projects are time limited and crowdfunded
        ideas that either get financed by reaching a minimum goal or not.
        Money will only be deducted from backers if the goal is reached. """

    max_duration = MAX_PROJECT_DURATION_DAYS

    def __init__(self, *args, **kwargs):
        # add the css and javascript files to project admin.
        super(Project, self).__init__(*args, **kwargs)
        self.feincms_item_editor_includes['head'].update([
            'admin/zipfelchappe/_project_head_include.html',
        ])

    title = models.CharField(_('title'), max_length=100)

    slug = models.SlugField(_('slug'), unique=True)
github feinheit / zipfelchappe / zipfelchappe / translations / models.py View on Github external
from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _

from feincms.models import Base


class ProjectTranslation(Base):

    translation_of = models.ForeignKey('zipfelchappe.Project',
        related_name='translations')

    lang = models.CharField(_('language'), max_length=10,
        choices=settings.LANGUAGES)

    title = models.CharField(_('title'), max_length=100)

    teaser_text = models.TextField(_('teaser text'), blank=True)

    class Meta:
        app_label = 'zipfelchappe'
        verbose_name = _('translation')
        verbose_name_plural = _('translations')
        unique_together = (('translation_of', 'lang'),)