-
Notifications
You must be signed in to change notification settings - Fork 239
Expand file tree
/
Copy pathmodels.py
More file actions
104 lines (82 loc) · 3.09 KB
/
models.py
File metadata and controls
104 lines (82 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
from django import forms
from django.db import models
from django.utils.text import capfirst
from django.utils.translation import ugettext_lazy as _
from feincms.module.blog.models import Entry, EntryAdmin
from feincms.module.page.models import Page
from feincms.content.raw.models import RawContent
from feincms.content.image.models import ImageContent
from feincms.content.medialibrary.models import MediaFileContent
from feincms.content.application.models import ApplicationContent
from feincms.module.page.extensions.navigation import NavigationExtension, PagePretender
from feincms.content.application.models import reverse
import mptt
Page.register_templates({
'key': 'base',
'title': 'Base Template',
'path': 'base.html',
'regions': (
('main', 'Main region'),
('sidebar', 'Sidebar', 'inherited'),
),
})
Page.create_content_type(RawContent)
MediaFileContent.default_create_content_type(Page)
Page.create_content_type(ImageContent, POSITION_CHOICES=(
('default', 'Default position'),
))
def get_admin_fields(form, *args, **kwargs):
return {
'exclusive_subpages': forms.BooleanField(
label=capfirst(_('exclusive subpages')),
required=False,
initial=form.instance.parameters.get('exclusive_subpages', False),
help_text=_('Exclude everything other than the application\'s content when rendering subpages.'),
),
}
Page.create_content_type(ApplicationContent, APPLICATIONS=(
('blog_urls', 'Blog', {'admin_fields': get_admin_fields}),
('whatever', 'Test Urls', {'urls': 'feincms.tests.applicationcontent_urls'}),
))
Entry.register_regions(
('main', 'Main region'),
)
Entry.create_content_type(RawContent)
Entry.create_content_type(ImageContent, POSITION_CHOICES=(
('default', 'Default position'),
))
class BlogEntriesNavigationExtension(NavigationExtension):
"""
Extended navigation for blog entries.
It would be added to 'Blog' page properties in admin.
"""
name = _('all blog entries')
def children(self, page, **kwargs):
for entry in Entry.objects.all():
yield PagePretender(
title=entry.title,
url=reverse('blog_urls/blog_entry_details', kwargs={'object_id': entry.id}),
)
Page.register_extensions('navigation')
Page.register_extensions('sites')
try:
from mptt.models import MPTTModel as base
mptt_register = False
except ImportError:
base = models.Model
mptt_register = True
class Category(base):
name = models.CharField(max_length=20)
slug = models.SlugField()
parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
class Meta:
ordering = ['tree_id', 'lft']
verbose_name = 'category'
verbose_name_plural = 'categories'
def __unicode__(self):
return self.name
if mptt_register:
mptt.register(Category)
# add m2m field to entry so it shows up in entry admin
Entry.add_to_class('categories', models.ManyToManyField(Category, blank=True, null=True))
EntryAdmin.list_filter += ('categories',)