-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmodels.py
118 lines (79 loc) · 3 KB
/
models.py
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
from bakery.models import BuildableModel, AutoPublishingBuildableModel
import os
class BakeryModel(BuildableModel):
"""
An abstract class that can be mixedin to create a self building model.
Example:
# File: app/models.py
from wagtail.wagtailcore.pages import Page
from wagtail.wagtailbakery.models import BakeryModel
class AuthorPage(Page, BakeryModel):
bakery_views = ('app.bakery_views.AuthorPage',)
...
# File: app/bakery_views.py
from wagtail.wagtailbakery.views import BakeryView
from . import models
class AuthorPage(BakeryView):
bakery_model = models.AuthorPage
# File: project/settings.py
BUILD_DIR = os.path.join(PROJECT_ROOT, 'baked')
Note:
- Setting BAKERY_VIEWS is only required if using the "build" command.
"""
bakery_views = []
def build(self):
"""
Overrides BuildableModel's build() to prevent multiple runs
"""
bid = '%s:%s' % (self.__class__.__name__, self.id)
if not bid in self.__class__._already_built:
super(BakeryModel, self).build()
@property
def template_name(self):
return self.template
@property
def detail_views(self):
"""
Provides detail_views value for BuildableDetailView from
bakery_views. BakeryView intends to abstract away the
detail/list distinction because BuildableListView is not
needed for Wagtail Pages.
"""
return self.bakery_views
@classmethod
def init_build_checks(cls):
cls._already_built = []
class Meta:
abstract = True
BakeryModel._already_built = []
class PublishingBakeryModel(BakeryModel, AutoPublishingBuildableModel):
"""
An abstract class that can be mixedin to create a self building
and self publishing model which uses Celery to work in the background.
If only background building is needed then set the following in settings:
ALLOW_AUTO_BAKERY_PUBLISHING = False
Example:
# File: app/models.py
from wagtail.wagtailcore.pages import Page
from wagtail.wagtailbakery.models import PublishingBakeryModel
class AuthorPage(Page, PublishingBakeryModel):
bakery_views = ('app.bakery_views.AuthorPage',)
...
# File: app/bakery_views.py
from wagtail.wagtailbakery.views import BakeryView
from . import models
class AuthorPage(BakeryView):
bakery_model = models.AuthorPage
# File: project/settings.py
BUILD_DIR = os.path.join(PROJECT_ROOT, 'baked')
Note:
- Setting BAKERY_VIEWS is only required if using the "build" command.
- PublishingBakeryModel requires that Celery be installed and configured.
"""
def get_publication_status(self):
"""
Provides publication status to AutoPublishingBuildableModel
"""
return self.live
class Meta:
abstract = True