From ca35d9c890d131456a0ac560d8ec5b178a4004f2 Mon Sep 17 00:00:00 2001 From: Sanj Date: Mon, 10 Oct 2011 16:00:18 +0530 Subject: [PATCH] search, etc --- itf/app/models.py | 20 ++++++-- itf/bestpractices/models.py | 3 +- itf/bestpractices/search_indexes.py | 7 +++ itf/festival/models.py | 4 ++ itf/insidepages/models.py | 2 +- itf/insidepages/views.py | 5 +- itf/static/js/insidepage.js | 54 ++++++++++++++++++--- itf/templates/modules/festival/meeting.html | 12 +++-- itf/templates/noel/insidepage.html | 2 +- 9 files changed, 87 insertions(+), 22 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index 97d5abf..99a1282 100755 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -75,7 +75,7 @@ class ItfModel(models.Model): def get_main_image(self): main_image = self.main_image() if main_image is not None: - imgfield = main_image.image + imgfield = main_image elif self.get_modelextra().default_image: imgfield = self.get_modelextra().default_image else: @@ -86,9 +86,9 @@ class ItfModel(models.Model): except: thumb = '' else: - thumb = '' + thumb = '' # Add default image for site return { - 'thumb': thumb + 'thumb': thumb } @@ -229,10 +229,11 @@ class ItfModel(models.Model): def get_list(kls, data): options = { 'page': 1, - 'count': 12, + 'count': 20, 'search': '', 'sort': [], - 'range': [0,50] + 'range': [0,50], + 'object_id': False } options.update(data) ret = [] @@ -243,6 +244,15 @@ class ItfModel(models.Model): except: qset = kls.objects.all() + if options['object_id'] != False and options['object_id'] != '': + object_id = options['object_id'] + qset = qset.exclude(pk=object_id) + try: + obj = kls.objects.get(pk=object_id) + ret.append(obj.list_dict()) + except: + pass + search = options['search'] if search != '': qset = kls.fts(qset, search) diff --git a/itf/bestpractices/models.py b/itf/bestpractices/models.py index 6262cfe..1305793 100755 --- a/itf/bestpractices/models.py +++ b/itf/bestpractices/models.py @@ -50,7 +50,8 @@ class BestPractice(ItfModel): def main_image(self): imgs = self.get_images() if len(imgs) > 0: - return imgs[0] + img = imgs[0] + return img.image else: return None diff --git a/itf/bestpractices/search_indexes.py b/itf/bestpractices/search_indexes.py index f371314..558f0b3 100755 --- a/itf/bestpractices/search_indexes.py +++ b/itf/bestpractices/search_indexes.py @@ -21,4 +21,11 @@ class BestPracticeIndex(SearchIndex): return Note.objects.filter(pub_date__lte=datetime.datetime.now()) ''' +class GuidelineIndex(SearchIndex): + text = CharField(document=True, use_template=True) + title = CharField(model_attr='title') + txt = CharField(model_attr='text') + + site.register(BestPractice, BestPracticeIndex) +site.register(Guideline, GuidelineIndex) diff --git a/itf/festival/models.py b/itf/festival/models.py index d8686ba..a18d507 100755 --- a/itf/festival/models.py +++ b/itf/festival/models.py @@ -49,6 +49,10 @@ class Meeting(ItfModel): def list_dict(self): return self.preview_dict() + def main_image(self): + img = Image.objects.filter(meeting=self)[0] + return img.file + def info_dict(self): meeting_data = {} meeting_data['meeting'] = self diff --git a/itf/insidepages/models.py b/itf/insidepages/models.py index a9d2290..1d90a2d 100755 --- a/itf/insidepages/models.py +++ b/itf/insidepages/models.py @@ -46,7 +46,7 @@ class ModuleTab(models.Model): 'title': self.title, 'text': self.text, 'has_list': self.model.has_list, - 'page': self.get_list({}), +# 'page': self.get_list({}), 'sorts': [s.get_dict() for s in self.model.modelsort_set.all()] } diff --git a/itf/insidepages/views.py b/itf/insidepages/views.py index 2095b40..513fa70 100755 --- a/itf/insidepages/views.py +++ b/itf/insidepages/views.py @@ -29,7 +29,7 @@ def get_tab(request): def get_list(request): tab_slug = request.GET.get("tab", "") tab = get_object_or_404(ModuleTab, slug=tab_slug) - + object_id = request.GET.get("object_id", False) sortString = request.GET.get("sort", "") if sortString == "" or sortString == 'null': sortArray = [] @@ -45,7 +45,8 @@ def get_list(request): 'search': request.GET.get("search", ""), 'sort': sortArray, 'page': request.GET.get("page", 1), - 'count': request.GET.get("count", 12) #FIXME: make list_length either in settings.py or config per model + 'object_id': object_id, + 'count': request.GET.get("count", 15) #FIXME: make list_length either in settings.py or config per model } object_list = tab.get_list(list_options) return render_to_json_response(object_list) diff --git a/itf/static/js/insidepage.js b/itf/static/js/insidepage.js index b51ebc2..4abe1c4 100755 --- a/itf/static/js/insidepage.js +++ b/itf/static/js/insidepage.js @@ -106,7 +106,7 @@ $(function() { // 'page_no': 1 }, function(data) { // $('#loadingList').hide(); - stopListLoading(data.page); + // stopListLoading(data.page); /* begin if for has_list, ideally make into separate render function */ if (data.has_list) { /* handle sort options on list */ @@ -120,9 +120,10 @@ $(function() { $select.append($opt); } /* end handle sort */ - + /* handle displaying initial list on page */ - displayList(data.page.items); + $('#listForm').submit(); +// displayList(data.page.items); /* end display initial list */ } else { @@ -190,11 +191,32 @@ $(function() { /* this function will grow to be a monster. be gentle with it, ideally move state functions to a state namespace or so. +queryData: + object_id + tab + sort + search + page + */ function doState(queryData) { // console.log(queryData); // var tab_slug = queryData.tab; // alert(tab_slug); + + if (queryData.hasOwnProperty("page")) { + $('#page_no').val(queryData.page); + } + if (queryData.hasOwnProperty("search")) { + $('#searchList').val(queryData.search); + } + if (queryData.hasOwnProperty("object_id")) { + $('#object_id').val(queryData.object_id); + } + if (queryData.hasOwnProperty("sort")) { + $('#orderBySelect').selectOption(queryData.sort); + } + if (queryData.tab == undefined || queryData.tab == '') { // alert("foo"); var $tab = $('.defaultTab'); @@ -204,6 +226,7 @@ function doState(queryData) { $tab = $('.defaultTab'); } } + $tab.click(); } @@ -247,7 +270,7 @@ function QueryStringToJSON(qstring) { function displayList(items) { var state = QueryStringToJSON(History.getState().hash); - console.log(state); +// console.log(state); for (var i=0; i 0) { + $a.click(); + } else { + $('#listLeft ul li a').eq(0).click(); + } } } @@ -338,9 +366,10 @@ function getNoListItemHtml(item) { function getSearchFormJSON() { return { 'tab': $('.innerSelected').attr("data-slug"), - 'sort': $('#orderBySelect').val(), + 'sort': $('#orderBySelect').val() != '' ? $('#orderBySelect').val() : '', 'search': $('#searchList').val(), - 'page': $('#page_no').val() + 'page': $('#page_no').val(), + 'object_id': $('#object_id').val() } } @@ -359,3 +388,14 @@ jQuery.fn.formatTitle = function() { } this.css({'fontSize': fontSize + "px"}); } + +jQuery.fn.selectOption = function(value) { + var that = this; + var options = that.find('option'); + options.each(function() { + if ($(this).attr("value") == value) { + $(this).attr("selected", "selected"); + return; + } + }); +} diff --git a/itf/templates/modules/festival/meeting.html b/itf/templates/modules/festival/meeting.html index 3f57a5d..64e9ca0 100755 --- a/itf/templates/modules/festival/meeting.html +++ b/itf/templates/modules/festival/meeting.html @@ -17,7 +17,7 @@
  • Pre-Reading
  • {% endifnotequal %} {% ifnotequal imagegallery|length 0 %} - +
  • Gallery
  • {% endifnotequal %} {% ifnotequal participants|length 0 %}
  • Participants
  • @@ -102,21 +102,23 @@ {% endifnotequal %} -{% comment %} {% ifnotequal imagegallery|length 0 %} {% endifnotequal %} -{% endcomment %} {% ifnotequal participants|length 0 %}
    diff --git a/itf/templates/noel/insidepage.html b/itf/templates/noel/insidepage.html index 90d7cca..7776103 100755 --- a/itf/templates/noel/insidepage.html +++ b/itf/templates/noel/insidepage.html @@ -82,7 +82,7 @@ --> - + search-icon