Ejemplo n.º 1
0
def build_settings_docs(docs_path, prefix=None):
    """
    Converts names, descriptions and defaults for settings in 
    ``mezzanine.conf.registry`` into RST format for use in docs, 
    optionally filtered by setting names with the given prefix.
    """
    # String to use instead of setting value for dynamic defaults
    dynamic = "[dynamic]"
    lines = [".. THIS DOCUMENT IS AUTO GENERATED VIA conf.py"]
    for name in sorted(registry.keys()):
        if prefix and not name.startswith(prefix):
            continue
        setting = registry[name]
        settings_name = "``%s``" % name
        setting_default = setting["default"]
        if isinstance(setting_default, basestring):
            if gethostname() in setting_default or (
                    setting_default.startswith("/")
                    and os.path.exists(setting_default)):
                setting_default = dynamic
        if setting_default != dynamic:
            setting_default = repr(setting_default)
        lines.extend(["", settings_name, "-" * len(settings_name)])
        lines.extend(["", setting["description"]])
        lines.extend(["", "Default: ``%s``" % setting_default])
    with open(os.path.join(docs_path, "settings.rst"), "w") as f:
        f.write("\n".join(lines))
Ejemplo n.º 2
0
def build_settings_docs(docs_path, prefix=None):
    """
    Converts names, descriptions and defaults for settings in
    ``mezzanine.conf.registry`` into RST format for use in docs,
    optionally filtered by setting names with the given prefix.
    """
    # String to use instead of setting value for dynamic defaults
    dynamic = "[dynamic]"
    lines = [".. THIS DOCUMENT IS AUTO GENERATED VIA conf.py"]
    for name in sorted(registry.keys()):
        if prefix and not name.startswith(prefix):
            continue
        setting = registry[name]
        settings_name = "``%s``" % name
        setting_default = setting["default"]
        if isinstance(setting_default, str):
            if gethostname() in setting_default or (
                setting_default.startswith("/") and
                    os.path.exists(setting_default)):
                setting_default = dynamic
        if setting_default != dynamic:
            setting_default = repr(deep_force_unicode(setting_default))
        lines.extend(["", settings_name, "-" * len(settings_name)])
        lines.extend(["",
            urlize(setting["description"] or "").replace(
                "<a href=\"", "`").replace(
                "\" rel=\"nofollow\">", " <").replace(
                "</a>", ">`_")])
        if setting["choices"]:
            choices = ", ".join(["%s: ``%s``" % (str(v), force_text(k))
                                 for k, v in setting["choices"]])
            lines.extend(["", "Choices: %s" % choices, ""])
        lines.extend(["", "Default: ``%s``" % setting_default])
    with open(os.path.join(docs_path, "settings.rst"), "w") as f:
        f.write("\n".join(lines).replace("u'", "'").replace("yo'", "you'"))
Ejemplo n.º 3
0
 def __init__(self, *args, **kwargs):
     super(SettingsForm, self).__init__(*args, **kwargs)
     # Create a form field for each editable setting's from its type.
     active_language = get_language()
     for name in sorted(registry.keys()):
         setting = registry[name]
         if setting["editable"]:
             field_class = FIELD_TYPES.get(setting["type"], forms.CharField)
             if settings.USE_MODELTRANSLATION and setting["translatable"]:
                 for code in OrderedDict(settings.LANGUAGES):
                     try:
                         activate(code)
                     except:
                         pass
                     else:
                         self._init_field(
                             setting,
                             field_class,
                             name,
                             code,
                             active_language,
                         )
             else:
                 self._init_field(setting, field_class, name)
         activate(active_language)
