search, etc

This commit is contained in:
Sanj 2011-10-10 16:00:18 +05:30
parent 8d4d1f0a0e
commit ca35d9c890
9 changed files with 87 additions and 22 deletions

View File

@ -75,7 +75,7 @@ class ItfModel(models.Model):
def get_main_image(self): def get_main_image(self):
main_image = self.main_image() main_image = self.main_image()
if main_image is not None: if main_image is not None:
imgfield = main_image.image imgfield = main_image
elif self.get_modelextra().default_image: elif self.get_modelextra().default_image:
imgfield = self.get_modelextra().default_image imgfield = self.get_modelextra().default_image
else: else:
@ -86,9 +86,9 @@ class ItfModel(models.Model):
except: except:
thumb = '' thumb = ''
else: else:
thumb = '' thumb = '' # Add default image for site
return { return {
'thumb': thumb 'thumb': thumb
} }
@ -229,10 +229,11 @@ class ItfModel(models.Model):
def get_list(kls, data): def get_list(kls, data):
options = { options = {
'page': 1, 'page': 1,
'count': 12, 'count': 20,
'search': '', 'search': '',
'sort': [], 'sort': [],
'range': [0,50] 'range': [0,50],
'object_id': False
} }
options.update(data) options.update(data)
ret = [] ret = []
@ -243,6 +244,15 @@ class ItfModel(models.Model):
except: except:
qset = kls.objects.all() 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'] search = options['search']
if search != '': if search != '':
qset = kls.fts(qset, search) qset = kls.fts(qset, search)

View File

@ -50,7 +50,8 @@ class BestPractice(ItfModel):
def main_image(self): def main_image(self):
imgs = self.get_images() imgs = self.get_images()
if len(imgs) > 0: if len(imgs) > 0:
return imgs[0] img = imgs[0]
return img.image
else: else:
return None return None

View File

@ -21,4 +21,11 @@ class BestPracticeIndex(SearchIndex):
return Note.objects.filter(pub_date__lte=datetime.datetime.now()) 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(BestPractice, BestPracticeIndex)
site.register(Guideline, GuidelineIndex)

View File

@ -49,6 +49,10 @@ class Meeting(ItfModel):
def list_dict(self): def list_dict(self):
return self.preview_dict() return self.preview_dict()
def main_image(self):
img = Image.objects.filter(meeting=self)[0]
return img.file
def info_dict(self): def info_dict(self):
meeting_data = {} meeting_data = {}
meeting_data['meeting'] = self meeting_data['meeting'] = self

View File

@ -46,7 +46,7 @@ class ModuleTab(models.Model):
'title': self.title, 'title': self.title,
'text': self.text, 'text': self.text,
'has_list': self.model.has_list, '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()] 'sorts': [s.get_dict() for s in self.model.modelsort_set.all()]
} }

View File

@ -29,7 +29,7 @@ def get_tab(request):
def get_list(request): def get_list(request):
tab_slug = request.GET.get("tab", "") tab_slug = request.GET.get("tab", "")
tab = get_object_or_404(ModuleTab, slug=tab_slug) tab = get_object_or_404(ModuleTab, slug=tab_slug)
object_id = request.GET.get("object_id", False)
sortString = request.GET.get("sort", "") sortString = request.GET.get("sort", "")
if sortString == "" or sortString == 'null': if sortString == "" or sortString == 'null':
sortArray = [] sortArray = []
@ -45,7 +45,8 @@ def get_list(request):
'search': request.GET.get("search", ""), 'search': request.GET.get("search", ""),
'sort': sortArray, 'sort': sortArray,
'page': request.GET.get("page", 1), '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) object_list = tab.get_list(list_options)
return render_to_json_response(object_list) return render_to_json_response(object_list)

View File

