Changeset 1166
- Timestamp:
- 11/10/05 22:45:05 (3 years ago)
- Files:
-
- django/trunk/django/conf/global_settings.py (modified) (1 diff)
- django/trunk/django/contrib/flatpages (added)
- django/trunk/django/contrib/flatpages/__init__.py (added)
- django/trunk/django/contrib/flatpages/middleware.py (added)
- django/trunk/django/contrib/flatpages/models (added)
- django/trunk/django/contrib/flatpages/models/flatpages.py (added)
- django/trunk/django/contrib/flatpages/models/__init__.py (added)
- django/trunk/django/contrib/flatpages/urls.py (moved) (moved from django/trunk/django/conf/urls/flatfiles.py) (1 diff)
- django/trunk/django/contrib/flatpages/views.py (added)
- django/trunk/django/contrib/redirects (added)
- django/trunk/django/contrib/redirects/__init__.py (added)
- django/trunk/django/contrib/redirects/middleware.py (added)
- django/trunk/django/contrib/redirects/models (added)
- django/trunk/django/contrib/redirects/models/__init__.py (added)
- django/trunk/django/contrib/redirects/models/redirects.py (added)
- django/trunk/django/middleware/common.py (modified) (3 diffs)
- django/trunk/django/models/core.py (modified) (2 diffs)
- django/trunk/django/views/core/flatfiles.py (deleted)
- django/trunk/django/views/defaults.py (modified) (6 diffs)
- django/trunk/docs/flatpages.txt (added)
- django/trunk/docs/legacy_databases.txt (modified) (1 diff)
- django/trunk/docs/middleware.txt (modified) (1 diff)
- django/trunk/docs/model-api.txt (modified) (1 diff)
- django/trunk/docs/redirects.txt (added)
- django/trunk/docs/settings.txt (modified) (1 diff)
- django/trunk/docs/url_dispatch.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/conf/global_settings.py
r1156 r1166 136 136 ADMIN_FOR = () 137 137 138 # Whether to check the flat-pages table as a last resort for all 404 errors.139 USE_FLAT_PAGES = True140 141 138 # 404s that may be ignored. 142 139 IGNORABLE_404_STARTS = ('/cgi-bin/', '/_vti_bin', '/_vti_inf') django/trunk/django/contrib/flatpages/urls.py
r3 r1166 2 2 3 3 urlpatterns = patterns('django.views', 4 (r'^(?P<url>.*)$', ' core.flatfiles.flat_file'),4 (r'^(?P<url>.*)$', 'django.contrib.flatpages.views.flatpage'), 5 5 ) django/trunk/django/middleware/common.py
r1096 r1166 1 1 from django.conf import settings 2 from django.core import exceptions3 2 from django.utils import httpwrappers 4 3 from django.core.mail import mail_managers 5 from django.views.core.flatfiles import flat_file6 4 import md5, os 7 5 … … 18 16 the entire page content and Not Modified responses will be returned 19 17 appropriately. 20 21 - Flat files: For 404 responses, a flat file matching the given path22 will be looked up and used if found.23 18 """ 24 19 … … 56 51 "Check for a flat page (for 404s) and calculate the Etag, if needed." 57 52 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 pass63 64 53 if settings.SEND_BROKEN_LINK_EMAILS: 65 54 # If the referrer was from an internal link or a non-search-engine site, django/trunk/django/models/core.py
r1150 r1166 1 1 import base64, md5, random, sys 2 2 import cPickle as pickle 3 from django.core import meta , validators3 from django.core import meta 4 4 from django.utils.translation import gettext_lazy as _ 5 5 … … 64 64 return self.get_model_module().get_object(**kwargs) 65 65 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.url115 116 66 class Session(meta.Model): 117 67 session_key = meta.CharField(_('session key'), maxlength=40, primary_key=True) django/trunk/django/views/defaults.py
r1012 r1166 5 5 6 6 def 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." 8 8 # Look up the object, making sure it's got a get_absolute_url() function. 9 9 try: … … 16 16 except AttributeError: 17 17 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 redirect20 # if necessary 18 19 # Try to figure out the object's domain, so we can do a cross-site redirect 20 # if necessary. 21 21 22 22 # If the object actually defines a domain, we're done. … … 25 25 26 26 object_domain = None 27 27 28 28 # Next, look for an many-to-many relationship to sites 29 29 if hasattr(obj, 'get_site_list'): … … 31 31 if site_list: 32 32 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 35 35 elif hasattr(obj, 'get_site'): 36 36 try: … … 56 56 Context: None 57 57 """ 58 from django.models.core import redirects59 from django.conf.settings import APPEND_SLASH, SITE_ID60 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 = None65 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 pass71 if r is not None:72 if r == '':73 return httpwrappers.HttpResponseGone()74 return httpwrappers.HttpResponseRedirect(r.new_path)75 58 t = loader.get_template('404') 76 c = Context() 77 return httpwrappers.HttpResponseNotFound(t.render(c)) 59 return httpwrappers.HttpResponseNotFound(t.render(Context())) 78 60 79 61 def server_error(request): 80 62 """ 81 500 Error handler63 500 error handler. 82 64 83 65 Templates: `500` … … 85 67 """ 86 68 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 70 70 * ``packages`` 71 71 * ``content_types`` 72 * ``redirects``73 * ``flatfiles``74 72 * ``core_sessions`` 75 * ``flatfiles_sites``76 73 * ``auth_permissions`` 77 74 * ``auth_groups`` django/trunk/docs/middleware.txt
r1162 r1166 72 72 MD5-hashing the page content, and it'll take care of sending 73 73 ``Not Modified`` responses, if appropriate. 74 75 * Handles flat pages. Every time Django encounters a 404 -- either within76 a view or as a result of no URLconfs matching -- it will check the77 database of flat pages based on the current URL.78 74 79 75 django.middleware.doc.XViewMiddleware django/trunk/docs/model-api.txt
r1108 r1166 832 832 given extra horizontal space. 833 833 834 For example (taken from the `` core.flatfiles`` model)::834 For example (taken from the ``django.contrib.flatpages`` model):: 835 835 836 836 fields = ( django/trunk/docs/settings.txt
r1165 r1166 563 563 is installed (see the `middleware docs`_). 564 564 565 USE_FLAT_PAGES566 --------------567 568 Default: ``True``569 570 Whether to check the flat-pages table as a last resort for all 404 errors. This571 is only used if ``CommonMiddleware`` is installed (see the `middleware docs`_).572 573 565 .. _cache docs: http://www.djangoproject.com/documentation/cache/ 574 566 .. _middleware docs: http://www.djangoproject.com/documentation/middleware/ django/trunk/docs/url_dispatch.txt
r704 r1166 57 57 (r'^comments/', include('django.contrib.comments.urls.comments')), 58 58 (r'^rss/', include('django.conf.urls.rss')), 59 (r'', include('django.conf.urls.flatfiles')),60 59 ) 61 60
