Django

Code

Changeset 913

Show
Ignore:
Timestamp:
10/17/05 14:03:16 (3 years ago)
Author:
rjwittams
Message:

Merged to r911

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/new-admin/django/conf/global_settings.py

    r881 r913  
    6666# documentation. 
    6767TEMPLATE_LOADERS = ( 
     68#     'django.core.template.loaders.app_directories.load_template_source', 
    6869    'django.core.template.loaders.filesystem.load_template_source', 
    6970#     'django.core.template.loaders.eggs.load_template_source', 
     
    110111# settings modules (in the format 'foo.bar.baz') for which this admin 
    111112# is an admin. 
    112 ADMIN_FOR = [] 
     113ADMIN_FOR = () 
    113114 
    114115# Whether to check the flat-pages table as a last resort for all 404 errors. 
  • django/branches/new-admin/django/conf/project_template/settings/main.py

    r881 r913  
    3131SECRET_KEY = '' 
    3232 
     33# List of callables that know how to import templates from various sources. 
     34TEMPLATE_LOADERS = ( 
     35#     'django.core.template.loaders.app_directories.load_template_source', 
     36    'django.core.template.loaders.filesystem.load_template_source', 
     37#     'django.core.template.loaders.eggs.load_template_source', 
     38) 
     39 
    3340MIDDLEWARE_CLASSES = ( 
    3441    "django.middleware.common.CommonMiddleware", 
  • django/branches/new-admin/django/core/template/loaders/app_directories.py

    r892 r913  
    2222        filepath = os.path.join(template_dir, template_name) + TEMPLATE_FILE_EXTENSION 
    2323        try: 
    24             return open(filepath).read(
     24            return (open(filepath).read(), filepath
    2525        except IOError: 
    2626            pass 
  • django/branches/new-admin/django/core/template/loaders/eggs.py

    r876 r913  
    99from django.conf.settings import INSTALLED_APPS, TEMPLATE_FILE_EXTENSION 
    1010 
    11 def load_template_source(name, dirs=None): 
     11def load_template_source(template_name, template_dirs=None): 
    1212    """ 
    1313    Loads templates from Python eggs via pkg_resource.resource_string. 
    1414 
    15     For every installed app, it tries to get the resource (app, name). 
     15    For every installed app, it tries to get the resource (app, template_name). 
    1616    """ 
    1717    if resource_string is not None: 
    18         pkg_name = 'templates/' + name + TEMPLATE_FILE_EXTENSION 
     18        pkg_name = 'templates/' + template_name + TEMPLATE_FILE_EXTENSION 
    1919        for app in INSTALLED_APPS: 
    2020            try: 
     
    2222            except: 
    2323                pass 
    24     raise TemplateDoesNotExist, name 
     24    raise TemplateDoesNotExist, template_name 
    2525load_template_source.is_usable = resource_string is not None 
  • django/branches/new-admin/django/core/template/loaders/filesystem.py

    r876 r913  
    1818        error_msg = "Tried %s" % tried 
    1919    else: 
    20         error_msg = "Your TEMPLATE_DIRS settings is empty. Change it to point to at least one template directory." 
     20        error_msg = "Your TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory." 
    2121    raise TemplateDoesNotExist, error_msg 
    2222load_template_source.is_usable = True 
  • django/branches/new-admin/django/views/defaults.py

    r876 r913  
    1111    except ObjectDoesNotExist: 
    1212        raise Http404, "Content type %s object %s doesn't exist" % (content_type_id, object_id) 
    13     if not hasattr(obj, 'get_absolute_url'): 
     13    try: 
     14        absurl = obj.get_absolute_url() 
     15    except AttributeError: 
    1416        raise Http404, "%s objects don't have get_absolute_url() methods" % content_type.name 
     17    if absurl.startswith('http://'): 
     18        return httpwrappers.HttpResponseRedirect(absurl) 
    1519    object_domain = None 
    1620    if hasattr(obj, 'get_site_list'): 
     
    2832        pass 
    2933    if not object_domain: 
    30         return httpwrappers.HttpResponseRedirect(obj.get_absolute_url()
    31     return httpwrappers.HttpResponseRedirect('http://%s%s' % (object_domain, obj.get_absolute_url())) 
     34        return httpwrappers.HttpResponseRedirect(absurl
     35    return httpwrappers.HttpResponseRedirect('http://%s%s' % (object_domain, absurl)) 
    3236 
    3337def page_not_found(request): 
  • django/branches/new-admin/docs/design_philosophies.txt

    r864 r913  
    243243A view shouldn't care about which template system the developer uses -- or even 
    244244whether a template system is used at all. 
     245 
     246Designate between GET and POST 
     247------------------------------ 
     248 
     249GET and POST are distinct; developers should explicitly use one or the other. 
     250The framework should make it easy to distinguish between GET and POST data. 
  • django/branches/new-admin/docs/django-admin.txt

    r803 r913  
    113113Just execute ``django-admin.py runserver`` more than once. 
    114114 
     115Note that the default IP address, 127.0.0.1, is not accessible from other 
     116machines on your network. To make your development server viewable to other 
     117machines on the network, use its own IP address (e.g. ``192.168.2.1``) or 
     118``0.0.0.0``. 
     119 
    115120Examples: 
    116121~~~~~~~~~ 
  • django/branches/new-admin/docs/model-api.txt

    r854 r913  
    253253    steps: 
    254254 
    255         1. In your settings file, you'll need to define ``MEDIA_ROOT``as the 
     255        1. In your settings file, you'll need to define ``MEDIA_ROOT`` as the 
    256256           full path to a directory where you'd like Django to store uploaded 
    257257           files. (For performance, these files are not stored in the database.) 
  • django/branches/new-admin/docs/templates_python.txt

    r876 r913  
    288288".html" extension in a directory specified as a **template directory**. 
    289289 
    290 (The ".html" extension is just a required convention. It doesn't mean templates 
    291 can only contain HTML. They can contain whatever textual content you want.) 
     290If you don't like the requirement that templates have an ".html" extension, 
     291change your ``TEMPLATE_FILE_EXTENSION`` setting. It's set to ``".html"`` by 
     292default. 
     293 
     294Also, the .html extension doesn't mean templates can contain only HTML. They 
     295can contain whatever textual content you want. 
    292296 
    293297The TEMPLATE_DIRS setting 
     
    355359 
    356360    get_template("news/story_detail") 
     361 
     362Loader types 
     363~~~~~~~~~~~~ 
     364 
     365By default, Django uses a filesystem-based template loader, but Django comes 
     366with a few other template loaders. They're disabled by default, but you can 
     367activate them by editing your ``TEMPLATE_LOADERS`` setting. 
     368``TEMPLATE_LOADERS`` should be a tuple of strings, where each string represents 
     369a template loader. Here are the built-in template loaders: 
     370 
     371``django.core.template.loaders.filesystem.load_template_source`` 
     372    Loads templates from the filesystem, according to ``TEMPLATE_DIRS``. 
     373 
     374``django.core.template.loaders.app_directories.load_template_source`` 
     375    Loads templates from Django apps on the filesystem. For each app in 
     376    ``INSTALLED_APPS``, the loader looks for a ``templates`` subdirectory. If 
     377    the directory exists, Django looks for templates in there. 
     378 
     379    This means you can store templates with your individual apps. This also 
     380    makes it easy to distribute Django apps with default templates. 
     381 
     382    For example, for this setting:: 
     383 
     384        INSTALLED_APPS = ('myproject.polls', 'myproject.music') 
     385 
     386    ...then ``get_template("foo")`` will look for templates in these 
     387    directories, in this order: 
     388 
     389        * ``/path/to/myproject/polls/templates/foo.html`` 
     390        * ``/path/to/myproject/music/templates/music.html`` 
     391 
     392    Note that the loader performs an optimization when it is first imported: 
     393    It caches a list of which ``INSTALLED_APPS`` packages have a ``templates`` 
     394    subdirectory. 
     395 
     396``django.core.template.loaders.eggs.load_template_source`` 
     397    Just like ``app_directories`` above, but it loads templates from Python 
     398    eggs rather than from the filesystem. 
     399 
     400Django uses the template loaders in order according to the ``TEMPLATE_LOADERS`` 
     401setting. It uses each loader until a loader finds a match. 
    357402 
    358403Extending the template system 
  • django/branches/new-admin/docs/templates.txt

    r864 r913  
    224224      if you want to add to the contents of a parent block instead of 
    225225      completely overriding it. 
     226 
     227Finally, note that you can't define multiple ``{% block %}`` tags with the same 
     228name in the same template. This limitation exists because a block tag works in 
     229"both" directions. That is, a block tag doesn't just provide a hole to fill -- 
     230it also defines the content that fills the hole in the *parent*. If there were 
     231two similarly-named ``{% block %}`` tags in a template, that template's parent 
     232wouldn't know which one of the blocks' content to use. 
    226233 
    227234Using the built-in reference 
     
    393400 
    394401        {% if athlete_list %} 
    395             Number of athletes: {{ athlete_list|count }} 
     402            Number of athletes: {{ athlete_list|length }} 
    396403        {% else %} 
    397404            No athletes. 
     
    399406 
    400407    In the above, if ``athlete_list`` is not empty, the number of athletes will be 
    401     displayed by the ``{{ athlete_list|count }}`` variable. 
     408    displayed by the ``{{ athlete_list|length }}`` variable. 
    402409 
    403410    As you can see, the ``if`` tag can take an option ``{% else %}`` clause that 
     
    426433        {% if athlete_list %} 
    427434            {% if coach_list %} 
    428                 Number of athletes: {{ athlete_list|count }}. 
    429                 Number of coaches: {{ coach_list|count }}. 
     435                Number of athletes: {{ athlete_list|length }}. 
     436                Number of coaches: {{ coach_list|length }}. 
    430437            {% endif %} 
    431438        {% endif %}