Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from django.db import models
from django.utils.translation import ugettext_lazy as _
from feincms import extensions
THEME_CHOICES = (
('default', _('Default theme')),
# ('amelia', _('Amelia')),
('cosmo', _('Cosmo')),
('cyborg', _('Cyborg')),
# ('slate', _('Slate')),
# ('superhero', _('Superhero')),
('united', _('United')),
)
class Board(extensions.Extension):
def handle_model(self):
self.model.add_to_class('board_theme', models.CharField(_('dashboard theme'), max_length=100, blank=True,
help_text=_('Dashboard theme for browser window.'), choices=THEME_CHOICES, default="default"))
self.model.add_to_class('board_locked', models.BooleanField(_('locked'),
help_text=_('Is dashboard locked for editing?'), default=False))
self.model.add_to_class('board_public', models.BooleanField(_('public'),
help_text=_('Is dashboard open for public viewing?'), default=False))
self.model.add_to_class('board_width', models.IntegerField(_('Board width'), default=1920,
help_text=_('Width in pixels of the whole dashboard.')))
self.model.add_to_class('board_height', models.IntegerField(_('Board height'), default=1080,
help_text=_('Height in pixels of the whole dashboard.')))
self.model.add_to_class('widget_width', models.IntegerField(_('Widget width'), default=220,
help_text=_('Width in pixels of a single widget.')))
self.model.add_to_class('widget_height', models.IntegerField(_('Widget height'), default=220,
help_text=_('Height in pixels of a single widget.')))
def navigation_extension_choices():
for ext in NavigationExtension.types:
if issubclass(ext, NavigationExtension) and ext is not NavigationExtension:
yield ("%s.%s" % (ext.__module__, ext.__name__), ext.name)
def get_extension_class(extension):
extension = get_object(extension)
if isinstance(extension, types.ModuleType):
return getattr(extension, "Extension")
return extension
class Extension(extensions.Extension):
ident = "navigation" # TODO actually use this
navigation_extensions = None
@cached_property
def _extensions(self):
if self.navigation_extensions is None:
return OrderedDict(
("%s.%s" % (ext.__module__, ext.__name__), ext)
for ext in NavigationExtension.types
if (
issubclass(ext, NavigationExtension)
and ext is not NavigationExtension
)
)
else:
('primary_links', _('primary links')),
('secondary_links', _('secondary links')),
)
navigation_type_choices = getattr(settings, "NAVIGATION_TYPE_CHOICES", DEFAULT_NAVIGATION_TYPE_CHOICES)
def register(cls, admin_cls):
cls.add_to_class('navigation_type', models.CharField(_('navigation type'),
max_length=32, choices=navigation_type_choices, default=navigation_type_choices[0][0]))
if hasattr(admin_cls, 'add_extension_options'):
admin_cls.add_extension_options('navigation_type')
else:
admin_cls.fieldsets[0][1]['fields'].extend(['navigation_type',])
class NavigationTypeExtension(extensions.Extension):
"""
``NAVIGATION_TYPE_CHOICES`` - from settings.py
"""
def handle_model(self):
self.model.add_to_class(
'navigation_type',
models.CharField(_('navigation type'),
max_length=32,
choices=navigation_type_choices,
default=navigation_type_choices[0][0]))
def handle_modeladmin(self, modeladmin):
modeladmin.add_extension_options('navigation_type')
import warnings
from django.contrib.gis import admin
from django.contrib.gis.db import models
from django.utils.translation import ugettext_lazy as _
from feincms import extensions
class Extension(extensions.Extension):
def handle_model(self):
self.model.add_to_class(
'location',
models.PointField(verbose_name=_('location'), null=True, blank=True))
from articles.models import ArticleManager
class GeoArticleManager(ArticleManager, models.GeoManager):
pass
self.model.add_to_class('objects', GeoArticleManager())
def handle_modeladmin(self, modeladmin):
if not issubclass(modeladmin, admin.OSMGeoAdmin):
warnings.warn(
"The admin class articles ArticleAdmin class is not a sub class of django.contrib.gis.admin.OSMGeoAdmin. "
"""
Sometimes, a single title is not enough, you'd like subtitles, and maybe
differing titles in the navigation and in the <title>-tag. This extension lets
you do that.
"""
from __future__ import absolute_import, unicode_literals
from django.db import models
from django.utils.translation import ugettext_lazy as _
from feincms import extensions
from feincms._internal import monkeypatch_property
class Extension(extensions.Extension):
def handle_model(self):
self.model.add_to_class(
"_content_title",
models.TextField(
_("content title"),
blank=True,
help_text=_(
"The first line is the main title, the following"
" lines are subtitles."
),
),
)
self.model.add_to_class(
"_page_title",
models.CharField(</title>
"""
This introduces a new page type, which has no content of its own but inherits
all content from the linked page.
"""
from __future__ import absolute_import, unicode_literals
from django.db import models
from django.utils.translation import ugettext_lazy as _
from feincms import extensions
from feincms._internal import monkeypatch_property
class Extension(extensions.Extension):
def handle_model(self):
self.model.add_to_class(
"symlinked_page",
models.ForeignKey(
"self",
blank=True,
null=True,
on_delete=models.CASCADE,
related_name="%(app_label)s_%(class)s_symlinks",
verbose_name=_("symlinked page"),
help_text=_("All content is inherited from this page if given."),
),
)
@monkeypatch_property(self.model)
def content(self):
from django.conf.urls import patterns, url
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import ugettext_lazy as _
from feincms import extensions
try:
from taggit.managers import TaggableManager
except ImportError:
raise ImproperlyConfigured('You need to install django-taggit to use the tags extension')
class Extension(extensions.Extension):
def handle_model(self):
self.model.add_to_class('tags', TaggableManager(verbose_name=_('tags'), blank=True))
self.model.get_urlpatterns_orig = self.model.get_urlpatterns
@classmethod
def get_urlpatterns(cls):
taggit_patterns = patterns('taggit.views',
url(r'^tags/(?P[^/]+)/$', 'tagged_object_list', {
'queryset': cls.objects.active}, name="article_tagged_list"
),
)
return cls.get_urlpatterns_orig() + taggit_patterns
self.model.get_urlpatterns = get_urlpatterns
def handle_modeladmin(self, modeladmin):
modeladmin.add_extension_options(_('Tags'), {
from django.db import models
from django.utils.translation import ugettext_lazy as _
from feincms import extensions
from ..models import Category
class CategoryAdmin(admin.ModelAdmin):
search_fields = ['title', 'slug']
prepopulated_fields = {
'slug': ('title',),
}
class Extension(extensions.Extension):
ident = 'categories'
def handle_model(self):
self.model.add_to_class('categories', models.ManyToManyField(Category,
verbose_name=_('categories'), related_name='projects',
null=True, blank=True)
)
def handle_modeladmin(self, modeladmin):
admin.site.register(Category, CategoryAdmin)
modeladmin.fieldsets.insert(2, [
_('categories'), {
'fields': ['categories'],
'classes': ['feincms_inline'],
}
"""
This extension adds a language field to every blog entry.
Blog entries in secondary languages can be said to be a translation of a
blog entry in the primary language (the first language in settings.LANGUAGES),
thereby enabling deeplinks between translated blog entries.
"""
from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
from feincms import extensions
class Extension(extensions.Extension):
def handle_model(self):
primary_language = settings.LANGUAGES[0][0]
self.model.add_to_class('language', models.CharField(
_('language'), max_length=10,
choices=settings.LANGUAGES))
self.model.add_to_class('translation_of', models.ForeignKey('self',
blank=True, null=True, verbose_name=_('translation of'),
related_name='translations',
limit_choices_to={'language': primary_language},
help_text=_('Leave this empty for entries in the primary language.')
))
def available_translations(self):
if self.language == primary_language:
return self.translations.all()
"""
Add a many-to-many relationship field to relate this page to other pages.
"""
from __future__ import absolute_import, unicode_literals
from django.db import models
from django.utils.translation import ugettext_lazy as _
from feincms import extensions, settings
class Extension(extensions.Extension):
def handle_model(self):
self.model.add_to_class(
"related_pages",
models.ManyToManyField(
settings.FEINCMS_DEFAULT_PAGE_MODEL,
blank=True,
related_name="%(app_label)s_%(class)s_related",
help_text=_("Select pages that should be listed as related content."),
),
)
def handle_modeladmin(self, modeladmin):
modeladmin.extend_list("filter_horizontal", ["related_pages"])
modeladmin.add_extension_options(
_("Related pages"), {"fields": ("related_pages",), "classes": ("collapse",)}