From 5fb754bec8f9a294548f89303f88604eaa116243 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sun, 10 Apr 2011 07:30:43 +0530 Subject: [PATCH] boxes successfully render on page --- itf/app/models.py | 13 +++++-- itf/bestpractices/models.py | 11 ++---- itf/boxes/models.py | 2 +- itf/erang_organised/models.py | 24 ++++++++++++- itf/festival/models.py | 45 +++++++++++++++++++++-- itf/static/js/itf/app.js | 43 +++++++++++++--------- itf/static/js/itf/boxes.js | 66 +++++++++++++++++++--------------- itf/static/js/itf/construct.js | 2 +- itf/static/js/itf/widgets.js | 3 +- itf/templates/index.html | 3 ++ 10 files changed, 150 insertions(+), 62 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index 0604ddf..51a6e5e 100644 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -155,7 +155,10 @@ class ItfModel(models.Model): ret = [] page_no = options['page_no'] list_size = options['list_size'] - qset = kls.objects.all() + try: + qset = kls.get_qset() + except: + qset = kls.objects.all() search = options['search'] if search != '': @@ -168,7 +171,7 @@ class ItfModel(models.Model): operator = '-' else: operator = '' - sort = operator + s['ey'] + sort = operator + s['key'] qset = qset.order_by(sort) r0 = options['range'][0] @@ -178,6 +181,12 @@ class ItfModel(models.Model): ret.append(r.list_dict()) return ret + @classmethod + def get_qset(kls): + ''' + Override this method in your model class to define a custom queryset instead of objects.all(), for instance, to always exclude unpublished items. + ''' + raise NotImplementedError def getField(fields, name): for f in fields: diff --git a/itf/bestpractices/models.py b/itf/bestpractices/models.py index 4b0f1d1..4335602 100644 --- a/itf/bestpractices/models.py +++ b/itf/bestpractices/models.py @@ -19,17 +19,10 @@ class BestPractice(ItfModel): added = models.DateTimeField(auto_now_add=True, null=True) modified = models.DateTimeField(auto_now=True, null=True) - fts_fields = ['title', 'story', 'guideline', 'law', 'theatre', 'quick_howto'] - related_models = ["bestpracticestory", "bestpracticelink", "bestpracticeimage"] - extra_buttons = [ - { - 'title': 'Foo button', - 'mouseover': 'blah', - 'dialog': '' - } - ] + fts_fields = ['title', 'story', 'guideline', 'law', 'theatre', 'quick_howto'] fk_filters = ['category'] sort_fields = ['title'] + add_form = "BestPracticeForm" getters = ['info_dict', 'list_dict', 'no_of_stories'] diff --git a/itf/boxes/models.py b/itf/boxes/models.py index 2f30f20..f4f4d66 100644 --- a/itf/boxes/models.py +++ b/itf/boxes/models.py @@ -22,7 +22,7 @@ class ModelExtra(models.Model): return { 'id': self.id, 'module': self.model.model_class()._meta.app_label, - 'model': self.model.model, + 'model': self.model.model_class().__name__, 'has_comments': self.has_comments, # 'info': self.info, 'friendly_name': self.friendly_name, diff --git a/itf/erang_organised/models.py b/itf/erang_organised/models.py index 18cd738..0e4022b 100644 --- a/itf/erang_organised/models.py +++ b/itf/erang_organised/models.py @@ -1,13 +1,35 @@ from django.db import models from django.contrib.comments.signals import comment_was_posted from django.core.mail import send_mail +from app.models import ItfModel -class Issue(models.Model): +class Issue(ItfModel): title = models.CharField(max_length=255) summary = models.TextField(blank=True, null=True) date = models.DateField() html = models.TextField(blank=True) + + fts_fields = ['title', 'summary'] + fk_filters = [] + + def preview_dict(self): + return { + 'id': self.id, + 'title': self.title, + 'summary': self.summary, + } + + def info_dict(self): + d = self.preview_dict() + d['html'] = self.html + return d + def list_dict(self): + return { + 'id': self.id, + 'title': self.title + } + def __unicode__(self): return self.title diff --git a/itf/festival/models.py b/itf/festival/models.py index 30a6ec2..1499b65 100644 --- a/itf/festival/models.py +++ b/itf/festival/models.py @@ -114,7 +114,7 @@ class Image(models.Model): def __unicode__(self): return self.title -class Document(models.Model): +class Document(ItfModel): title = models.CharField(max_length=255) intro = RichTextField(blank=True, null=True) file = models.FileField(upload_to='upload/docs', blank=True, null=True) @@ -122,16 +122,57 @@ class Document(models.Model): talk = models.ForeignKey('Talk', blank=True, null=True) is_resource = models.BooleanField() + fts_fields = ['title', 'intro'] + fk_filters = [] + sort_fields = ['title'] + + def preview_dict(self): + return { + 'id': self.id, + 'title': self.title, + 'intro': self.intro, + 'file': self.file.url + } + + def list_dict(self): + return { + 'id': self.id, + 'title': self.title + } + + def info_dict(self): + return self.preview_dict() + def __unicode__(self): return self.title -class Project(models.Model): +class Project(ItfModel): title = models.CharField(max_length=255) intro = models.TextField(blank=True, null=True) start_date = models.DateField(blank=True, null=True) end_date = models.DateField(blank=True, null=True) slug = models.SlugField() + fts_fields = ['title', 'intro'] + fk_filters = [] + sort_fields = ['title', 'start_date'] + + def preview_dict(self): + return { + 'id': self.id, + 'title': self.title, + 'intro': self.intro + } + + def info_dict(self): + return self.preview_dict() + + def list_dict(self): + return { + 'id': self.id, + 'title': self.title + } + def __unicode__(self): return self.title diff --git a/itf/static/js/itf/app.js b/itf/static/js/itf/app.js index cc3572e..3e28bb6 100644 --- a/itf/static/js/itf/app.js +++ b/itf/static/js/itf/app.js @@ -8,12 +8,6 @@ app.launch(function(data) { Ox.theme("classic"); Ox.print(data); - app.$body = $('body'); - app.$document = $(document); - app.$window = $(window); - app.$window.resize(function() { - ITF.setSizes(); - }); /* app.user = data.user; app.config = data.config; @@ -24,21 +18,36 @@ app.launch(function(data) { app.constructors = ['wrapper', 'headerPanel', 'mainPanel', 'leftPanel', 'cityPicker', 'calendarBox', 'currentEventsList', 'middlePanel', 'middleTopPanel', 'newsfeedBox', 'aboutBox', 'itfBox', 'middleBottomPanel', 'erangBox', 'scriptArchiveBox', 'bestPracticesBox', 'biblioBox', 'offersNeedsBox', 'surveysBox', 'rightPanel', 'searchBox', 'loginBox', 'previewBox', 'footerPanel'] */ + app.$ui = {}; + app.$body = $('body'); + app.$document = $(document); + app.$window = $(window); /* Ox.each(app.constructors, function(i, v) { app.$ui[v] = app.construct[v](); }); */ - var wrapper = app.construct.wrapper(data.page); - app.$body.css({'opacity': 0}); - //FIXME: user handling should be cleaner? - if (data.user.level != 'guest') { - ITF.login(data); - } - wrapper.appendTo(app.$body); - ITF.setSizes(); - app.$body.animate({ - 'opacity': 1 - }, 2000); +// Ox.print("BOO", data); + app.api.getPage({}, function(data) { + var wrapper = app.construct.wrapper(data.data); + app.$body.css({'opacity': 0}); + //FIXME: user handling should be cleaner? + + wrapper.appendTo(app.$body); +/* + if (data.user.level != 'guest') { + ITF.login(data); + } +*/ +/* + app.$window.resize(function() { + ITF.setSizes(); + }); + ITF.setSizes(); +*/ + app.$body.animate({ + 'opacity': 1 + }, 2000); + }); }); diff --git a/itf/static/js/itf/boxes.js b/itf/static/js/itf/boxes.js index bb5c744..22462f5 100644 --- a/itf/static/js/itf/boxes.js +++ b/itf/static/js/itf/boxes.js @@ -1,38 +1,49 @@ /* */ - Ox.ItfPage = function(page, parentPanel) { var panelItems = []; - for (var i=0; i < page.panels.displayed.length; i++) { - var t = page.panels.displayed[i]; + Ox.print("page", page); + GLOB_PAGE = page; + for (var i=0; i < page.displayed.length; i++) { + var t = page.displayed[i]; var displayed = true; var panel = new Ox.ItfPanel(t, displayed); - panelItems.push(panel); + panelItems.push({ + 'element': panel, + 'size': 300 + }); } var hiddenPanel = new Ox.ItfHiddenPanelContainer(); - for (var j=0; j < page.panels.hidden.length; j++) { - var t = page.panels.hidden[j]; + for (var j=0; j < page.hidden.length; j++) { + var t = page.hidden[j]; var displayed = false; var panel = new Ox.ItfPanel(t, displayed); hiddenPanel.addPanel(panel); } - var that = app.ui['ItfPage'] = new Ox.SplitPanel({ + panelItems.push({ + 'element': hiddenPanel, + 'size': 30 + }); + var that = app.$ui['ItfPage'] = new Ox.SplitPanel({ orientation: 'vertical', id: 'ItfPage', elements: panelItems }); return that; -} +}; Ox.ItfPanel = function(panelData, displayed) { var items = []; - var id = panelData.title; + var id = "Panel" + panelData.id; for (var i=0; i < panelData.boxes.length; i++) { var t = panelData.boxes[i]; var box = new Ox.ItfBox(t); - items.push(box); + items.push({ + 'element': box, + 'size': 512 + }); } var that = new Ox.SplitPanel({ orientation: 'horizontal', @@ -40,11 +51,12 @@ Ox.ItfPanel = function(panelData, displayed) { elements: items }); that.displayed = displayed; + return that; }; -Ox.HiddenPanelContainer = function() { - +Ox.ItfHiddenPanelContainer = function() { + return new Ox.Element(); }; @@ -55,27 +67,26 @@ Ox.ItfBox = function(boxData) { 'id': boxData.itfId, 'title': boxData.title }; - var that = app.ui[boxData.itfId] = new Ox.Element(options, self); + var that = app.$ui[boxData.itfId] = new Ox.Element(options, self); var $titlebar = new Ox.Bar({ orientation: 'horizontal', - size: '24 + size: 24 }).appendTo(that); var $title = new Ox.Element() .addClass('OxTitle') - .html(title) + .html(boxData.title) .appendTo($titlebar); var $buttons = new Ox.Element().appendTo($title).css({'position': 'absolute', 'top': '1px', 'right': '1px'}); var boxButtons = Ox.merge(ItfBoxTypes[boxData.type].buttons, boxData.extra_buttons); for (var i=0; i + + +