forked from feincms/feincms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
126 lines (99 loc) · 3.4 KB
/
Copy pathmodels.py
File metadata and controls
126 lines (99 loc) · 3.4 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
from django import forms
from django.db import models
from django.utils.text import capfirst
from django.utils.translation import gettext_lazy as _
from mptt.models import MPTTModel
from feincms.content.application.models import ApplicationContent
from feincms.contents import RawContent, TemplateContent
from feincms.models import Base, create_base_model
from feincms.module.medialibrary.contents import MediaFileContent
from feincms.module.page import processors
from feincms.module.page.models import Page
from .content import CustomContentType
Page.register_templates(
{
"key": "base",
"title": "Base Template",
"path": "base.html",
"regions": (("main", "Main region"), ("sidebar", "Sidebar", "inherited")),
}
)
Page.create_content_type(RawContent)
Page.create_content_type(
MediaFileContent, TYPE_CHOICES=(("default", "Default position"),)
)
Page.create_content_type(
TemplateContent, TEMPLATES=[("templatecontent_1.html", "template 1")]
)
Page.register_request_processor(processors.etag_request_processor)
Page.register_response_processor(processors.etag_response_processor)
Page.register_response_processor(processors.debug_sql_queries_response_processor())
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."
),
),
"custom_field": forms.CharField(),
}
Page.create_content_type(
ApplicationContent,
APPLICATIONS=(
(
"whatever",
"Test Urls",
{
"admin_fields": get_admin_fields,
"urls": "testapp.applicationcontent_urls",
},
),
),
)
Page.register_extensions(
"feincms.module.page.extensions.navigation",
"feincms.module.page.extensions.sites",
"feincms.extensions.translations",
"feincms.extensions.datepublisher",
"feincms.extensions.translations",
"feincms.extensions.ct_tracker",
"feincms.extensions.seo",
"feincms.extensions.changedate",
"feincms.extensions.seo", # duplicate
"feincms.module.page.extensions.navigation",
"feincms.module.page.extensions.symlinks",
"feincms.module.page.extensions.titles",
"feincms.module.page.extensions.navigationgroups",
)
class Category(MPTTModel):
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")
)
class MyModel(create_base_model()):
pass
MyModel.register_regions(("main", "Main region"))
unchanged = CustomContentType
MyModel.create_content_type(CustomContentType)
assert CustomContentType is unchanged