solve bug with clashing model names
This commit is contained in:
parent
7dffe01de0
commit
d2bbe35156
|
@ -15,6 +15,13 @@ def splitSearch(string):
|
||||||
ret.append(word)
|
ret.append(word)
|
||||||
return ret
|
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):
|
class ItfModel(models.Model):
|
||||||
fts_fields = []
|
fts_fields = []
|
||||||
fk_filters = []
|
fk_filters = []
|
||||||
|
@ -22,7 +29,7 @@ class ItfModel(models.Model):
|
||||||
sort_fields = []
|
sort_fields = []
|
||||||
hasComments = True
|
hasComments = True
|
||||||
title_field = "title"
|
title_field = "title"
|
||||||
|
is_itf_model = True
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
@ -37,7 +44,11 @@ class ItfModel(models.Model):
|
||||||
return self.get(self.title_field)
|
return self.get(self.title_field)
|
||||||
|
|
||||||
def get_tab(self):
|
def get_tab(self):
|
||||||
|
try:
|
||||||
ctype = ContentType.objects.get(model=self.__class__._meta.module_name)
|
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]
|
modelextra = ModelExtra.objects.filter(model=ctype)[0]
|
||||||
tab = ModuleTab.objects.filter(model=modelextra)[0]
|
tab = ModuleTab.objects.filter(model=modelextra)[0]
|
||||||
return tab
|
return tab
|
||||||
|
@ -53,6 +64,7 @@ class ItfModel(models.Model):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_main_image(self):
|
def get_main_image(self):
|
||||||
return {
|
return {
|
||||||
'url': '',
|
'url': '',
|
||||||
|
|
|
@ -103,6 +103,14 @@ class BestPracticeFAQ(ItfModel):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.question
|
return self.question
|
||||||
|
|
||||||
|
def list_dict(self):
|
||||||
|
return {
|
||||||
|
'id': self.id,
|
||||||
|
'question': self.question,
|
||||||
|
'answer': self.answer,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class BestPracticeCategory(models.Model):
|
class BestPracticeCategory(models.Model):
|
||||||
name = models.CharField(max_length=256)
|
name = models.CharField(max_length=256)
|
||||||
description = models.TextField(blank=True)
|
description = models.TextField(blank=True)
|
||||||
|
@ -147,7 +155,7 @@ class BestPracticeImage(models.Model):
|
||||||
def get_thumb(self, max_width='200'):
|
def get_thumb(self, max_width='200'):
|
||||||
return self.image.url #FIXME!!
|
return self.image.url #FIXME!!
|
||||||
|
|
||||||
class Guideline(models.Model):
|
class Guideline(ItfModel):
|
||||||
title = models.CharField(max_length=512)
|
title = models.CharField(max_length=512)
|
||||||
text = models.TextField()
|
text = models.TextField()
|
||||||
|
|
||||||
|
@ -157,6 +165,19 @@ class Guideline(models.Model):
|
||||||
'text': self.text
|
'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):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
@ -171,6 +192,13 @@ class Glossary(models.Model):
|
||||||
'definition': self.definition
|
'definition': self.definition
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def list_dict(self):
|
||||||
|
return {
|
||||||
|
'id': self.id,
|
||||||
|
'term': self.term,
|
||||||
|
'definition': self.definition
|
||||||
|
}
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.term
|
return self.term
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,37 @@ class Meeting(ItfModel):
|
||||||
slug = models.SlugField()
|
slug = models.SlugField()
|
||||||
fts_fields = ['title', 'intro']
|
fts_fields = ['title', 'intro']
|
||||||
|
|
||||||
|
def preview_dict(self):
|
||||||
|
return {
|
||||||
|
'id': self.id,
|
||||||
|
'title': self.title,
|
||||||
|
}
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
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):
|
class Participant(models.Model):
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
title = models.CharField(max_length=255, blank=True, null=True)
|
title = models.CharField(max_length=255, blank=True, null=True)
|
||||||
|
@ -146,6 +174,11 @@ class Document(ItfModel):
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_qset(kls):
|
||||||
|
return kls.objects.filter(is_resource=True)
|
||||||
|
|
||||||
|
|
||||||
class Project(ItfModel):
|
class Project(ItfModel):
|
||||||
title = models.CharField(max_length=255)
|
title = models.CharField(max_length=255)
|
||||||
intro = models.TextField(blank=True, null=True)
|
intro = models.TextField(blank=True, null=True)
|
||||||
|
|
|
@ -49,6 +49,7 @@ $(function() {
|
||||||
'page_no': 1
|
'page_no': 1
|
||||||
}, function(data) {
|
}, function(data) {
|
||||||
$('#loadingList').hide();
|
$('#loadingList').hide();
|
||||||
|
|
||||||
for (var i=0; i<data.length; i++) {
|
for (var i=0; i<data.length; i++) {
|
||||||
var $li = getLi(data[i]);
|
var $li = getLi(data[i]);
|
||||||
$('#listLeft ul').append($li);
|
$('#listLeft ul').append($li);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user