Last active
August 29, 2015 13:57
-
-
Save bmihelac/9543971 to your computer and use it in GitHub Desktop.
FeinCMSTemplatesDirective lists all templates / regions / content types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ... | |
import sys, os | |
sys.path.append(os.path.abspath('../website')) # add django project path | |
sys.path.append(os.path.abspath(os.path.dirname(__file__))) # add path where sphinx extension is stored | |
os.environ['DJANGO_SETTINGS_MODULE'] = 'website.settings' # django settings module | |
extensions = ["extensions.feincms"] | |
# ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# extensions/feincms.py | |
# −*− coding: UTF−8 −*− | |
from django.db import models | |
from docutils.parsers.rst import Directive | |
from docutils import nodes | |
class FeinCMSTemplatesDirective(Directive): | |
required_arguments = 1 | |
def run(self): | |
env = self.state.document.settings.env | |
app_label, model_name = self.arguments[0].strip().split(".", 1) | |
feincms_model = models.get_model(app_label, model_name) | |
res = [] | |
for key, template in feincms_model._feincms_templates.items(): | |
title_node = nodes.subtitle(text=template.title) | |
res.append(title_node) | |
for region in template.regions: | |
content_types_node = nodes.bullet_list() | |
for ct in region._content_types: | |
ct_node = nodes.literal(text=unicode(ct._meta.verbose_name)) | |
content_types_node += nodes.list_item("", ct_node) | |
list_item = nodes.definition_list_item( | |
"", | |
nodes.term(text=region.title), | |
nodes.definition("", content_types_node) | |
) | |
res.append(nodes.definition_list("", list_item)) | |
return res | |
def setup(app): | |
app.add_directive('feincmstemplates', FeinCMSTemplatesDirective) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
========= | |
Templates | |
========= | |
.. feincmstemplates:: page.Page |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment