Django

Code

Changeset 3027

Show
Ignore:
Timestamp:
05/31/06 13:44:14 (2 years ago)
Author:
adrian
Message:

Got django_website.apps.docs.parts.build_documentation working

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • djangoproject.com/django_website/apps/docs/parts/build_documentation.py

    r3025 r3027  
    99from django.conf import settings 
    1010from django import template 
    11 from django.db import models 
     11from django.db.models import get_app, get_models 
    1212from docutils import nodes, utils 
    1313from docutils.core import publish_parts 
     
    7474    import runtests 
    7575 
    76     # Manually set INSTALLED_APPS to point to the test app. 
    77     settings.INSTALLED_APPS = (runtests.APP_NAME,) 
     76    # An empty access of the settings to force the default options to be 
     77    # installed prior to assigning to them. 
     78    settings.INSTALLED_APPS 
     79 
     80    # Manually set INSTALLED_APPS to point to the test models. 
     81    settings.INSTALLED_APPS = runtests.ALWAYS_INSTALLED_APPS + [runtests.MODEL_TESTS_DIR_NAME + '.' + a for a in runtests.get_test_models()] 
    7882 
    7983    # Some of the test models need to know whether the docs are being built. 
     
    8185 
    8286    for model_name in runtests.get_test_models(): 
    83         mod = models.get_app(model_name) 
     87        mod = get_app(model_name) 
    8488 
    8589        out_file = os.path.join(settings.DJANGO_DOCUMENT_ROOT_PATH, 'model_' + model_name + '.html') 
     
    8791 
    8892        # Clean up the title and blurb. 
    89         title, blurb = mod.__doc__.strip().split('\n', 1) 
     93        try: 
     94            title, blurb = mod.__doc__.strip().split('\n', 1) 
     95        except ValueError: 
     96            sys.stderr.write("title and blurb not found in %s model test.\n" % model_name) 
     97            continue 
    9098        parts = publish_parts( 
    9199            blurb, 
     
    96104        ) 
    97105        blurb = parts["html_body"] 
    98         api_usage = mod.API_TESTS 
     106        try: 
     107            api_usage = mod.API_TESTS 
     108        except AttributeError: 
     109            continue # This model didn't have API_TESTS. 
    99110 
    100111        # Get the source code of the model, without the docstring or the 
     
    108119 
    109120        models = [] 
    110         for m in mod._MODELS
     121        for m in get_models(mod)
    111122            models.append({ 
    112123                'name': m._meta.object_name, 
     
    123134            fp = open(out_file, 'w') 
    124135        except IOError: 
    125             sys.stderr.write("Couldn't write to %s.\n" % file_name) 
     136            sys.stderr.write("Couldn't write to %s.\n" % out_file) 
    126137            continue 
    127138        else: 
     
    132143            fp = open(toc_file, 'w') 
    133144        except IOError: 
    134             sys.stderr.write("Couldn't write to %s.\n" % file_name) 
     145            sys.stderr.write("Couldn't write to %s.\n" % toc_file) 
    135146            continue 
    136147        else: