Alive CMS
from django.utils.html import escape from utils.object import Obj
__all__ = ['HelloWorld'] class HelloWorld(Obj): 'Very basic content type, no storage' is_container = 0 def view_item(self): # If you add '?name=John' to the URL of the object then # request.GET.get('name') will contain 'John' or None (no name) # Note: request is passed into the object inside self.context name = self.context.request.GET.get('name') if not name: # Default name name = 'World' content = '<h2>Hello %s!</h2>' % escape(name) # HTML in the return value is escaped by default, # so in the template the content is marked as safe and then # it will be rendered as HTML, so make sure user provided input is safe # Also note that there is a default template for view_item # that uses the variable 'content' for displaying content, so this works return {'content': content, 'message': 'The mandatory example:'} # returning a HttpResponse is an alternative way of returning data # without using a template, useful for image data for instance # but in that case you need to set the headers too. # you can do something like this for a file: # from django.http import HttpResponse # response = HttpResponse(file_data) # response['Content-Length'] = '%s' % len(file_data) # response['Content-Type'] = file_content_type # the file's content type # response['Cache-Control'] = 'no-cache' # response['Pragma'] = 'no-cache' # return response def edit_item(self): # return the view return self.view_item()