-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmodels.py
More file actions
147 lines (119 loc) · 4.07 KB
/
Copy pathmodels.py
File metadata and controls
147 lines (119 loc) · 4.07 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from content_editor.models import Region, create_plugin_base
from django.db import models
from django.utils.translation import gettext_lazy as _, override
from feincms3.applications import (
ApplicationType,
PageTypeMixin,
TemplateType,
reverse_app,
)
from feincms3.mixins import LanguageAndTranslationOfMixin, MenuMixin, RedirectMixin
from feincms3.pages import AbstractPage
from feincms3.plugins import external, html, image, richtext, snippet
class Page(
# Add this first so that AbstractPage.Meta's properties are active:
AbstractPage,
# For adding the articles app to pages through the CMS:
PageTypeMixin,
# We have a main and a footer navigation (meta):
MenuMixin,
# We're building a multilingual CMS. (Also, feincms3.applications depends on
# LanguageMixin currently):
LanguageAndTranslationOfMixin,
# Allow redirecting pages to other pages and/or arbitrary URLs:
RedirectMixin,
):
# MenuMixin
MENUS = [("main", _("main")), ("footer", _("footer"))]
# PageTypeMixin. We have two templates and four apps.
TYPES = [
TemplateType(
key="standard",
title=_("standard"),
template_name="pages/standard.html",
regions=[Region(key="main", title=_("Main"))],
),
TemplateType(
key="with-sidebar",
title=_("with sidebar"),
template_name="pages/with-sidebar.html",
regions=[
Region(key="main", title=_("Main")),
Region(key="sidebar", title=_("Sidebar")),
],
),
ApplicationType(
key="publications",
title=_("publications"),
urlconf="testapp.articles_urls",
),
ApplicationType(
key="blog",
title=_("blog"),
urlconf="testapp.articles_urls",
),
ApplicationType(
key="importable_module",
title="importable_module",
urlconf="importable_module",
required_fields=("optional", "not_editable"),
),
ApplicationType(
key="translated-articles",
title=_("translated articles"),
urlconf="testapp.translated_articles_urls",
),
ApplicationType(
key="imprint",
title="imprint",
urlconf="feincms3.root.passthru",
template_name="pages/standard.html",
regions=[Region(key="main", title=_("Main"))],
),
]
optional = models.IntegerField(blank=True, null=True)
not_editable = models.IntegerField(blank=True, null=True, editable=False)
class Meta(AbstractPage.Meta):
unique_together = [("language_code", "translation_of")]
PagePlugin = create_plugin_base(Page)
class RichText(richtext.RichText, PagePlugin):
pass
class Image(image.Image, PagePlugin):
pass
class Snippet(snippet.Snippet, PagePlugin):
TEMPLATES = [
(
"snippet.html",
_("snippet"),
lambda plugin, context: {"plugin": plugin, "additional": "context"},
)
]
class External(external.External, PagePlugin):
pass
class HTML(html.HTML, PagePlugin):
pass
class Article(models.Model):
title = models.CharField(_("title"), max_length=200)
category = models.CharField(
_("category"),
max_length=100,
choices=(("publications", "publications"), ("blog", "blog")),
)
class Meta:
ordering = ["-pk"]
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse_app(
(self.category, "articles"), "article-detail", kwargs={"pk": self.pk}
)
class TranslatedArticle(LanguageAndTranslationOfMixin):
title = models.CharField(_("title"), max_length=200)
class Meta:
ordering = ["-pk"]
unique_together = [("language_code", "translation_of")]
def __str__(self):
return self.title
def get_absolute_url(self):
with override(self.language_code):
return reverse_app("translated-articles", "detail", kwargs={"pk": self.pk})