~ubuntu-branches/ubuntu/quantal/python-django/quantal

« back to all changes in this revision

Viewing changes to tests/regressiontests/views/views.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2009-07-29 11:26:28 UTC
  • mfrom: (1.1.8 upstream) (4.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090729112628-pg09ino8sz0sj21t
Tags: 1.1-1
* New upstream release.
* Merge from experimental:
  - Ship FastCGI initscript and /etc/default file in python-django's examples
    directory (Closes: #538863)
  - Drop "05_10539-sphinx06-compatibility.diff"; it has been applied
    upstream.
  - Bump Standards-Version to 3.8.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import sys
 
2
 
 
3
from django.http import HttpResponse, HttpResponseRedirect
 
4
from django import forms
 
5
from django.views.debug import technical_500_response
 
6
from django.views.generic.create_update import create_object
 
7
 
 
8
from models import Article
 
9
 
 
10
 
 
11
def index_page(request):
 
12
    """Dummy index page"""
 
13
    return HttpResponse('<html><body>Dummy page</body></html>')
 
14
 
 
15
 
 
16
def custom_create(request):
 
17
    """
 
18
    Calls create_object generic view with a custom form class.
 
19
    """
 
20
    class SlugChangingArticleForm(forms.ModelForm):
 
21
        """Custom form class to overwrite the slug."""
 
22
 
 
23
        class Meta:
 
24
            model = Article
 
25
 
 
26
        def save(self, *args, **kwargs):
 
27
            self.cleaned_data['slug'] = 'some-other-slug'
 
28
            return super(SlugChangingArticleForm, self).save(*args, **kwargs)
 
29
 
 
30
    return create_object(request,
 
31
        post_save_redirect='/views/create_update/view/article/%(slug)s/',
 
32
        form_class=SlugChangingArticleForm)
 
33
 
 
34
def raises(request):
 
35
    try:
 
36
        raise Exception
 
37
    except Exception:
 
38
        return technical_500_response(request, *sys.exc_info())
 
39
 
 
40
def redirect(request):
 
41
    """
 
42
    Forces an HTTP redirect.
 
43
    """
 
44
    return HttpResponseRedirect("target/")
 
45