From 86258ec5284b9d7901952262c9bf49262d1e1ebe Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 23 Aug 2011 03:26:30 +0530 Subject: [PATCH] bunch of models meta foo; add fccv spam protection for comments --- itf/app/models.py | 50 +++++++++++++++++++++++++++++++++++-- itf/bestpractices/models.py | 2 +- itf/settings.py | 2 ++ itf/urls.py | 2 ++ requirements.txt | 1 + 5 files changed, 54 insertions(+), 3 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index 51a6e5e..56049cf 100644 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -4,7 +4,9 @@ from django.db.models import Q from ox.text import smartSplit from ox.django.fields import DictField from django.core.paginator import Paginator, InvalidPage, EmptyPage - +from django.template.loader import render_to_string +from django.contrib.contenttypes.models import ContentType +from insidepages.models import ModuleTab def splitSearch(string): ret = [] @@ -19,7 +21,8 @@ class ItfModel(models.Model): # related_models = [] sort_fields = [] hasComments = True - + title_field = "title" + class Meta: abstract = True @@ -30,9 +33,52 @@ class ItfModel(models.Model): def info_dict(self): return self.get_dict() + def get_title(self): + return self.get(self.title_field) + + def get_tab(self): + ctype = ContentType.objects.get(model=self.__class__._meta.module_name) + tab = ModuleTab.objects.filter(model=ctype)[0] + return tab + + def get_absolute_url(self): + return "%s?tab_id=%d&object_id=%d" % (self.get_module().get_absolute_url(), self.get_tab().id, self.id) + + def get_module(self): + tab = self.get_tab() + if tab: + return tab.module + else: + return None + + + def get_main_image(self): + return { + 'url': '', + 'caption': '' + } + + def get_template_path(self): + kls = self.__class__ + return "modules/%s/%s.html" % (kls._meta.app_label, kls._meta.module_name) + def get_dict(self): return self.get(self._get_fields().keys()) + def insidepage_dict(self): + try: + html = render_to_string(self.get_template_path(), self.info_dict()) + except: + html = "Template for this model not found." + return { + 'url': self.get_absolute_url(), + 'title': self.get_title(), + 'main_image': self.get_main_image(), + 'html': html + } + + + def get(self, props): typ = type(props) if typ == list: diff --git a/itf/bestpractices/models.py b/itf/bestpractices/models.py index aee62a5..09ae5f4 100644 --- a/itf/bestpractices/models.py +++ b/itf/bestpractices/models.py @@ -96,7 +96,7 @@ class BestPracticeStory(models.Model): 'image': self.image.url if self.image.name != '' else '' } -class BestPracticeFAQ(models.Model): +class BestPracticeFAQ(ItfModel): question = models.TextField() answer = models.TextField() diff --git a/itf/settings.py b/itf/settings.py index cde37cf..ec993f0 100644 --- a/itf/settings.py +++ b/itf/settings.py @@ -141,6 +141,7 @@ INSTALLED_APPS = ( 'registration', # 'itfcore', 'festival', + 'insidepages', 'erang_organised', 'scriptbank', 'bestpractices', @@ -158,6 +159,7 @@ INSTALLED_APPS = ( 'south', 'user', 'ckeditor', + 'fccv', ) ACCOUNT_ACTIVATION_DAYS = 30 diff --git a/itf/urls.py b/itf/urls.py index 5a7f78d..5b191ba 100644 --- a/itf/urls.py +++ b/itf/urls.py @@ -17,6 +17,8 @@ urlpatterns = patterns('', # (r'^bhangar/', include('bhangar.foo.urls')), #(r'^search/', include('solango.urls')), (r'^t/$', "frontpage.views.index"), + (r'm/', include('insidepages.urls')), + # ('m/(?P.*)', 'insidepages.views.main'), (r'^comments/', include('django.contrib.comments.urls')), (r'^ckeditor/', include('ckeditor.urls')), (r'^robots.txt$', direct_to_template, {'template': 'robots.txt', 'mimetype': 'text/plain'}), diff --git a/requirements.txt b/requirements.txt index c3cecb6..53290f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,3 +10,4 @@ django-extensions django-debug-toolbar South django-ckeditor +fccv #for comment-spam protection