<s> from xml . dom . minidom import parseString <EOL> from django . contrib . auth . decorators import login_required , permission_required <EOL> from django . core import mail <EOL> from django . forms import fields <EOL> from django . forms . forms import Form <EOL> from django . http import HttpResponse , HttpResponseRedirect , HttpResponseNotFound <EOL> from django . shortcuts import render_to_response <EOL> from django . template import Context , Template <EOL> from django . utils . decorators import method_decorator <EOL> def get_view ( request ) : <EOL> "<STR_LIT>" <EOL> t = Template ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> c = Context ( { '<STR_LIT>' : request . GET . get ( '<STR_LIT>' , <NUM_LIT> ) } ) <EOL> return HttpResponse ( t . render ( c ) ) <EOL> def post_view ( request ) : <EOL> """<STR_LIT>""" <EOL> if request . method == '<STR_LIT:POST>' : <EOL> if request . POST : <EOL> t = Template ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> c = Context ( { '<STR_LIT:data>' : request . POST [ '<STR_LIT:value>' ] } ) <EOL> else : <EOL> t = Template ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> c = Context ( ) <EOL> else : <EOL> t = Template ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> c = Context ( ) <EOL> return HttpResponse ( t . render ( c ) ) <EOL> def view_with_header ( request ) : <EOL> "<STR_LIT>" <EOL> response = HttpResponse ( ) <EOL> response [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> return response <EOL> def raw_post_view ( request ) : <EOL> """<STR_LIT>""" <EOL> if request . method == '<STR_LIT:POST>' : <EOL> root = parseString ( request . body ) <EOL> first_book = root . firstChild . firstChild <EOL> title , author = [ n . firstChild . nodeValue for n in first_book . childNodes ] <EOL> t = Template ( "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> c = Context ( { "<STR_LIT:title>" : title , "<STR_LIT>" : author } ) <EOL> else : <EOL> t = Template ( "<STR_LIT>" , name = "<STR_LIT>" ) <EOL> c = Context ( ) <EOL> return HttpResponse ( t . render ( c ) ) <EOL> def redirect_view ( request ) : <EOL> "<STR_LIT>" <EOL> if request . GET : <EOL> from urllib import urlencode <EOL> query = '<STR_LIT:?>' + urlencode ( request . GET , True ) <EOL> else : <EOL> query = '<STR_LIT>' <EOL> return HttpResponseRedirect ( '<STR_LIT>' + query ) <EOL> def view_with_secure ( request ) : <EOL> "<STR_LIT>" <EOL> response = HttpResponse ( ) <EOL> response . test_was_secure_request = request . is_secure ( ) <EOL> return response <EOL> def double_redirect_view ( request ) : <EOL> "<STR_LIT>" <EOL> return HttpResponseRedirect ( '<STR_LIT>' ) <EOL> def bad_view ( request ) : <EOL> "<STR_LIT>" <EOL> return HttpResponseNotFound ( '<STR_LIT>' ) <EOL> TestChoices = ( <EOL> ( '<STR_LIT:a>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:b>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:c>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:d>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:e>' , '<STR_LIT>' ) <EOL> ) <EOL> class TestForm ( Form ) : <EOL> text = fields . CharField ( ) <EOL> email = fields . EmailField ( ) <EOL> value = fields . IntegerField ( ) <EOL> single = fields . ChoiceField ( choices = TestChoices ) <EOL> multi = fields . MultipleChoiceField ( choices = TestChoices ) <EOL> def form_view ( request ) : <EOL> "<STR_LIT>" <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = TestForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> t = Template ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> c = Context ( ) <EOL> else : <EOL> t = Template ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> c = Context ( { '<STR_LIT>' : form } ) <EOL> else : <EOL> form = TestForm ( request . GET ) <EOL> t = Template ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> c = Context ( { '<STR_LIT>' : form } ) <EOL> return HttpResponse ( t . render ( c ) ) <EOL> def form_view_with_template ( request ) : <EOL> "<STR_LIT>" <EOL> if request . method == '<STR_LIT:POST>' : <EOL> form = TestForm ( request . POST ) <EOL> if form . is_valid ( ) : <EOL> message = '<STR_LIT>' <EOL> else : <EOL> message = '<STR_LIT>' <EOL> else : <EOL> form = TestForm ( ) <EOL> message = '<STR_LIT>' <EOL> return render_to_response ( '<STR_LIT>' , <EOL> { <EOL> '<STR_LIT>' : form , <EOL> '<STR_LIT:message>' : message <EOL> } <EOL> ) <EOL> def login_protected_view ( request ) : <EOL> "<STR_LIT>" <EOL> t = Template ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> c = Context ( { '<STR_LIT:user>' : request . user } ) <EOL> return HttpResponse ( t . render ( c ) ) <EOL> login_protected_view = login_required ( login_protected_view ) <EOL> def login_protected_view_changed_redirect ( request ) : <EOL> "<STR_LIT>" <EOL> t = Template ( '<STR_LIT>' , name = '<STR_LIT>' ) <EOL> c = Context ( { '<STR_LIT:user>' : request . user } ) <EOL> return HttpResponse ( t . render ( c ) ) <EOL> login_protected_view_changed_redirect = login_required ( redirect_field_name = "<STR_LIT>" ) ( login_protected_view_changed_redirect ) <EOL> def _permission_protected_view ( request ) : <EOL> "<STR_LIT>" <EOL> t = Template ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> name = '<STR_LIT>' ) <EOL> c = Context ( { '<STR_LIT:user>' : request . user } ) <EOL> return HttpResponse ( t . render ( c ) ) <EOL> permission_protected_view = permission_required ( '<STR_LIT>' ) ( _permission_protected_view ) <EOL> permission_protected_view_exception = permission_required ( '<STR_LIT>' , raise_exception = True ) ( _permission_protected_view ) <EOL> class _ViewManager ( object ) : <EOL> @ method_decorator ( login_required ) <EOL> def login_protected_view ( self , request ) : <EOL> t = Template ( '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> name = '<STR_LIT>' ) <EOL> c = Context ( { '<STR_LIT:user>' : request . user } ) <EOL> return HttpResponse ( t . render ( c ) ) <EOL> @ method_decorator ( permission_required ( '<STR_LIT>' ) ) <EOL> def permission_protected_view ( self , request ) : <EOL> t = Template ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> name = '<STR_LIT>' ) <EOL> c = Context ( { '<STR_LIT:user>' : request . user } ) <EOL> return HttpResponse ( t . render ( c ) ) <EOL> _view_manager = _ViewManager ( ) <EOL> login_protected_method_view = _view_manager . login_protected_view <EOL> permission_protected_method_view = _view_manager . permission_protected_view <EOL> def session_view ( request ) : <EOL> "<STR_LIT>" <EOL> request . session [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> t = Template ( '<STR_LIT>' , <EOL> name = '<STR_LIT>' ) <EOL> c = Context ( ) <EOL> return HttpResponse ( t . render ( c ) ) <EOL> def broken_view ( request ) : <EOL> """<STR_LIT>""" <EOL> raise KeyError ( "<STR_LIT>" ) <EOL> def mail_sending_view ( request ) : <EOL> mail . EmailMessage ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) . send ( ) <EOL> return HttpResponse ( "<STR_LIT>" ) <EOL> def mass_mail_sending_view ( request ) : <EOL> m1 = mail . EmailMessage ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> m2 = mail . EmailMessage ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> c = mail . get_connection ( ) <EOL> c . send_messages ( [ m1 , m2 ] ) <EOL> return HttpResponse ( "<STR_LIT>" ) </s>