Ejemplo n.º 4
0
def build_settings_docs(docs_path, prefix=None):
    """
    Converts names, descriptions and defaults for settings in
    ``mezzanine.conf.registry`` into RST format for use in docs,
    optionally filtered by setting names with the given prefix.
    """
    # String to use instead of setting value for dynamic defaults
    dynamic = "[dynamic]"
    lines = [".. THIS DOCUMENT IS AUTO GENERATED VIA conf.py"]
    for name in sorted(registry.keys()):
        if prefix and not name.startswith(prefix):
            continue
        setting = registry[name]
        settings_name = "``%s``" % name
        setting_default = setting["default"]
        if isinstance(setting_default, basestring):
            if gethostname() in setting_default or (
                setting_default.startswith("/") and
                os.path.exists(setting_default)):
                setting_default = dynamic
        if setting_default != dynamic:
            setting_default = repr(setting_default)
        lines.extend(["", settings_name, "-" * len(settings_name)])
        lines.extend(["", setting["description"]])
        lines.extend(["", "Default: ``%s``" % setting_default])
    with open(os.path.join(docs_path, "settings.rst"), "w") as f:
        f.write("\n".join(lines))
Ejemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     super(SettingsForm, self).__init__(*args, **kwargs)
     # Create a form field for each editable setting's from its type.
     active_language = get_language()
     for name in sorted(registry.keys()):
         setting = registry[name]
         if setting["editable"]:
             codes = [active_language]
             if settings.USE_MODELTRANSLATION and setting["translatable"]:
                 codes = SortedDict(settings.LANGUAGES)
             field_class = FIELD_TYPES.get(setting["type"], forms.CharField)
             for code in codes:
                 try:
                     activate(code)
                 except:
                     pass
                 else:
                     # refresh settings cache for each language to properly
                     # handle initial values.
                     settings.use_editable()
                     kwargs = {
                         "label": setting["label"] + ":",
                         "required": setting["type"] in (int, float),
                         "initial": getattr(settings, name),
                         "help_text":
                         self.format_help(setting["description"]),
                     }
                     if setting["choices"]:
                         field_class = forms.ChoiceField
                         kwargs["choices"] = setting["choices"]
                     field_instance = field_class(**kwargs)
                     self.fields[name + "/" + code] = field_instance
                     css_class = field_class.__name__.lower()
                     field_instance.widget.attrs["class"] = css_class
     activate(active_language)
Ejemplo n.º 6
0
 def __init__(self, *args, **kwargs):
     super(SettingsForm, self).__init__(*args, **kwargs)
     # Create a form field for each editable setting's from its type.
     active_language = get_language()
     for name in sorted(registry.keys()):
         setting = registry[name]
         if setting["editable"]:
             codes = [active_language]
             if settings.USE_MODELTRANSLATION and setting["translatable"]:
                 codes = SortedDict(settings.LANGUAGES)
             field_class = FIELD_TYPES.get(setting["type"], forms.CharField)
             for code in codes:
                 try:
                     activate(code)
                 except:
                     pass
                 else:
                     # refresh settings cache for each language to properly
                     # handle initial values.
                     settings.use_editable()
                     kwargs = {
                         "label": setting["label"] + ":",
                         "required": setting["type"] in (int, float),
                         "initial": getattr(settings, name),
                         "help_text":
                             self.format_help(setting["description"]),
                     }
                     if setting["choices"]:
                         field_class = forms.ChoiceField
                         kwargs["choices"] = setting["choices"]
                     field_instance = field_class(**kwargs)
                     self.fields[name + "/" + code] = field_instance
                     css_class = field_class.__name__.lower()
                     field_instance.widget.attrs["class"] = css_class
     activate(active_language)
Ejemplo n.º 7
0
 def __init__(self, *args, **kwargs):
     super(SettingsForm, self).__init__(*args, **kwargs)
     settings.use_editable()
     # Create a form field for each editable setting's from its type.
     for name in sorted(registry.keys()):
         setting = registry[name]
         if setting["editable"]:
             field_class = FIELD_TYPES.get(setting["type"], forms.CharField)
             self.fields[name] = field_class(label=name + ":",
                             required=False, initial=getattr(settings, name),
                             help_text=setting["description"])
