Django

Code

Changeset 1166

Show
Ignore:
Timestamp:
11/10/05 22:45:05 (3 years ago)
Author:
adrian
Message:

BACKWARDS-INCOMPATIBLE CHANGE -- Moved flatpages and redirects to standalone apps in django.contrib that are NOT installed by default. See http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges for full migration information.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/conf/global_settings.py

    r1156 r1166  
    136136ADMIN_FOR = () 
    137137 
    138 # Whether to check the flat-pages table as a last resort for all 404 errors. 
    139 USE_FLAT_PAGES = True 
    140  
    141138# 404s that may be ignored. 
    142139IGNORABLE_404_STARTS = ('/cgi-bin/', '/_vti_bin', '/_vti_inf') 
  • django/trunk/django/contrib/flatpages/urls.py

    r3 r1166  
    22 
    33urlpatterns = patterns('django.views', 
    4     (r'^(?P<url>.*)$', 'core.flatfiles.flat_file'), 
     4    (r'^(?P<url>.*)$', 'django.contrib.flatpages.views.flatpage'), 
    55) 
  • django/trunk/django/middleware/common.py

    r1096 r1166  
    11from django.conf import settings 
    2 from django.core import exceptions 
    32from django.utils import httpwrappers 
    43from django.core.mail import mail_managers 
    5 from django.views.core.flatfiles import flat_file 
    64import md5, os 
    75 
     
    1816          the entire page content and Not Modified responses will be returned 
    1917          appropriately. 
    20  
    21         - Flat files: For 404 responses, a flat file matching the given path 
    22           will be looked up and used if found. 
    2318    """ 
    2419 
     
    5651        "Check for a flat page (for 404s) and calculate the Etag, if needed." 
    5752        if response.status_code == 404: 
    58             if settings.USE_FLAT_PAGES: 
    59                 try: 
    60                     return flat_file(request, request.path) 
    61                 except exceptions.Http404: 
    62                     pass 
    63  
    6453            if settings.SEND_BROKEN_LINK_EMAILS: 
    6554                # If the referrer was from an internal link or a non-search-engine site, 
  • django/trunk/django/models/core.py

    r1150 r1166  
    11import base64, md5, random, sys 
    22import cPickle as pickle 
    3 from django.core import meta, validators 
     3from django.core import meta 
    44from django.utils.translation import gettext_lazy as _ 
    55 
     
    6464        return self.get_model_module().get_object(**kwargs) 
    6565 
    66 class Redirect(meta.Model): 
    67     site = meta.ForeignKey(Site, radio_admin=meta.VERTICAL) 
    68     old_path = meta.CharField(_('redirect from'), maxlength=200, db_index=True, 
    69         help_text=_("This should be an absolute path, excluding the domain name. Example: '/events/search/'.")) 
    70     new_path = meta.CharField(_('redirect to'), maxlength=200, blank=True, 
    71         help_text=_("This can be either an absolute path (as above) or a full URL starting with 'http://'.")) 
    72     class META: 
    73         verbose_name = _('redirect') 
    74         verbose_name_plural = _('redirects') 
    75         db_table = 'redirects' 
    76         unique_together=(('site', 'old_path'),) 
    77         ordering = ('old_path',) 
    78         admin = meta.Admin( 
    79             list_filter = ('site',), 
    80             search_fields = ('old_path', 'new_path'), 
    81         ) 
    82  
    83     def __repr__(self): 
    84         return "%s ---> %s" % (self.old_path, self.new_path) 
    85  
    86 class FlatFile(meta.Model): 
    87     url = meta.CharField(_('URL'), maxlength=100, validator_list=[validators.isAlphaNumericURL], 
    88         help_text=_("Example: '/about/contact/'. Make sure to have leading and trailing slashes.")) 
    89     title = meta.CharField(_('title'), maxlength=200) 
    90     content = meta.TextField(_('content')) 
    91     enable_comments = meta.BooleanField(_('enable comments')) 
    92     template_name = meta.CharField(_('template name'), maxlength=70, blank=True, 
    93         help_text=_("Example: 'flatfiles/contact_page'. If this isn't provided, the system will use 'flatfiles/default'.")) 
    94     registration_required = meta.BooleanField(_('registration required'), help_text=_("If this is checked, only logged-in users will be able to view the page.")) 
    95     sites = meta.ManyToManyField(Site) 
    96     class META: 
    97         db_table = 'flatfiles' 
    98         verbose_name = _('flat page') 
    99         verbose_name_plural = _('flat pages') 
    100         ordering = ('url',) 
    101         admin = meta.Admin( 
    102             fields = ( 
    103                 (None, {'fields': ('url', 'title', 'content', 'sites')}), 
    104                 ('Advanced options', {'classes': 'collapse', 'fields': ('enable_comments', 'registration_required', 'template_name')}), 
    105             ), 
    106             list_filter = ('sites',), 
    107             search_fields = ('url', 'title'), 
    108         ) 
    109  
    110     def __repr__(self): 
    111         return "%s -- %s" % (self.url, self.title) 
    112  
    113     def get_absolute_url(self): 
    114         return self.url 
    115  
    11666class Session(meta.Model): 
    11767    session_key = meta.CharField(_('session key'), maxlength=40, primary_key=True) 
  • django/trunk/django/views/defaults.py

    r1012 r1166  
    55 
    66def shortcut(request, content_type_id, object_id): 
    7     """Redirect to an object's page based on a content-type ID and an object ID""
     7    "Redirect to an object's page based on a content-type ID and an object ID.
    88    # Look up the object, making sure it's got a get_absolute_url() function. 
    99    try: 
     
    1616    except AttributeError: 
    1717        raise Http404, "%s objects don't have get_absolute_url() methods" % content_type.name 
    18      
    19     # Try to figure out the object's domain so we can do a cross-site redirect 
    20     # if necessary 
     18 
     19    # Try to figure out the object's domain, so we can do a cross-site redirect 
     20    # if necessary. 
    2121 
    2222    # If the object actually defines a domain, we're done. 
     
    2525 
    2626    object_domain = None 
    27      
     27 
    2828    # Next, look for an many-to-many relationship to sites 
    2929    if hasattr(obj, 'get_site_list'): 
     
    3131        if site_list: 
    3232            object_domain = site_list[0].domain 
    33     
    34     # Next, look for a many-to-one relationship to sites  
     33 
     34    # Next, look for a many-to-one relationship to sites 
    3535    elif hasattr(obj, 'get_site'): 
    3636        try: 
     
    5656    Context: None 
    5757    """ 
    58     from django.models.core import redirects 
    59     from django.conf.settings import APPEND_SLASH, SITE_ID 
    60     path = request.get_full_path() 
    61     try: 
    62         r = redirects.get_object(site__id__exact=SITE_ID, old_path__exact=path) 
    63     except redirects.RedirectDoesNotExist: 
    64         r = None 
    65     if r is None and APPEND_SLASH: 
    66         # Try removing the trailing slash. 
    67         try: 
    68             r = redirects.get_object(site__id__exact=SITE_ID, old_path__exact=path[:path.rfind('/')]+path[path.rfind('/')+1:]) 
    69         except redirects.RedirectDoesNotExist: 
    70             pass 
    71     if r is not None: 
    72         if r == '': 
    73             return httpwrappers.HttpResponseGone() 
    74         return httpwrappers.HttpResponseRedirect(r.new_path) 
    7558    t = loader.get_template('404') 
    76     c = Context() 
    77     return httpwrappers.HttpResponseNotFound(t.render(c)) 
     59    return httpwrappers.HttpResponseNotFound(t.render(Context())) 
    7860 
    7961def server_error(request): 
    8062    """ 
    81     500 Error handler 
     63    500 error handler. 
    8264 
    8365    Templates: `500` 
     
    8567    """ 
    8668    t = loader.get_template('500') 
    87     c = Context() 
    88     return httpwrappers.HttpResponseServerError(t.render(c)) 
     69    return httpwrappers.HttpResponseServerError(t.render(Context())) 
  • django/trunk/docs/legacy_databases.txt

    r1054 r1166  
    7070    * ``packages`` 
    7171    * ``content_types`` 
    72     * ``redirects`` 
    73     * ``flatfiles`` 
    7472    * ``core_sessions`` 
    75     * ``flatfiles_sites`` 
    7673    * ``auth_permissions`` 
    7774    * ``auth_groups`` 
  • django/trunk/docs/middleware.txt

    r1162 r1166  
    7272  MD5-hashing the page content, and it'll take care of sending 
    7373  ``Not Modified`` responses, if appropriate. 
    74  
    75 * Handles flat pages. Every time Django encounters a 404 -- either within 
    76   a view or as a result of no URLconfs matching -- it will check the 
    77   database of flat pages based on the current URL. 
    7874 
    7975django.middleware.doc.XViewMiddleware 
  • django/trunk/docs/model-api.txt

    r1108 r1166  
    832832            given extra horizontal space. 
    833833 
    834     For example (taken from the ``core.flatfiles`` model):: 
     834    For example (taken from the ``django.contrib.flatpages`` model):: 
    835835 
    836836        fields = ( 
  • django/trunk/docs/settings.txt

    r1165 r1166  
    563563is installed (see the `middleware docs`_). 
    564564 
    565 USE_FLAT_PAGES 
    566 -------------- 
    567  
    568 Default: ``True`` 
    569  
    570 Whether to check the flat-pages table as a last resort for all 404 errors. This 
    571 is only used if ``CommonMiddleware`` is installed (see the `middleware docs`_). 
    572  
    573565.. _cache docs: http://www.djangoproject.com/documentation/cache/ 
    574566.. _middleware docs: http://www.djangoproject.com/documentation/middleware/ 
  • django/trunk/docs/url_dispatch.txt

    r704 r1166  
    5757        (r'^comments/',      include('django.contrib.comments.urls.comments')), 
    5858        (r'^rss/',           include('django.conf.urls.rss')), 
    59         (r'',                include('django.conf.urls.flatfiles')), 
    6059    ) 
    6160