<s> from django . shortcuts import render_to_response <EOL> from django . template import RequestContext <EOL> from django . http import HttpResponseRedirect <EOL> from models import BlogPost <EOL> from forms import BlogPostForm <EOL> def index ( request , slug = None , template_name = '<STR_LIT>' ) : <EOL> posts = BlogPost . objects [ : <NUM_LIT:5> ] <EOL> template_context = { '<STR_LIT>' : posts } <EOL> return render_to_response ( <EOL> template_name , <EOL> template_context , <EOL> RequestContext ( request ) <EOL> ) <EOL> def show ( request , slug , template_name = '<STR_LIT>' ) : <EOL> post = BlogPost . objects . get ( slug = slug ) <EOL> template_context = { '<STR_LIT>' : post } <EOL> return render_to_response ( <EOL> template_name , <EOL> template_context , <EOL> RequestContext ( request ) <EOL> ) <EOL> def new ( request , template_name = '<STR_LIT>' ) : <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = BlogPostForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> return HttpResponseRedirect ( "<STR_LIT:/>" ) <EOL> else : <EOL> form = BlogPostForm ( ) <EOL> template_context = { '<STR_LIT>' : form } <EOL> return render_to_response ( <EOL> template_name , <EOL> template_context , <EOL> RequestContext ( request ) <EOL> ) <EOL> def delete ( request , slug ) : <EOL> post = BlogPost . objects ( slug = slug ) <EOL> post . delete ( ) <EOL> return HttpResponseRedirect ( "<STR_LIT:/>" ) <EOL> def edit ( request , slug , template_name = '<STR_LIT>' ) : <EOL> post = BlogPost . objects . get ( slug = slug ) <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = BlogPostForm ( request . POST , instance = post ) <EOL> if form . is_valid ( ) : <EOL> form . save ( ) <EOL> return HttpResponseRedirect ( post . get_absolute_url ( ) ) <EOL> else : <EOL> form = BlogPostForm ( instance = post ) <EOL> template_context = { '<STR_LIT>' : form } <EOL> return render_to_response ( <EOL> template_name , <EOL> template_context , <EOL> RequestContext ( request ) <EOL> ) </s>
