summaryrefslogtreecommitdiff
path: root/django/views
diff options
context:
space:
mode:
authorChristopher Long <indirecthit@gmail.com>2006-07-27 22:38:02 +0000
committerChristopher Long <indirecthit@gmail.com>2006-07-27 22:38:02 +0000
commit75c6dc967d4f27a8361d8cf77a1ea279ba9fa3b1 (patch)
tree2b1ad1b7c7af7cc9ed04a843c33d6ae539b51475 /django/views
parent8e48efbbd09685f04856bf448d37c4b7a84e8548 (diff)
downloaddjango-75c6dc967d4f27a8361d8cf77a1ea279ba9fa3b1.tar.gz
[per-object-permissions] Update to trunk
git-svn-id: http://code.djangoproject.com/svn/django/branches/per-object-permissions@3464 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/views')
-rw-r--r--django/views/debug.py6
-rw-r--r--django/views/decorators/cache.py1
-rw-r--r--django/views/generic/create_update.py13
-rw-r--r--django/views/generic/date_based.py57
-rw-r--r--django/views/static.py1
5 files changed, 46 insertions, 32 deletions
diff --git a/django/views/debug.py b/django/views/debug.py
index 6cbbde987b..6934360afd 100644
--- a/django/views/debug.py
+++ b/django/views/debug.py
@@ -3,8 +3,6 @@ from django.template import Template, Context, TemplateDoesNotExist
from django.utils.html import escape
from django.http import HttpResponseServerError, HttpResponseNotFound
import os, re
-from itertools import count, izip
-from os.path import dirname, join as pathjoin
HIDDEN_SETTINGS = re.compile('SECRET|PASSWORD')
@@ -124,7 +122,7 @@ def technical_500_response(request, exc_type, exc_value, tb):
'frames': frames,
'lastframe': frames[-1],
'request': request,
- 'request_protocol': os.environ.get("HTTPS") == "on" and "https" or "http",
+ 'request_protocol': request.is_secure() and "https" or "http",
'settings': get_safe_settings(),
'template_info': template_info,
'template_does_not_exist': template_does_not_exist,
@@ -149,7 +147,7 @@ def technical_404_response(request, exception):
'urlpatterns': tried,
'reason': str(exception),
'request': request,
- 'request_protocol': os.environ.get("HTTPS") == "on" and "https" or "http",
+ 'request_protocol': request.is_secure() and "https" or "http",
'settings': get_safe_settings(),
})
return HttpResponseNotFound(t.render(c), mimetype='text/html')
diff --git a/django/views/decorators/cache.py b/django/views/decorators/cache.py
index 5467ff501e..b04cc2340b 100644
--- a/django/views/decorators/cache.py
+++ b/django/views/decorators/cache.py
@@ -10,7 +10,6 @@ example, as that is unique across a Django project.
Additionally, all headers from the response's Vary header will be taken into
account on caching -- just like the middleware does.
"""
-import re
from django.utils.decorators import decorator_from_middleware
from django.utils.cache import patch_cache_control, add_never_cache_headers
diff --git a/django/views/generic/create_update.py b/django/views/generic/create_update.py
index b5fdd3e4cc..27ba327ff5 100644
--- a/django/views/generic/create_update.py
+++ b/django/views/generic/create_update.py
@@ -4,7 +4,6 @@ from django import forms
from django.db.models import FileField
from django.contrib.auth.views import redirect_to_login
from django.template import RequestContext
-from django.core.paginator import ObjectPaginator, InvalidPage
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.core.exceptions import ObjectDoesNotExist, ImproperlyConfigured
@@ -20,7 +19,7 @@ def create_object(request, model, template_name=None,
the form wrapper for the object
"""
if extra_context is None: extra_context = {}
- if login_required and request.user.is_anonymous():
+ if login_required and not request.user.is_authenticated():
return redirect_to_login(request.path)
manipulator = model.AddManipulator(follow=follow)
@@ -39,7 +38,7 @@ def create_object(request, model, template_name=None,
# No errors -- this means we can save the data!
new_object = manipulator.save(new_data)
- if not request.user.is_anonymous():
+ if request.user.is_authenticated():
request.user.message_set.create(message="The %s was created successfully." % model._meta.verbose_name)
# Redirect to the new object: first by trying post_save_redirect,
@@ -86,7 +85,7 @@ def update_object(request, model, object_id=None, slug=None,
the original object being edited
"""
if extra_context is None: extra_context = {}
- if login_required and request.user.is_anonymous():
+ if login_required and not request.user.is_authenticated():
return redirect_to_login(request.path)
# Look up the object to be edited
@@ -113,7 +112,7 @@ def update_object(request, model, object_id=None, slug=None,
if not errors:
object = manipulator.save(new_data)
- if not request.user.is_anonymous():
+ if request.user.is_authenticated():
request.user.message_set.create(message="The %s was updated successfully." % model._meta.verbose_name)
# Do a post-after-redirect so that reload works, etc.
@@ -162,7 +161,7 @@ def delete_object(request, model, post_delete_redirect,
the original object being deleted
"""
if extra_context is None: extra_context = {}
- if login_required and request.user.is_anonymous():
+ if login_required and not request.user.is_authenticated():
return redirect_to_login(request.path)
# Look up the object to be edited
@@ -180,7 +179,7 @@ def delete_object(request, model, post_delete_redirect,
if request.method == 'POST':
object.delete()
- if not request.user.is_anonymous():
+ if request.user.is_authenticated():
request.user.message_set.create(message="The %s was deleted." % model._meta.verbose_name)
return HttpResponseRedirect(post_delete_redirect)
else:
diff --git a/django/views/generic/date_based.py b/django/views/generic/date_based.py
index 7084cdfe5e..860199c22e 100644
--- a/django/views/generic/date_based.py
+++ b/django/views/generic/date_based.py
@@ -7,7 +7,7 @@ import datetime, time
def archive_index(request, queryset, date_field, num_latest=15,
template_name=None, template_loader=loader,
extra_context=None, allow_empty=False, context_processors=None,
- mimetype=None):
+ mimetype=None, allow_future=False):
"""
Generic top-level archive of date-based objects.
@@ -20,7 +20,8 @@ def archive_index(request, queryset, date_field, num_latest=15,
"""
if extra_context is None: extra_context = {}
model = queryset.model
- queryset = queryset.filter(**{'%s__lte' % date_field: datetime.datetime.now()})
+ if not allow_future:
+ queryset = queryset.filter(**{'%s__lte' % date_field: datetime.datetime.now()})
date_list = queryset.dates(date_field, 'year')[::-1]
if not date_list and not allow_empty:
raise Http404, "No %s available" % model._meta.verbose_name
@@ -47,7 +48,7 @@ def archive_index(request, queryset, date_field, num_latest=15,
def archive_year(request, year, queryset, date_field, template_name=None,
template_loader=loader, extra_context=None, allow_empty=False,
context_processors=None, template_object_name='object', mimetype=None,
- make_object_list=False):
+ make_object_list=False, allow_future=False):
"""
Generic yearly archive view.
@@ -67,8 +68,8 @@ def archive_year(request, year, queryset, date_field, template_name=None,
lookup_kwargs = {'%s__year' % date_field: year}
- # Only bother to check current date if the year isn't in the past.
- if int(year) >= now.year:
+ # Only bother to check current date if the year isn't in the past and future objects aren't requested.
+ if int(year) >= now.year and not allow_future:
lookup_kwargs['%s__lte' % date_field] = now
date_list = queryset.filter(**lookup_kwargs).dates(date_field, 'month')
if not date_list and not allow_empty:
@@ -95,7 +96,7 @@ def archive_year(request, year, queryset, date_field, template_name=None,
def archive_month(request, year, month, queryset, date_field,
month_format='%b', template_name=None, template_loader=loader,
extra_context=None, allow_empty=False, context_processors=None,
- template_object_name='object', mimetype=None):
+ template_object_name='object', mimetype=None, allow_future=False):
"""
Generic monthly archive view.
@@ -127,19 +128,28 @@ def archive_month(request, year, month, queryset, date_field,
last_day = first_day.replace(month=first_day.month + 1)
lookup_kwargs = {'%s__range' % date_field: (first_day, last_day)}
- # Only bother to check current date if the month isn't in the past.
- if last_day >= now.date():
+ # Only bother to check current date if the month isn't in the past and future objects are requested.
+ if last_day >= now.date() and not allow_future:
lookup_kwargs['%s__lte' % date_field] = now
object_list = queryset.filter(**lookup_kwargs)
if not object_list and not allow_empty:
raise Http404
+
+ # Calculate the next month, if applicable.
+ if allow_future:
+ next_month = last_day + datetime.timedelta(days=1)
+ elif last_day < datetime.date.today():
+ next_month = last_day + datetime.timedelta(days=1)
+ else:
+ next_month = None
+
if not template_name:
template_name = "%s/%s_archive_month.html" % (model._meta.app_label, model._meta.object_name.lower())
t = template_loader.get_template(template_name)
c = RequestContext(request, {
'%s_list' % template_object_name: object_list,
'month': date,
- 'next_month': (last_day < datetime.date.today()) and (last_day + datetime.timedelta(days=1)) or None,
+ 'next_month': next_month,
'previous_month': first_day - datetime.timedelta(days=1),
}, context_processors)
for key, value in extra_context.items():
@@ -152,7 +162,7 @@ def archive_month(request, year, month, queryset, date_field,
def archive_week(request, year, week, queryset, date_field,
template_name=None, template_loader=loader,
extra_context=None, allow_empty=True, context_processors=None,
- template_object_name='object', mimetype=None):
+ template_object_name='object', mimetype=None, allow_future=False):
"""
Generic weekly archive view.
@@ -177,8 +187,8 @@ def archive_week(request, year, week, queryset, date_field,
last_day = date + datetime.timedelta(days=7)
lookup_kwargs = {'%s__range' % date_field: (first_day, last_day)}
- # Only bother to check current date if the week isn't in the past.
- if last_day >= now.date():
+ # Only bother to check current date if the week isn't in the past and future objects aren't requested.
+ if last_day >= now.date() and not allow_future:
lookup_kwargs['%s__lte' % date_field] = now
object_list = queryset.filter(**lookup_kwargs)
if not object_list and not allow_empty:
@@ -201,7 +211,7 @@ def archive_day(request, year, month, day, queryset, date_field,
month_format='%b', day_format='%d', template_name=None,
template_loader=loader, extra_context=None, allow_empty=False,
context_processors=None, template_object_name='object',
- mimetype=None):
+ mimetype=None, allow_future=False):
"""
Generic daily archive view.
@@ -229,12 +239,21 @@ def archive_day(request, year, month, day, queryset, date_field,
'%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max)),
}
- # Only bother to check current date if the date isn't in the past.
- if date >= now.date():
+ # Only bother to check current date if the date isn't in the past and future objects aren't requested.
+ if date >= now.date() and not allow_future:
lookup_kwargs['%s__lte' % date_field] = now
object_list = queryset.filter(**lookup_kwargs)
if not allow_empty and not object_list:
raise Http404
+
+ # Calculate the next day, if applicable.
+ if allow_future:
+ next_day = date + datetime.timedelta(days=1)
+ elif date < datetime.date.today():
+ next_day = date + datetime.timedelta(days=1)
+ else:
+ next_day = None
+
if not template_name:
template_name = "%s/%s_archive_day.html" % (model._meta.app_label, model._meta.object_name.lower())
t = template_loader.get_template(template_name)
@@ -242,7 +261,7 @@ def archive_day(request, year, month, day, queryset, date_field,
'%s_list' % template_object_name: object_list,
'day': date,
'previous_day': date - datetime.timedelta(days=1),
- 'next_day': (date < datetime.date.today()) and (date + datetime.timedelta(days=1)) or None,
+ 'next_day': next_day,
}, context_processors)
for key, value in extra_context.items():
if callable(value):
@@ -267,7 +286,7 @@ def object_detail(request, year, month, day, queryset, date_field,
month_format='%b', day_format='%d', object_id=None, slug=None,
slug_field=None, template_name=None, template_name_field=None,
template_loader=loader, extra_context=None, context_processors=None,
- template_object_name='object', mimetype=None):
+ template_object_name='object', mimetype=None, allow_future=False):
"""
Generic detail view from year/month/day/slug or year/month/day/id structure.
@@ -289,8 +308,8 @@ def object_detail(request, year, month, day, queryset, date_field,
'%s__range' % date_field: (datetime.datetime.combine(date, datetime.time.min), datetime.datetime.combine(date, datetime.time.max)),
}
- # Only bother to check current date if the date isn't in the past.
- if date >= now.date():
+ # Only bother to check current date if the date isn't in the past and future objects aren't requested.
+ if date >= now.date() and not allow_future:
lookup_kwargs['%s__lte' % date_field] = now
if object_id:
lookup_kwargs['%s__exact' % model._meta.pk.name] = object_id
diff --git a/django/views/static.py b/django/views/static.py
index 072a01671e..ac323944d0 100644
--- a/django/views/static.py
+++ b/django/views/static.py
@@ -1,5 +1,4 @@
from django.template import loader
-from django.core.exceptions import ImproperlyConfigured
from django.http import Http404, HttpResponse, HttpResponseRedirect, HttpResponseNotModified
from django.template import Template, Context, TemplateDoesNotExist
import mimetypes