Revision 719d8d08
b/cloudcms/cms_utils.py | ||
---|---|---|
1 |
from feincms.content.application.models import ApplicationContent |
|
2 |
|
|
3 |
def get_app_page(model, urlconf_path): |
|
4 |
""" |
|
5 |
Returns the model entry that has been associated with the application that |
|
6 |
provides the passed urlconf_path. |
|
7 |
|
|
8 |
e.g. to retrieve the page associated with |
|
9 |
|
|
10 |
>>> page = get_app_page(Page, 'cloudcmsblog') |
|
11 |
>>> print page.get_navigation_url() |
|
12 |
>>> "/blog/" |
|
13 |
|
|
14 |
""" |
|
15 |
app_content_type = model.content_type_for(ApplicationContent) |
|
16 |
try: |
|
17 |
blog_block = app_content_type.objects.filter(urlconf_path="cloudcmsblog")[0] |
|
18 |
except: |
|
19 |
return None |
|
20 |
return blog_block.parent |
|
21 |
|
b/cloudcmsblog/models.py | ||
---|---|---|
54 | 54 |
from feincms.content.application.models import ApplicationContent |
55 | 55 |
|
56 | 56 |
from cloudcms.models import Application |
57 |
from cloudcms.cms_utils import get_app_page |
|
57 | 58 |
|
58 | 59 |
# monkeypatch django reverse (feincms 1.5+ solves this issue) |
59 | 60 |
urlresolvers.reverse = reverse |
... | ... | |
114 | 115 |
def latest(self, limit=3): |
115 | 116 |
return self.filter()[:limit] |
116 | 117 |
|
118 |
|
|
119 |
def get_blog_page(): |
|
120 |
""" |
|
121 |
Returns Page model that has been associated with blog application |
|
122 |
""" |
|
123 |
return get_app_page(Page, "cloudcmsblog") |
|
124 |
|
|
117 | 125 |
class Entry(Base): |
118 | 126 |
""" |
119 | 127 |
Blog post entry |
... | ... | |
166 | 174 |
# ugly hack to fix proper application reverse url |
167 | 175 |
BLOG_URL = "" |
168 | 176 |
try: |
169 |
AC = Page.content_type_for(ApplicationContent) |
|
170 |
blog_block = AC.objects.filter(urlconf_path="cloudcmsblog")[0] |
|
171 |
BLOG_URL = blog_block.parent.get_navigation_url() |
|
177 |
BLOG_URL = get_blog_page().get_navigation_url() |
|
172 | 178 |
except Exception, e: |
173 | 179 |
print e |
174 | 180 |
if r.startswith(BLOG_URL): |
... | ... | |
177 | 183 |
return BLOG_URL + r |
178 | 184 |
|
179 | 185 |
def back_url(self): |
180 |
AC = Page.content_type_for(ApplicationContent) |
|
181 |
blog_block = AC.objects.filter(urlconf_path="cloudcmsblog")[0] |
|
182 |
BLOG_URL = blog_block.parent.get_navigation_url() |
|
183 |
return BLOG_URL |
|
186 |
return get_blog_page().get_navigation_url() |
|
184 | 187 |
|
185 | 188 |
|
186 | 189 |
# Feincms navigation extension |
Also available in: Unified diff