~ubuntu-branches/ubuntu/jaunty/python-django/jaunty

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant, Eddy Mulyono
  • Date: 2008-09-16 12:18:47 UTC
  • mfrom: (1.1.5 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080916121847-mg225rg5mnsdqzr0
Tags: 1.0-1ubuntu1
* Merge from Debian (LP: #264191), remaining changes:
  - Run test suite on build.

[Eddy Mulyono]
* Update patch to workaround network test case failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from django.http import HttpResponse
 
2
from django import forms
 
3
from django.views.generic.create_update import create_object
 
4
 
 
5
from models import Article
 
6
 
 
7
 
 
8
def index_page(request):
 
9
    """Dummy index page"""
 
10
    return HttpResponse('<html><body>Dummy page</body></html>')
 
11
 
 
12
 
 
13
def custom_create(request):
 
14
    """
 
15
    Calls create_object generic view with a custom form class.
 
16
    """
 
17
    class SlugChangingArticleForm(forms.ModelForm):
 
18
        """Custom form class to overwrite the slug."""
 
19
 
 
20
        class Meta:
 
21
            model = Article
 
22
 
 
23
        def save(self, *args, **kwargs):
 
24
            self.cleaned_data['slug'] = 'some-other-slug'
 
25
            return super(SlugChangingArticleForm, self).save(*args, **kwargs)
 
26
 
 
27
    return create_object(request,
 
28
        post_save_redirect='/views/create_update/view/article/%(slug)s/',
 
29
        form_class=SlugChangingArticleForm)