scriptbank models changes; add_form logic

This commit is contained in:
Sanj 2011-10-13 20:10:45 +05:30
parent 036fdc60f6
commit 6572afb7c8
8 changed files with 92 additions and 21 deletions

View File

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

View File

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

View File

@ -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'],
@ -26,6 +37,7 @@ def get_tab(request):
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)

View File

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

View File

@ -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,18 +82,10 @@ 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
class Meta:
abstract = True
class LicenseAdapt(License):
pass
class LicensePerform(License):
pass
return self.typ + ": " + self.letter + ": " + self.name
class Review(models.Model):

View File

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

View File

@ -34,14 +34,22 @@ $('.thumbsDetails').live("click", function(e) {
var that = this;
var bigImage = $(this).attr("data-bigimage");
var $img = $('<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 = $('<div />').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 = $('<div />').addClass("aboutLightbox").html(about);
showLightbox($content);
});
$('#addBtn').click(function() {
var add = $('#moduleAdd').html();
var $content = $('<div />').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');

View File

@ -20,6 +20,18 @@
</div>
<div id="lightbox"></div>
<div id="moduleAbout" class="hidden">
{{ about }}
</div>
<div id="moduleAdd" class="hidden">
<form id="addForm" action="" method="POST" data-id="{{ default_tab.id }}">
<table>
{{ add_form.as_table }}
</table>
</form>
</div>
<div id="centerInner">
<div id="woodPng">
</div>
@ -34,10 +46,14 @@
<div id="searchInnerDiv">
<img src="/static/images/noel/search-inner.png" width="22" height="18" alt="search" class="searchInner">
<img src="/static/images/noel/search-inner.png" width="22" height="18" id="aboutBtn" alt="About" class="searchInner">
{% if has_add %}
<img src="/static/images/noel/search-inner.png" width="22" height="18" id="addBtn" alt="Add" class="searchInner">
{% endif %}
<!--
<img src="/static/images/noel/search-inner.png" width="22" height="18" alt="search" class="searchInner">
<img src="/static/images/noel/search-inner.png" width="22" height="18" alt="search" class="searchInner">
<img src="/static/images/noel/search-inner.png" width="22" height="18" alt="search" class="searchInner">
-->
</div>