@ -106,7 +106,7 @@ $(function() {
// 'page_no': 1 // 'page_no': 1
}, function(data) { }, function(data) {
// $('#loadingList').hide(); // $('#loadingList').hide();
stopListLoading(data.page); // stopListLoading(data.page);
/* begin if for has_list, ideally make into separate render function */ /* begin if for has_list, ideally make into separate render function */
if (data.has_list) { if (data.has_list) {
/* handle sort options on list */ /* handle sort options on list */
@ -120,9 +120,10 @@ $(function() {
$select.append($opt); $select.append($opt);
} }
/* end handle sort */ /* end handle sort */
/* handle displaying initial list on page */ /* handle displaying initial list on page */
displayList(data.page.items); $('#listForm').submit();
// displayList(data.page.items);
/* end display initial list */ /* end display initial list */
} else { } 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. 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) { function doState(queryData) {
// console.log(queryData); // console.log(queryData);
// var tab_slug = queryData.tab; // var tab_slug = queryData.tab;
// alert(tab_slug); // 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 == '') { if (queryData.tab == undefined || queryData.tab == '') {
// alert("foo"); // alert("foo");
var $tab = $('.defaultTab'); var $tab = $('.defaultTab');
@ -204,6 +226,7 @@ function doState(queryData) {
$tab = $('.defaultTab'); $tab = $('.defaultTab');
} }
} }
$tab.click(); $tab.click();
} }
@ -247,7 +270,7 @@ function QueryStringToJSON(qstring) {
function displayList(items) { function displayList(items) {
var state = QueryStringToJSON(History.getState().hash); var state = QueryStringToJSON(History.getState().hash);
console.log(state); // console.log(state);
for (var i=0; i<items.length; i++) { for (var i=0; i<items.length; i++) {
var $li = getLi(items[i]); var $li = getLi(items[i]);
$('#listLeft ul').append($li); $('#listLeft ul').append($li);
@ -255,7 +278,12 @@ function displayList(items) {
if (state.object_id == undefined || state.object_id == '') { if (state.object_id == undefined || state.object_id == '') {
$('#listLeft ul li a').eq(0).click(); $('#listLeft ul li a').eq(0).click();
} else { } else {
$('#listLeft ul li a[data-id=' + state.object_id + ']').click(); //FIXME: FIXME!!!!!!!!!! var $a = $('#listLeft ul li a[data-id=' + state.object_id + ']');
if ($a.length > 0) {
$a.click();
} else {
$('#listLeft ul li a').eq(0).click();
}
} }
} }
@ -338,9 +366,10 @@ function getNoListItemHtml(item) {
function getSearchFormJSON() { function getSearchFormJSON() {
return { return {
'tab': $('.innerSelected').attr("data-slug"), 'tab': $('.innerSelected').attr("data-slug"),
'sort': $('#orderBySelect').val(), 'sort': $('#orderBySelect').val() != '' ? $('#orderBySelect').val() : '',
'search': $('#searchList').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"}); 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;
}
});
}

View File

@ -17,7 +17,7 @@
<li><a href="#prereading">Pre-Reading</a></li> <li><a href="#prereading">Pre-Reading</a></li>
{% endifnotequal %} {% endifnotequal %}
{% ifnotequal imagegallery|length 0 %} {% ifnotequal imagegallery|length 0 %}
<!-- <li><a href="#gallery">Gallery</a></li> --> <li><a href="#gallery">Gallery</a></li>
{% endifnotequal %} {% endifnotequal %}
{% ifnotequal participants|length 0 %} {% ifnotequal participants|length 0 %}
<li><a href="#participants">Participants</a></li> <li><a href="#participants">Participants</a></li>
@ -102,21 +102,23 @@
</div> </div>
{% endifnotequal %} {% endifnotequal %}
{% comment %}
{% ifnotequal imagegallery|length 0 %} {% ifnotequal imagegallery|length 0 %}
<div id="gallery"> <div id="gallery">
<h4 class="tabTitle">Gallery</h4> <h4 class="tabTitle">Gallery</h4>
<div> <div>
{% load thumbnail %} {% load thumbnail %}
{% for i in imagegallery %} {% for i in imagegallery %}
<a href="{% thumbnail i.file 600x500 quality=60 %}" title="{{i.title}}" class="thickbox" rel="gall"> {% thumbnail i.file "600x500" crop="center" as big %}
<img src="{% thumbnail i.file 100x100 autocrop crop %}" /> {% thumbnail i.file "100x100" crop="center" as thumb %}
<a href="{{ big.url }}" title="{{i.title}}" class="thickbox" rel="gall">
<img src="{{ thumb.url }}" />
</a> </a>
{% endthumbnail %}
{% endthumbnail %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>
{% endifnotequal %} {% endifnotequal %}
{% endcomment %}
{% ifnotequal participants|length 0 %} {% ifnotequal participants|length 0 %}
<div id="participants" class="tab_content"> <div id="participants" class="tab_content">

View File

@ -82,7 +82,7 @@
--> -->
</select> </select>
<input id="page_no" name="page_no" type="hidden" value="1" /> <input id="page_no" name="page_no" type="hidden" value="1" />
<input id="object_id" name="object_id" type="hidden" value="" />
<input type="text" placeholder="search list" id="searchList" name="field" class="searchListField"/> <input type="text" placeholder="search list" id="searchList" name="field" class="searchListField"/>
<img src="/static/images/noel/search-icon.png" width="18" height="14" alt="search-icon" id="searchListIcon"> <img src="/static/images/noel/search-icon.png" width="18" height="14" alt="search-icon" id="searchListIcon">
<span id="pageDisplay" style="display:none;">Page <span id="currPageNo">1</span> of <span id="totalPages">10</span></span> <span id="pageDisplay" style="display:none;">Page <span id="currPageNo">1</span> of <span id="totalPages">10</span></span>