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):
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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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()]
}

View File

@ -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)

View File

@ -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<items.length; i++) {
var $li = getLi(items[i]);
$('#listLeft ul').append($li);
@ -255,7 +278,12 @@ function displayList(items) {
if (state.object_id == undefined || state.object_id == '') {
$('#listLeft ul li a').eq(0).click();
} 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() {
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;
}
});
}

View File

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

View File

@ -82,7 +82,7 @@
-->
</select>
<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"/>
<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>