<s> from jsonrpc import * <EOL> from djangoweb . webpages . models import Page <EOL> from django . template import loader <EOL> from django . shortcuts import render_to_response <EOL> from django . template import RequestContext , Template <EOL> from django . http import HttpResponseRedirect , HttpResponse <EOL> import urllib <EOL> service = JSONRPCService ( ) <EOL> def index ( request , path = None ) : <EOL> f = open ( "<STR_LIT>" , "<STR_LIT:a>" ) <EOL> f . write ( "<STR_LIT>" % str ( path ) ) <EOL> f . write ( "<STR_LIT>" % str ( request ) ) <EOL> path = request . GET . get ( '<STR_LIT>' , None ) <EOL> if path == '<STR_LIT>' : <EOL> path = '<STR_LIT:index>' <EOL> f . write ( "<STR_LIT>" % ( path ) ) <EOL> if path is None : <EOL> return HttpResponseRedirect ( "<STR_LIT>" ) <EOL> p = Page . objects . get ( name = path ) <EOL> f . write ( "<STR_LIT>" % ( str ( p ) ) ) <EOL> f . close ( ) <EOL> args = { '<STR_LIT:title>' : p . name , <EOL> '<STR_LIT>' : p . text <EOL> } <EOL> context_instance = RequestContext ( request ) <EOL> context_instance . autoescape = False <EOL> try : <EOL> template = Page . objects . get ( name = '<STR_LIT>' ) <EOL> except Page . DoesNotExist : <EOL> template = None <EOL> if not template : <EOL> return render_to_response ( '<STR_LIT>' , args , context_instance ) <EOL> tpl = loader . get_template_from_string ( template ) <EOL> context_instance . update ( args ) <EOL> tpl = tpl . render ( context_instance ) <EOL> return HttpResponse ( tpl ) <EOL> @ jsonremote ( service ) <EOL> def getPage ( request , num ) : <EOL> return json_convert ( [ Page . objects . get ( id = num ) ] ) <EOL> @ jsonremote ( service ) <EOL> def getPageByName ( request , name ) : <EOL> return json_convert ( [ Page . objects . get ( name = name ) ] ) <EOL> @ jsonremote ( service ) <EOL> def getPages ( request ) : <EOL> return json_convert ( Page . objects . all ( ) ) <EOL> @ jsonremote ( service ) <EOL> def updatePage ( request , item ) : <EOL> t = Page . objects . get ( id = item [ '<STR_LIT:id>' ] ) <EOL> t . name = item [ '<STR_LIT:name>' ] <EOL> t . text = item [ '<STR_LIT:text>' ] <EOL> t . save ( ) <EOL> return getPages ( request ) <EOL> @ jsonremote ( service ) <EOL> def addPage ( request , item ) : <EOL> t = Page ( ) <EOL> t . name = item [ '<STR_LIT:name>' ] <EOL> t . text = item [ '<STR_LIT:text>' ] <EOL> t . save ( ) <EOL> return getPages ( request ) <EOL> @ jsonremote ( service ) <EOL> def deletePage ( request , num ) : <EOL> t = Page . objects . get ( id = num ) <EOL> t . delete ( ) <EOL> return getPages ( request ) </s>
