From bf9bf130c67e53224ee49f9ffc0d772f800d1a69 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 7 Mar 2011 03:10:29 +0530 Subject: [PATCH] disable csrf for api calls, best practices info template --- itf/api/views.py | 2 ++ itf/app/models.py | 1 + itf/bestpractices/models.py | 9 +++++++++ itf/templates/bestpractices/BestPractice/info.html | 11 ++++++++++- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/itf/api/views.py b/itf/api/views.py index 0fc8a14..95709de 100644 --- a/itf/api/views.py +++ b/itf/api/views.py @@ -28,7 +28,9 @@ from ox.django.http import HttpFileResponse import ox from actions import actions from user.models import get_user_json +from django.views.decorators.csrf import csrf_exempt +@csrf_exempt def api(request): if request.META['REQUEST_METHOD'] == "OPTIONS": response = render_to_json_response({'status': {'code': 200, diff --git a/itf/app/models.py b/itf/app/models.py index 6d77066..5641b68 100644 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -57,6 +57,7 @@ class ItfModel(models.Model): qobjects.append(qobject) return qset.filter(reduce(operator.or_, qobjects)) + @classmethod def get_fk_objects(kls): ret = {} diff --git a/itf/bestpractices/models.py b/itf/bestpractices/models.py index fc9b00f..a295875 100644 --- a/itf/bestpractices/models.py +++ b/itf/bestpractices/models.py @@ -27,13 +27,16 @@ class BestPractice(ItfModel): def __unicode__(self): return str(self.id) + ": " + self.title + def info_dict(self): return { 'id': self.id, 'title': self.title, 'story': self.story, + 'stories': map(lambda x: x.get_dict(), BestPracticeStory.objects.filter(bestpractice=self)), 'guideline': self.guideline, 'law': self.law, + 'law_image': self.law_image if self.law_image != None else '', 'theatre': self.theatre, 'quick_howto': self.quick_howto, 'category': self.category.name, @@ -74,6 +77,12 @@ class BestPracticeStory(models.Model): def __unicode__(self): return self.text + def get_dict(self): + return { + 'text': self.text, + 'image': self.image.url, + } + class BestPracticeCategory(models.Model): name = models.CharField(max_length=256) diff --git a/itf/templates/bestpractices/BestPractice/info.html b/itf/templates/bestpractices/BestPractice/info.html index 1187ece..9ba77aa 100644 --- a/itf/templates/bestpractices/BestPractice/info.html +++ b/itf/templates/bestpractices/BestPractice/info.html @@ -1,6 +1,15 @@
Story: {{html tmplToHtml(story)}}

- Law: {{html tmplToHtml(law)}}

+ {{each stories}} + Story ${$index + 1}: ${value.text} + +

+ {{/each}} + Law: {{html tmplToHtml(law)}} + {{if law_image}} + + {{/if}} +

Relevance to Theatre: {{html tmplToHtml(theatre)}}

Quick Howto: {{html tmplToHtml(quick_howto)}}