Ejemplo n.º 1
0
def build_doc_file(app_label):
    export_fields = get_data_export_fields(app_label)
    app_models_module = import_module('{}.models'.format(app_label))

    first_line = '{}: Field descriptions'.format(app_name_format(app_label))

    docs = ['{}\n{}\n\n'.format(first_line,
                                '*'*len(first_line))]

    doc_string_wrapper = TextWrapper(
        width=100,
        initial_indent='\t'*2,
        subsequent_indent='\t'*2
    )

    for model_name in MODEL_NAMES:
        if model_name == 'SessionParticipant':
            Model = ptree.session.models.SessionParticipant
        elif model_name == 'Session':
            Model = ptree.session.models.Session
        else:
            Model = getattr(app_models_module, model_name)
        im = InspectModel(Model)
        member_types = {
            'fields': im.fields,
            'methods': im.methods,
            # TODO: add properties, attributes, and others
        }

        docs.append('\n' + model_name)

        for member_name in export_fields[model_name]:

            if member_name in member_types['methods']:
                # check if it's a method
                member = getattr(Model, member_name)
                doc = inspect.getdoc(member)
            elif member_name in member_types['fields']:
                try:
                    member = Model._meta.get_field_by_name(member_name)[0]
                    doc = member.documentation
                except AttributeError:
                    # maybe the field isn't from ptree.db
                    doc = ''
            else:
                doc = '[not a field or method]'
            doc = doc or ''
            docs.append('\n\t' + member_name)
            if doc:
                docs.append('\n'.join(doc_string_wrapper.wrap(doc)))

    output = '\n'.join(docs)
    return output.replace('\n', LINE_BREAK).replace('\t', '    ')
Ejemplo n.º 2
0
def doc_file_name(app_label):
    return '{} -- field descriptions ({}).txt'.format(app_name_format(app_label),
                                                      )