Commits

Shu Zong Chen committed 1444b41 Merge

merging

  • Participants
  • Parent commits 0883a5a, 52c6dff

Comments (0)

Files changed (3)

 
 *.swp
 *.pyc
+build/

File sasaba/views.py

 # Create your views here.
-from django.http import HttpResponse, Http404
-import django.template
+from django.http import HttpResponse, HttpResponseNotFound
+from django import template
 
 class SasabaView(object):
 	def __init__(self, manager, default_template = None):
 		self.default_template = default_template
 
 	def page(self, request, page = None, template = None):
+		c = template.RequestContext(request, {})
 		if page is None:
-			raise Http404
+			return Sasaba404(c, "Page is not set")
+
 		try:
 			p = self.manager.objects.get(path=page)
-		except (self.manager.DoesNotExist, self.manager.MultipleObjectsReturned):
-			raise Http404
+		except (self.manager.DoesNotExist):
+			return Sasaba404(c, "Page does not exist")
+
+		templates = (p.template, self.default_template)
 		try:
-			t = django.template.loader.select_template((template, p.template, self.default_template))
-		except (django.template.TemplateDoesNotExist):
-			raise Http404
-		c = django.template.RequestContext(request, {})
+			t = template.loader.select_template(templates)
+		except (template.TemplateDoesNotExist):
+			return Sasaba404(c, "Template {0} does not exist".format(templates))
 		return SasabaContext(c, p, t)
 
 class SasabaContext(object):
 	def HttpResponse(self):
 		return HttpResponse(self.template.render(self.context))
 
+class Sasaba404(object):
+	def __init__(self, context, msg):
+		self.msg = msg
+		self.context = context
+		self.template = None
+		self.page = None
+
+	@property
+	def HttpResponse(self):
+		return HttpResponseNotFound(self.msg)
 from distutils.core import setup
 setup(name='sasaba',
-      version='1.0',
+      version='1.0.1',
       packages = ['sasaba',],
       )