Ejemplo n.º 8
0
 def __init__(self, *args, **kwargs):
     super(SettingsForm, self).__init__(*args, **kwargs)
     settings.use_editable()
     # Create a form field for each editable setting's from its type.
     for name in sorted(registry.keys()):
         setting = registry[name]
         if setting["editable"]:
             field_class = FIELD_TYPES.get(setting["type"], forms.CharField)
             self.fields[name] = field_class(
                 label=setting["label"] + ":",
                 required=False,
                 initial=getattr(settings, name),
                 help_text=setting["description"])
Ejemplo n.º 9
0
 def __init__(self, *args, **kwargs):
     super(SettingsForm, self).__init__(*args, **kwargs)
     # Create a form field for each editable setting's from its type.
     active_language = get_language()
     for name in sorted(registry.keys()):
         setting = registry[name]
         if setting["editable"]:
             field_class = FIELD_TYPES.get(setting["type"], forms.CharField)
             if settings.USE_MODELTRANSLATION and setting["translatable"]:
                 for code in OrderedDict(settings.LANGUAGES):
                     try:
                         activate(code)
                     except:
                         pass
                     else:
                         self._init_field(setting, field_class, name, code)
             else:
                 self._init_field(setting, field_class, name)
     activate(active_language)
Ejemplo n.º 10
0
 def __init__(self, *args, **kwargs):
     super(SettingsForm, self).__init__(*args, **kwargs)
     settings.use_editable()
     # Create a form field for each editable setting's from its type.
     for name in sorted(registry.keys()):
         setting = registry[name]
         if setting["editable"]:
             field_class = FIELD_TYPES.get(setting["type"], forms.CharField)
             kwargs = {
                 "label": setting["label"] + ":",
                 "required": setting["type"] == int,
                 "initial": getattr(settings, name),
                 "help_text": self.format_help(setting["description"]),
             }
             if setting["choices"]:
                 field_class = forms.ChoiceField
                 kwargs["choices"] = setting["choices"]
             self.fields[name] = field_class(**kwargs)
             css_class = field_class.__name__.lower()
             self.fields[name].widget.attrs["class"] = css_class
Ejemplo n.º 11
0
 def __init__(self, *args, **kwargs):
     super(SettingsForm, self).__init__(*args, **kwargs)
     settings.use_editable()
     # Create a form field for each editable setting's from its type.
     for name in sorted(registry.keys()):
         setting = registry[name]
         if setting["editable"]:
             field_class = FIELD_TYPES.get(setting["type"], forms.CharField)
             kwargs = {
                 "label": setting["label"] + ":",
                 "required": setting["type"] in (int, float),
                 "initial": getattr(settings, name),
                 "help_text": self.format_help(setting["description"]),
             }
             if setting["choices"]:
                 field_class = forms.ChoiceField
                 kwargs["choices"] = setting["choices"]
             self.fields[name] = field_class(**kwargs)
             css_class = field_class.__name__.lower()
             self.fields[name].widget.attrs["class"] = css_class
Ejemplo n.º 12
0
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
docs_path = os.path.abspath(os.path.dirname(__file__))
mezzanine_path = os.path.join(docs_path, "..")
sys.path.insert(0, mezzanine_path)
os.environ["DJANGO_SETTINGS_MODULE"] = "mezzanine.project_template.settings"
import mezzanine

# Generate the documentation for mezzanine.conf
from mezzanine.conf import registry

settings_docs = [".. THIS DOCUMENT IS AUTO GENERATED VIA conf.py"]
for name in sorted(registry.keys()):
    setting = registry[name]
    settings_name = "``%s``" % name
    setting_default = setting["default"]
    if isinstance(setting_default, basestring) and \
        setting_default.startswith("/") and \
        os.path.exists(setting_default):
        setting_default = "[dynamic]"
    else:
        setting_default = repr(setting_default)
    settings_docs.extend(["", settings_name, "-" * len(settings_name)])
    settings_docs.extend(["", setting["description"]])
    settings_docs.extend(["", "Default: ``%s``" % setting_default])
with open(os.path.join(docs_path, "settings.rst"), "w") as f:
    f.write("\n".join(settings_docs))