From 54b69c6d5e424acfb4357a5ec53eca96bbb30473 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sat, 27 Aug 2011 16:24:45 +0530 Subject: [PATCH] changed model structure to have ModelExtra to be able to add more options to a model class --- itf/app/models.py | 5 +++-- itf/insidepages/admin.py | 14 ++++++++++++ itf/insidepages/models.py | 43 ++++++++++++++++++++++++++++++++++--- itf/insidepages/views.py | 4 ++-- itf/settings.py | 2 +- itf/static/js/insidepage.js | 7 +----- 6 files changed, 61 insertions(+), 14 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index f9367e7..6b3197e 100644 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -6,7 +6,7 @@ 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 +from insidepages.models import ModuleTab, ModelExtra def splitSearch(string): ret = [] @@ -38,7 +38,8 @@ class ItfModel(models.Model): def get_tab(self): ctype = ContentType.objects.get(model=self.__class__._meta.module_name) - tab = ModuleTab.objects.filter(model=ctype)[0] + modelextra = ModelExtra.objects.filter(model=ctype)[0] + tab = ModuleTab.objects.filter(model=modelextra)[0] return tab def get_absolute_url(self): diff --git a/itf/insidepages/admin.py b/itf/insidepages/admin.py index 741f9f6..768bf5a 100644 --- a/itf/insidepages/admin.py +++ b/itf/insidepages/admin.py @@ -8,9 +8,23 @@ class TabsInline(admin.StackedInline): class ModuleAdmin(admin.ModelAdmin): inlines = [TabsInline] + prepopulated_fields = {'slug': ('title',)} # list_display = ('name', 'order',) # list_editable = ['order'] +class ButtonsInline(admin.StackedInline): + model = ModelExtra.buttons.through + extra = 3 + +class SortInline(admin.StackedInline): + model = ModelSort + extra = 4 + +class ModelExtraAdmin(admin.ModelAdmin): + inlines = [SortInline, ButtonsInline] + admin.site.register(Module, ModuleAdmin) +admin.site.register(ModelExtra, ModelExtraAdmin) +admin.site.register(ModelButton) #admin.site.register(SliderBox, SliderBoxAdmin) diff --git a/itf/insidepages/models.py b/itf/insidepages/models.py index f202492..6bdcf51 100644 --- a/itf/insidepages/models.py +++ b/itf/insidepages/models.py @@ -17,7 +17,7 @@ class ModuleTab(models.Model): module = models.ForeignKey(Module) title = models.CharField(max_length=64) text = models.TextField() - model = models.ForeignKey(ContentType) + model = models.ForeignKey("ModelExtra") is_default = models.BooleanField(default=False) order = models.IntegerField(default=1) is_displayed = models.BooleanField(default=True) @@ -28,6 +28,43 @@ class ModuleTab(models.Model): def __unicode__(self): return self.title - def get_list(self, options): - return self.model.model_class().get_list(options) + def model_class(self): + return self.model.model.model_class() + + def get_list(self, options): + return self.model_class().get_list(options) + + +class ModelExtra(models.Model): + model = models.ForeignKey(ContentType) + friendly_name = models.CharField(max_length=128) + has_comments = models.BooleanField(default=False) + buttons = models.ManyToManyField('ModelButton', through='ModelExtraButton', blank=True) + + def __unicode__(self): + return self.friendly_name + + +class ModelSort(models.Model): + model = models.ForeignKey(ModelExtra) + operator = models.CharField(max_length=1) + field_name = models.CharField(max_length=64) + friendly_name = models.CharField(max_length=128) + + def __unicode__(self): + return self.friendly_name + + +class ModelButton(models.Model): + name = models.CharField(max_length=64) + template = models.TextField(blank=True) + + def __unicode__(self): + return self.name + + +class ModelExtraButton(models.Model): + modelextra = models.ForeignKey(ModelExtra) + modelbutton = models.ForeignKey(ModelButton) + parameters = models.CharField(max_length=64, blank=True) diff --git a/itf/insidepages/views.py b/itf/insidepages/views.py index 43452fb..0e51643 100644 --- a/itf/insidepages/views.py +++ b/itf/insidepages/views.py @@ -9,7 +9,7 @@ def main(request, module_slug): tabs = m.moduletab_set.all() default_tab = tabs[0] list_options = {} #get some options as GET params, etc. to potentially pass to get_list - default_tab_list = default_tab.model.model_class().get_list(list_options) + default_tab_list = default_tab.model_class().get_list(list_options) context = RequestContext(request, { 'title': m.title, 'default_tab': tabs[0], @@ -34,7 +34,7 @@ def get_list(request): def get_details(request): tab_id = request.GET.get("tab_id", 0) tab = get_object_or_404(ModuleTab, pk=tab_id) - model_class = tab.model.model_class() + model_class = tab.model_class() object_id = request.GET.get("object_id", 0) obj = get_object_or_404(model_class, pk=object_id) return render_to_json_response(obj.insidepage_dict()) diff --git a/itf/settings.py b/itf/settings.py index ec993f0..99569e3 100644 --- a/itf/settings.py +++ b/itf/settings.py @@ -148,7 +148,7 @@ INSTALLED_APPS = ( 'tagging', 'app', 'api', - 'boxes', +# 'boxes', 'frontpage', # 'solango', 'multilingual', diff --git a/itf/static/js/insidepage.js b/itf/static/js/insidepage.js index db2b0c2..55ac193 100644 --- a/itf/static/js/insidepage.js +++ b/itf/static/js/insidepage.js @@ -24,12 +24,7 @@ function getLi(item) { var $li = $('
  • ').addClass("tabListItem"); var $a = $('').attr("href", '#').attr("data-id", item.id).appendTo($li); // console.log(item.title.length); - if (item.title.length > titleLength) { - var title = item.title.substring(0,titleLength) + "..."; - } else { - var title = item.title; - } - var $span = $('').text(title).appendTo($a); + var $span = $('').text(item.title).appendTo($a); return $li; }