Пример #1
0
def doc(item, field=None):
    """Gets the appropriate help text or docstring for a model or field.
    Accepts 1 or 2 string arguments:
    If 1, returns the docstring for the given model in the specified app.
    If 2, returns the help_text for the field on the given model in the specified app.
    """

    from aristotle_mdr.utils.doc_parse import parse_rst, parse_docstring

    ct = item
    if field is None:
        model_name = ct._meta.model_name
        title, body, metadata = parse_docstring(ct.__doc__)
        if title:
            title = parse_rst(title, 'model', _('model:') + model_name)
        if body:
            body = parse_rst(body, 'model', _('model:') + model_name)
        return title
    else:
        if ct._meta.get_field(field).help_text:
            return _(ct._meta.get_field(field).help_text)
        else:
            # return _("No help text for the field '%(field)s' found on the model '%(model)s' in the app '%(app)s'") % {'app':app_label,'model':model_name,'field':field}
            return _(
                "No help text for the field '%(field)s' found for the model '%(model)s'"
            ) % {
                'model': item.get_verbose_name(),
                'field': field
            }
Пример #2
0
def doc(item, field=None):
    """Gets the appropriate help text or docstring for a model or field.
    Accepts 1 or 2 string arguments:
    If 1, returns the docstring for the given model in the specified app.
    If 2, returns the help_text for the field on the given model in the specified app.
    """

    from django.contrib.contenttypes.models import ContentType
    from aristotle_mdr.utils.doc_parse import parse_rst, parse_docstring

    ct = item
    if field is None:
        model_name = ct._meta.model_name
        title, body, metadata = parse_docstring(ct.__doc__)
        if title:
            title = parse_rst(title, 'model', _('model:') + model_name)
        if body:
            body = parse_rst(body, 'model', _('model:') + model_name)
        return title
    else:
        if ct._meta.get_field(field).help_text:
            return _(ct._meta.get_field(field).help_text)
        else:
            # return _("No help text for the field '%(field)s' found on the model '%(model)s' in the app '%(app)s'") % {'app':app_label,'model':model_name,'field':field}
            return _("No help text for the field '%(field)s' found for the model '%(model)s'") % {'model': item.get_verbose_name(), 'field': field}