From 6572afb7c8e1bc6fab56e03202da68c226e1651a Mon Sep 17 00:00:00 2001 From: Sanj Date: Thu, 13 Oct 2011 20:10:45 +0530 Subject: [PATCH] scriptbank models changes; add_form logic --- itf/app/models.py | 12 ++++++++++++ itf/bestpractices/models.py | 7 ++++++- itf/insidepages/views.py | 16 +++++++++++++-- itf/scriptbank/admin.py | 3 +-- itf/scriptbank/models.py | 21 +++++++++----------- itf/static/css/noel/inner.css | 5 +++++ itf/static/js/insidepage.js | 31 +++++++++++++++++++++++++++--- itf/templates/noel/insidepage.html | 18 ++++++++++++++++- 8 files changed, 92 insertions(+), 21 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index 99a1282..e170854 100755 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -50,6 +50,18 @@ class ItfModel(models.Model): tab = ModuleTab.objects.filter(model=modelextra)[0] return tab + @classmethod + def get_add_form(cls): + try: + formStr = cls.add_form +# cls = default_tab.model_class() + app_label = cls._meta.app_label + module = __import__(app_label + ".forms") + add_form = module.forms.__getattribute__(formStr) + return add_form + except: + return None + def get_modelextra(self): try: diff --git a/itf/bestpractices/models.py b/itf/bestpractices/models.py index 1305793..5af9faf 100755 --- a/itf/bestpractices/models.py +++ b/itf/bestpractices/models.py @@ -2,9 +2,12 @@ from django.db import models from tagging.fields import TagField from django.core.paginator import Paginator, InvalidPage, EmptyPage from app.models import ItfModel +from django.forms import ModelForm # from django.forms import # import forms + + class BestPractice(ItfModel): title = models.CharField(max_length=512) story = models.TextField() @@ -22,14 +25,15 @@ class BestPractice(ItfModel): 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'] def __unicode__(self): return str(self.id) + ": " + self.title + def info_dict(self): return { 'id': self.id, @@ -90,6 +94,7 @@ class BestPractice(ItfModel): def no_of_stories(self): return BestPracticeStory.objects.filter(bestpractice=self).count() + class BestPracticeDownload(models.Model): language = models.CharField(max_length=255) fil = models.FileField(upload_to="upload/bestpractices_downloads/") diff --git a/itf/insidepages/views.py b/itf/insidepages/views.py index 513fa70..5f0239a 100755 --- a/itf/insidepages/views.py +++ b/itf/insidepages/views.py @@ -8,10 +8,21 @@ def main(request, module_slug): m = get_object_or_404(Module, slug=module_slug) tabs = m.moduletab_set.all() default_tab = tabs[0] + try: + formStr = default_tab.model_class().add_form + has_add = True + add_form = default_tab.model_class().get_add_form() + except: + add_form = None + has_add = False + list_options = {} #get some options as GET params, etc. to potentially pass to get_list default_tab_list = default_tab.model_class().get_list(list_options) context = RequestContext(request, { 'title': m.title, + 'about': m.about, + 'has_add': has_add, + 'add_form': add_form(), 'default_tab': tabs[0], 'default_list': default_tab_list, 'default_sorts': default_tab.get_dict()['sorts'], @@ -24,8 +35,9 @@ def get_tab(request): tab_slug = request.GET.get("tab", "") tab = get_object_or_404(ModuleTab, slug=tab_slug) return render_to_json_response(tab.get_dict()) - - + + + def get_list(request): tab_slug = request.GET.get("tab", "") tab = get_object_or_404(ModuleTab, slug=tab_slug) diff --git a/itf/scriptbank/admin.py b/itf/scriptbank/admin.py index da6da18..e1baa92 100755 --- a/itf/scriptbank/admin.py +++ b/itf/scriptbank/admin.py @@ -8,8 +8,7 @@ class ScriptAdmin(admin.ModelAdmin): admin.site.register(Script, ScriptAdmin) -admin.site.register(LicenseAdapt) -admin.site.register(LicensePerform) +admin.site.register(License) admin.site.register(Review) admin.site.register(Downloader) diff --git a/itf/scriptbank/models.py b/itf/scriptbank/models.py index 17ca1f5..14e9361 100755 --- a/itf/scriptbank/models.py +++ b/itf/scriptbank/models.py @@ -9,6 +9,11 @@ GENRES = ( ('Comedy', 'Comedy'), ) +LICENSE_TYPE_CHOICES = ( + ('adapt', 'Adaptation License'), + ('perform', 'Performance License'), +) + LANGUAGE_CHOICES = ( ('en', 'English'), ('hi', 'Hindi'), @@ -30,8 +35,8 @@ class Script(ItfModel): author = models.CharField(max_length=255) contact = models.EmailField() script = models.FileField(null=True, upload_to='upload/scripts/') - license_adapt = models.ForeignKey("LicensePerform", help_text="License for adaptation rights") - license_perform = models.ForeignKey("LicenseAdapt", help_text="License for performance rights") + license_adapt = models.ForeignKey("License", related_name="adaptation_license", help_text="License for adaptation rights") + license_perform = models.ForeignKey("License", related_name="performance_license", help_text="License for performance rights") fts_fields = ['title', 'synopsis', 'author'] fk_fields = ['license_adapt', 'license_perform'] @@ -77,19 +82,11 @@ class License(models.Model): short_description = models.TextField() readable_file = models.FileField(upload_to='upload/licenses/short/') legal_file = models.FileField(upload_to='upload/licenses/legal/') + typ = models.CharField(choices=LICENSE_TYPE_CHOICES, max_length=32) def __unicode__(self): - return self.letter + ": " + self.name + return self.typ + ": " + self.letter + ": " + self.name - class Meta: - abstract = True - -class LicenseAdapt(License): - pass - -class LicensePerform(License): - pass - class Review(models.Model): script = models.ForeignKey(Script) diff --git a/itf/static/css/noel/inner.css b/itf/static/css/noel/inner.css index 9bf63a0..1d7ee03 100755 --- a/itf/static/css/noel/inner.css +++ b/itf/static/css/noel/inner.css @@ -9,6 +9,10 @@ margin-left:auto; position:relative; } +.hidden { + display: none; +} + #leftColumn {width:296px; background-color:#FFF; @@ -395,6 +399,7 @@ position:fixed; top:0px; left:0px; bottom:0px; + right:0px; width:100%; height:100%; diff --git a/itf/static/js/insidepage.js b/itf/static/js/insidepage.js index e098bf9..69b243d 100755 --- a/itf/static/js/insidepage.js +++ b/itf/static/js/insidepage.js @@ -34,14 +34,22 @@ $('.thumbsDetails').live("click", function(e) { var that = this; var bigImage = $(this).attr("data-bigimage"); var $img = $('').attr("src", bigImage); - $('#lightbox, #lightboxPanel').fadeIn(400); - $('#lightboxPanel').empty().append($img); + showLightbox($img); var title = $(this).hasAttr("title") ? $(this).attr("title") : ''; if (title != '') { var $caption = $('
').addClass("lightboxCaption").text(title).appendTo($('#lightboxPanel')); } }); +function hideLightbox() { + $('#lightbox, #lightboxPanel').fadeOut(400); +} + +function showLightbox($content) { + $('#lightbox, #lightboxPanel').fadeIn(400); + $('#lightboxPanel').empty().append($content); +} + $('.toggleNext').live("click", function(e) { e.preventDefault(); @@ -76,7 +84,7 @@ function getLi(item) { $(function() { $('#lightbox').click(function() { - $('#lightbox, #lightboxPanel').fadeOut(400); + hideLightbox(); }); /* search button toggle */ @@ -89,6 +97,18 @@ $(function() { /* search button end */ + $('#aboutBtn').click(function() { + var about = $('#moduleAbout').html(); + var $content = $('
').addClass("aboutLightbox").html(about); + showLightbox($content); + }); + + $('#addBtn').click(function() { + var add = $('#moduleAdd').html(); + var $content = $('
').addClass("addLightbox").html(add); + showLightbox($content); + }); + // $('#listLeft ul li a').eq(0).click(); // alert("hi"); @@ -222,6 +242,11 @@ function doState(queryData) { $('#orderBySelect').selectOption(queryData.sort); } + //FIXME TO USE ABOUT / NO ABOUT LOGIC BASED ON USER PREFS. + if (!queryData.hasOwnProperty("noAbout")) { + $('#aboutBtn').click(); + } + if (queryData.tab == undefined || queryData.tab == '') { // alert("foo"); var $tab = $('.defaultTab'); diff --git a/itf/templates/noel/insidepage.html b/itf/templates/noel/insidepage.html index 7776103..d7b17bd 100755 --- a/itf/templates/noel/insidepage.html +++ b/itf/templates/noel/insidepage.html @@ -20,6 +20,18 @@
+ + + +
@@ -34,10 +46,14 @@
search + About + {% if has_add %} + Add + {% endif %} +