From d2bbe35156e60ee4282bf5aca0b8062a24954d09 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sat, 10 Sep 2011 04:43:27 +0530 Subject: [PATCH] solve bug with clashing model names --- itf/app/models.py | 16 ++++++++++++++-- itf/bestpractices/models.py | 30 +++++++++++++++++++++++++++++- itf/festival/models.py | 33 +++++++++++++++++++++++++++++++++ itf/static/js/insidepage.js | 1 + 4 files changed, 77 insertions(+), 3 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index 6b3197e..0de33c3 100644 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -15,6 +15,13 @@ def splitSearch(string): ret.append(word) return ret +#i see the point of this function, but please clean it up: refer to 'except MultipleObjectsReturned' to see why this is here. +def get_real_ctype(module_name): + for c in ContentType.objects.filter(model=module_name): + if c.is_itf_model == True: + return c + return None + class ItfModel(models.Model): fts_fields = [] fk_filters = [] @@ -22,7 +29,7 @@ class ItfModel(models.Model): sort_fields = [] hasComments = True title_field = "title" - + is_itf_model = True class Meta: abstract = True @@ -37,7 +44,11 @@ class ItfModel(models.Model): return self.get(self.title_field) def get_tab(self): - ctype = ContentType.objects.get(model=self.__class__._meta.module_name) + try: + ctype = ContentType.objects.get(model=self.__class__._meta.module_name) + except MultipleObectsReturned: #FUCKING way ugly hack to get clashing model ctype names with django internal models working (get_real_ctypes simply checks, if there are multiple content objects with the same 'module_name', which one is_itf_model, and returns that). + ctype = get_real_ctype(self.__class__m.meta.module_name) + modelextra = ModelExtra.objects.filter(model=ctype)[0] tab = ModuleTab.objects.filter(model=modelextra)[0] return tab @@ -53,6 +64,7 @@ class ItfModel(models.Model): return None + def get_main_image(self): return { 'url': '', diff --git a/itf/bestpractices/models.py b/itf/bestpractices/models.py index 09ae5f4..edb51c0 100644 --- a/itf/bestpractices/models.py +++ b/itf/bestpractices/models.py @@ -103,6 +103,14 @@ class BestPracticeFAQ(ItfModel): def __unicode__(self): return self.question + def list_dict(self): + return { + 'id': self.id, + 'question': self.question, + 'answer': self.answer, + } + + class BestPracticeCategory(models.Model): name = models.CharField(max_length=256) description = models.TextField(blank=True) @@ -147,7 +155,7 @@ class BestPracticeImage(models.Model): def get_thumb(self, max_width='200'): return self.image.url #FIXME!! -class Guideline(models.Model): +class Guideline(ItfModel): title = models.CharField(max_length=512) text = models.TextField() @@ -157,6 +165,19 @@ class Guideline(models.Model): 'text': self.text } + def list_dict(self): + return { + 'id': self.id, + 'title': self.title, + } + + def info_dict(self): + return { + 'id': self.id, + 'title': self.title, + 'text': self.text + } + def __unicode__(self): return self.title @@ -171,6 +192,13 @@ class Glossary(models.Model): 'definition': self.definition } + def list_dict(self): + return { + 'id': self.id, + 'term': self.term, + 'definition': self.definition + } + def __unicode__(self): return self.term diff --git a/itf/festival/models.py b/itf/festival/models.py index 1499b65..86d5120 100644 --- a/itf/festival/models.py +++ b/itf/festival/models.py @@ -37,9 +37,37 @@ class Meeting(ItfModel): slug = models.SlugField() fts_fields = ['title', 'intro'] + def preview_dict(self): + return { + 'id': self.id, + 'title': self.title, + } + def __unicode__(self): return self.title + def info_dict(self): + meeting_data = {} + meeting_data['meeting'] = self + meeting_id = self.id +# meeting_data['sessions'] = Session.objects.filter(day__meeting__id=meeting_id) # get meetings session objs + meeting_data['talks'] = Talk.objects.filter(session__day__meeting__id=meeting_id) + meeting_data['images'] = Image.objects.filter(meeting__id=meeting_id) + meeting_data['sessions'] = Session.objects.filter(day__meeting__id=meeting_id).order_by("day").order_by("session_no") + meeting_data['documents'] = Document.objects.filter(meeting__id=meeting_id).exclude(talk__isnull=False) + + for s in meeting_data['sessions']: + s.talks = Talk.objects.select_related('image', 'audio', 'document').filter(session__id=s.id) + for t in s.talks: + t.images = Image.objects.filter(talk__id=t.id) + t.documents = Document.objects.filter(talk__id=t.id) + t.audio = Audio.objects.filter(talk__id=t.id) + t.video = Video.objects.filter(talk__id=t.id) + + meeting_data['imagegallery'] = Image.objects.filter(meeting__id=meeting_id) + meeting_data['participants'] = Participant.objects.filter(meeting__id=meeting_id).order_by('name') + return meeting_data + class Participant(models.Model): name = models.CharField(max_length=255) title = models.CharField(max_length=255, blank=True, null=True) @@ -146,6 +174,11 @@ class Document(ItfModel): def __unicode__(self): return self.title + @classmethod + def get_qset(kls): + return kls.objects.filter(is_resource=True) + + class Project(ItfModel): title = models.CharField(max_length=255) intro = models.TextField(blank=True, null=True) diff --git a/itf/static/js/insidepage.js b/itf/static/js/insidepage.js index 55ac193..4bea13f 100644 --- a/itf/static/js/insidepage.js +++ b/itf/static/js/insidepage.js @@ -49,6 +49,7 @@ $(function() { 'page_no': 1 }, function(data) { $('#loadingList').hide(); + for (var i=0; i