2009-04-01 01:10:06 +08:00
|
|
|
import sys
|
|
|
|
|
2009-04-12 11:50:47 +08:00
|
|
|
from django.http import HttpResponse, HttpResponseRedirect
|
2008-07-19 09:22:26 +08:00
|
|
|
from django import forms
|
2009-04-01 01:10:06 +08:00
|
|
|
from django.views.debug import technical_500_response
|
2008-07-19 03:45:00 +08:00
|
|
|
from django.views.generic.create_update import create_object
|
|
|
|
|
|
|
|
from models import Article
|
|
|
|
|
2007-09-17 22:48:33 +08:00
|
|
|
|
|
|
|
def index_page(request):
|
2007-09-19 21:26:56 +08:00
|
|
|
"""Dummy index page"""
|
2007-09-17 22:48:33 +08:00
|
|
|
return HttpResponse('<html><body>Dummy page</body></html>')
|
2008-07-19 03:45:00 +08: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):
|
|
|
|
self.cleaned_data['slug'] = 'some-other-slug'
|
|
|
|
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-04-01 01:10:06 +08:00
|
|
|
|
|
|
|
def raises(request):
|
|
|
|
try:
|
|
|
|
raise Exception
|
|
|
|
except Exception:
|
|
|
|
return technical_500_response(request, *sys.exc_info())
|
2009-04-12 11:50:47 +08:00
|
|
|
|
|
|
|
def redirect(request):
|
|
|
|
"""
|
|
|
|
Forces an HTTP redirect.
|
|
|
|
"""
|
|
|
|
return HttpResponseRedirect("target/")
|
|
|
|
|