2009-03-31 17:10:06 +00:00
|
|
|
import sys
|
|
|
|
|
2008-07-19 01:22:26 +00:00
|
|
|
from django import forms
|
2010-12-21 17:18:41 +00:00
|
|
|
from django.http import HttpResponse, HttpResponseRedirect
|
|
|
|
from django.core.urlresolvers import get_resolver
|
|
|
|
from django.shortcuts import render_to_response, render
|
|
|
|
from django.template import Context, RequestContext
|
2009-03-31 17:10:06 +00:00
|
|
|
from django.views.debug import technical_500_response
|
2008-07-18 19:45:00 +00:00
|
|
|
from django.views.generic.create_update import create_object
|
|
|
|
|
2010-03-08 15:20:29 +00:00
|
|
|
from regressiontests.views import BrokenException, except_args
|
|
|
|
|
2008-07-18 19:45:00 +00:00
|
|
|
from models import Article
|
|
|
|
|
2007-09-17 14:48:33 +00:00
|
|
|
|
|
|
|
def index_page(request):
|
2007-09-19 13:26:56 +00:00
|
|
|
"""Dummy index page"""
|
2007-09-17 14:48:33 +00:00
|
|
|
return HttpResponse('<html><body>Dummy page</body></html>')
|
2008-07-18 19:45:00 +00:00
|
|
|
|
|
|
|
def custom_create(request):
|
|
|
|
"""
|
|
|
|
Calls create_object generic view with a custom form class.
|
|
|
|
"""
|
|
|
|
class SlugChangingArticleForm(forms.ModelForm):
|
|
|
|
"""Custom form class to overwrite the slug."""
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Article
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
2010-01-05 03:56:19 +00:00
|
|
|
self.instance.slug = 'some-other-slug'
|
2008-07-18 19:45:00 +00:00
|
|
|
return super(SlugChangingArticleForm, self).save(*args, **kwargs)
|
|
|
|
|
|
|
|
return create_object(request,
|
|
|
|
post_save_redirect='/views/create_update/view/article/%(slug)s/',
|
|
|
|
form_class=SlugChangingArticleForm)
|
2009-03-31 17:10:06 +00:00
|
|
|
|
|
|
|
def raises(request):
|
|
|
|
try:
|
|
|
|
raise Exception
|
|
|
|
except Exception:
|
|
|
|
return technical_500_response(request, *sys.exc_info())
|
2009-04-12 03:50:47 +00:00
|
|
|
|
2010-03-05 18:53:07 +00:00
|
|
|
def raises404(request):
|
|
|
|
resolver = get_resolver(None)
|
|
|
|
resolver.resolve('')
|
2010-03-08 15:20:29 +00:00
|
|
|
|
2009-04-12 03:50:47 +00:00
|
|
|
def redirect(request):
|
|
|
|
"""
|
|
|
|
Forces an HTTP redirect.
|
|
|
|
"""
|
|
|
|
return HttpResponseRedirect("target/")
|
|
|
|
|
2010-03-08 15:20:29 +00:00
|
|
|
def view_exception(request, n):
|
|
|
|
raise BrokenException(except_args[int(n)])
|
|
|
|
|
2010-03-08 17:01:21 +00:00
|
|
|
def template_exception(request, n):
|
|
|
|
return render_to_response('debug/template_exception.html',
|
|
|
|
{'arg': except_args[int(n)]})
|
|
|
|
|
2010-12-21 17:18:41 +00:00
|
|
|
# Some views to exercise the shortcuts
|
|
|
|
|
|
|
|
def render_to_response_view(request):
|
|
|
|
return render_to_response('debug/render_test.html', {
|
|
|
|
'foo': 'FOO',
|
|
|
|
'bar': 'BAR',
|
|
|
|
})
|
|
|
|
|
|
|
|
def render_to_response_view_with_request_context(request):
|
|
|
|
return render_to_response('debug/render_test.html', {
|
|
|
|
'foo': 'FOO',
|
|
|
|
'bar': 'BAR',
|
|
|
|
}, context_instance=RequestContext(request))
|
|
|
|
|
|
|
|
def render_to_response_view_with_mimetype(request):
|
|
|
|
return render_to_response('debug/render_test.html', {
|
|
|
|
'foo': 'FOO',
|
|
|
|
'bar': 'BAR',
|
|
|
|
}, mimetype='application/x-rendertest')
|
|
|
|
|
|
|
|
def render_view(request):
|
|
|
|
return render(request, 'debug/render_test.html', {
|
|
|
|
'foo': 'FOO',
|
|
|
|
'bar': 'BAR',
|
|
|
|
})
|
|
|
|
|
|
|
|
def render_view_with_base_context(request):
|
|
|
|
return render(request, 'debug/render_test.html', {
|
|
|
|
'foo': 'FOO',
|
|
|
|
'bar': 'BAR',
|
|
|
|
}, context_instance=Context())
|
|
|
|
|
|
|
|
def render_view_with_mimetype(request):
|
|
|
|
return render(request, 'debug/render_test.html', {
|
|
|
|
'foo': 'FOO',
|
|
|
|
'bar': 'BAR',
|
|
|
|
}, mimetype='application/x-rendertest')
|