From 152d7ed9dce00ca6c0391080e9109f7cb54245af Mon Sep 17 00:00:00 2001 From: Sanj Date: Sat, 10 Sep 2011 07:10:47 +0530 Subject: [PATCH] sorting works, pagination works. --- itf/app/models.py | 15 ++-- itf/insidepages/models.py | 19 ++++ itf/insidepages/urls.py | 1 + itf/insidepages/views.py | 22 ++++- itf/static/js/insidepage.js | 134 ++++++++++++++++++++++++++--- itf/templates/noel/insidepage.html | 6 +- 6 files changed, 178 insertions(+), 19 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index fbad0ae..09407e2 100644 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -205,16 +205,16 @@ class ItfModel(models.Model): @classmethod def get_list(kls, data): options = { - 'page_no': 1, - 'list_size': 12, + 'page': 1, + 'count': 12, 'search': '', 'sort': [], 'range': [0,50] } options.update(data) ret = [] - page_no = options['page_no'] - list_size = options['list_size'] + page_no = options['page'] + list_size = options['count'] try: qset = kls.get_qset() except: @@ -225,6 +225,7 @@ class ItfModel(models.Model): qset = kls.fts(qset, search) sort = options['sort'] + if sort != []: for s in sort: if s['operator'] == '-': @@ -249,7 +250,11 @@ class ItfModel(models.Model): for r in results.object_list: ret.append(r.list_dict()) - return ret + return { + 'page_no': page_no, + 'num_pages': paginator.num_pages, + 'items': ret + } @classmethod def get_qset(kls): diff --git a/itf/insidepages/models.py b/itf/insidepages/models.py index 4052206..8e438d1 100644 --- a/itf/insidepages/models.py +++ b/itf/insidepages/models.py @@ -32,9 +32,22 @@ class ModuleTab(models.Model): def model_class(self): return self.model.model.model_class() + def get_absolute_url(self): #FIXME!! + return self.slug + def get_list(self, options): return self.model_class().get_list(options) + def get_dict(self): + return { + 'id': self.id, + 'slug': self.slug, + 'title': self.title, + 'text': self.text, + 'has_list': self.model.has_list, + 'page': self.get_list({}), + 'sorts': [s.get_dict() for s in self.model.modelsort_set.all()] + } class ModelExtra(models.Model): model = models.ForeignKey(ContentType, help_text="Chose from the list of death at your own peril.") @@ -57,6 +70,12 @@ class ModelSort(models.Model): def __unicode__(self): return self.friendly_name + def get_dict(self): + return { + 'operator': self.operator, + 'field_name': self.field_name, + 'friendly_name': self.friendly_name + } class ModelButton(models.Model): name = models.CharField(max_length=64, help_text="Name of button, eg. Download") diff --git a/itf/insidepages/urls.py b/itf/insidepages/urls.py index 875c3b3..e6e8344 100644 --- a/itf/insidepages/urls.py +++ b/itf/insidepages/urls.py @@ -4,5 +4,6 @@ import views urlpatterns = patterns('', (r'^get_list$', views.get_list), (r'^get_details$', views.get_details), + (r'^get_tab$', views.get_tab), (r'^(?P.*)$', views.main), ) diff --git a/itf/insidepages/views.py b/itf/insidepages/views.py index 0e51643..28a50cd 100644 --- a/itf/insidepages/views.py +++ b/itf/insidepages/views.py @@ -17,15 +17,33 @@ def main(request, module_slug): 'tabs': tabs[1:] }) return render_to_response("noel/insidepage.html", context) + +def get_tab(request): + tab_id = request.GET.get("tab_id", 0) + tab = get_object_or_404(ModuleTab, pk=tab_id) + return render_to_json_response(tab.get_dict()) def get_list(request): tab_id = request.GET.get("tab_id", 0) tab = get_object_or_404(ModuleTab, pk=tab_id) + + sortString = request.GET.get("sort", "") + if sortString == "": + sortArray = [] + else: + sortOperator = sortString[0] + sortField = sortString[1:] + sortArray = [{ + 'operator': sortOperator, + 'key': sortField + }] + list_options = { 'search': request.GET.get("search", ""), - 'sort': request.GET.get("sort", ""), - 'page': request.GET.get("page_no", 1) + '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_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 4bea13f..1b215e9 100644 --- a/itf/static/js/insidepage.js +++ b/itf/static/js/insidepage.js @@ -19,6 +19,13 @@ $('#listLeft ul li a').live("click", function() { return false; }); + +/* Get a jquery