test profile form + padma video

This commit is contained in:
Sanj 2012-04-21 16:05:01 +05:30
parent c28f903df0
commit 795c65a999
10 changed files with 245 additions and 32 deletions

View File

@ -56,7 +56,9 @@ class ItfModel(models.Model):
return {} return {}
def info_dict(self): def info_dict(self):
return self.get_dict() d = self.get_dict()
d['add_form'] = self.__class__.get_add_form()
return d
def get_title(self): def get_title(self):
return self.get(self.title_field) return self.get(self.title_field)
@ -66,6 +68,7 @@ class ItfModel(models.Model):
tab = ModuleTab.objects.filter(model=modelextra)[0] tab = ModuleTab.objects.filter(model=modelextra)[0]
return tab return tab
#TODO: Get rid off and use .get_forms() instead
@classmethod @classmethod
def get_add_form(cls): def get_add_form(cls):
try: try:
@ -78,6 +81,20 @@ class ItfModel(models.Model):
except: except:
return None return None
@classmethod
def get_forms(cls):
def get_form(form_name):
app_label = cls._meta.app_label
module = __import__(app_label + ".forms")
return module.forms.__getattribute__(form_name)
ret = {}
for form_name in cls.form_names:
ret[form_name] = get_form(form_name)
return ret
def get_modelextra(self): def get_modelextra(self):
try: try:

View File

@ -11,6 +11,9 @@ GENDER_CHOICES = (
) )
class Person(models.Model): class Person(models.Model):
#ItfModel Stuff:
form_names = ['PersonForm']
fts_fields = ['first_name', 'last_name', 'email', 'about']
#Basic Info #Basic Info
user = models.ForeignKey(User, blank=True, null=True, db_index=True) user = models.ForeignKey(User, blank=True, null=True, db_index=True)

View File

@ -1,6 +1,6 @@
from django import forms import floppyforms as forms
from registration.forms import RegistrationForm from registration.forms import RegistrationForm
from models import ItfProfile from models import *
from registration.models import RegistrationProfile from registration.models import RegistrationProfile
class ItfRegistrationForm(RegistrationForm): class ItfRegistrationForm(RegistrationForm):
@ -11,3 +11,22 @@ class ItfRegistrationForm(RegistrationForm):
new_profile = ItfProfile(user=new_user, subscribed=self.cleaned_data['subscribe']) new_profile = ItfProfile(user=new_user, subscribed=self.cleaned_data['subscribe'])
new_profile.save() new_profile.save()
return new_user return new_user
#Actual person form definition
class PersonForm(forms.ModelForm):
# occupations = forms.ModelMultipleChoiceField(Occupation.objects.all(), widget=forms.CheckboxSelectMultiple())
email = forms.EmailField(widget=forms.EmailInput(attrs={'placeholder': 'john@example.com'}))
# inlines = [ConnectionFormset, ProductionFormset]
class Meta:
model = Person
widgets = {
'first_name': forms.TextInput,
'last_name': forms.TextInput,
'occupations': forms.CheckboxSelectMultiple
}
# exclude = ('connections', 'productions')

View File

@ -1,13 +1,172 @@
from django.db import models from django.db import models
from app.models import ItfModel from app.models import ItfModel
from django.contrib.auth.models import User from django.contrib.auth.models import User
from datetime import datetime
from django.contrib.localflavor.in_.forms import INZipCodeField
#from ox.django.fields import DictField
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
('O', 'Other'),
)
class Person(ItfModel):
#ItfModel stuff:
form_names = ['PersonForm']
fts_fields = ['first_name', 'last_name', 'email', 'about']
#Basic Info
user = models.ForeignKey(User, blank=True, null=True, db_index=True, editable=False)
first_name = models.CharField(max_length=255)
last_name = models.CharField(max_length=255)
email = models.EmailField(blank=True, null=True, unique=True, db_index=True)
email_validated = models.BooleanField(default=False, editable=False)
tel_no = models.CharField(max_length=100, blank=True)
about = models.TextField(blank=True, null=True)
#Occupation info
occupations = models.ManyToManyField("Occupation", through='PersonOccupation', blank=True, null=True)
is_practitioner = models.BooleanField(default=False)
is_enthusiast = models.BooleanField(default=True)
#Personal info
dob = models.DateField(null=True, verbose_name="Date of Birth")
gender = models.CharField(max_length=255, choices=GENDER_CHOICES, blank=True)
image = models.ImageField(upload_to='images/', blank=True, null=True)
locations = models.ManyToManyField("Location", blank=True, null=True)
#Groups and Connections
is_freelancer = models.BooleanField(default=False)
groups = models.ManyToManyField("TheatreGroup", blank=True, null=True, through='PersonGroup')
connections = models.ManyToManyField('Person', blank=True, null=True, through='PersonPerson')
productions = models.ManyToManyField("Production", blank=True, null=True, through='PersonProduction')
trainings = models.ManyToManyField("Training", blank=True, null=True, related_name="trainee")
# photos = models.ManyToManyField("PhotoAlbum", blank=True, null=True)
# orphans = models.ManyToManyField("Orphan", blank=True, null=True, through='PersonOrphan')
#Meta
last_accessed = models.DateTimeField(default=datetime.now)
#Tokens
reset_token = models.CharField(max_length=256, null=True, editable=False)
validate_token = models.CharField(max_length=256, null=True, editable=False)
def __unicode__(self):
return "%s %s" % (self.first_name, self.last_name,)
class ItfProfile(ItfModel): class Occupation(models.Model):
user = models.ForeignKey(User, null=True) name = models.CharField(max_length=255)
subscribed = models.BooleanField(default=True) parent = models.ForeignKey('Occupation', blank=True, null=True)
def __unicode__(self):
return self.name
def is_child(self):
return self.parent != None
def is_parent(self):
if self.is_child():
return False
else:
if Occupation.objects.filter(parent=self).count() > 0: #self has children
return True
return False
class PersonOccupation(models.Model):
person = models.ForeignKey(Person, db_index=True)
occupation = models.ForeignKey(Occupation)
order = models.IntegerField()
class PersonPerson(models.Model):
person1 = models.ForeignKey(Person, related_name='PersonFrom', db_index=True)
person2 = models.ForeignKey(Person, related_name='PersonTo', db_index=True)
relation = models.ForeignKey("Relation")
disapproved = models.BooleanField(default=False)
class Relation(models.Model):
name = models.CharField(max_length=255, db_index=True)
reverse = models.CharField(max_length=255, db_index=True)
def __unicode__(self):
return self.name
class Location(models.Model):
address = models.TextField(blank=True, null=True)
city = models.CharField(blank=True, max_length=255, db_index=True)
pin_code = INZipCodeField()
lat = models.FloatField(blank=True, null=True)
lng = models.FloatField(blank=True, null=True)
class Training(models.Model):
person = models.ForeignKey("Person")
area = models.CharField(max_length=255) # Choices?
with_whom = models.CharField(max_length=255) # Is this a foreign key to person, or group, or just text field like now?
where = models.ForeignKey("TheatreGroup")
from_when = models.DateField(blank=True, null=True)
until_when = models.DateField(blank=True, null=True)
class Play(ItfModel):
title = models.CharField(max_length=512)
author = models.CharField(max_length=512, blank=True)
year = models.IntegerField(null=True, blank=True, max_length=4)
user = models.ForeignKey(User)
def __unicode__(self):
return self.title
class Production(ItfModel):
play = models.ForeignKey("Play", null=True, blank=True)
name = models.CharField(max_length=255, db_index=True)
language = models.ForeignKey("Language", blank=True, null=True)
group = models.ForeignKey("TheatreGroup")
director = models.ForeignKey(Person)
SHOWS_NO_CHOICES = (
('5', '0-5 Shows'),
('10', '6-10 Shows'),
('50', '11-50 Shows'),
('100', '51-100 Shows'),
('1000', 'More Than 100 Shows'),
#add more.
)
class PersonProduction(models.Model):
person = models.ForeignKey(Person, db_index=True)
production = models.ForeignKey(Production, db_index=True)
role = models.CharField(max_length=255)
start_year = models.IntegerField(max_length=4)
years = models.IntegerField(blank=True, null=True)
no_of_shows = models.CharField(max_length=25, choices = SHOWS_NO_CHOICES)
original_cast = models.BooleanField(default=False)
class TheatreGroup(ItfModel):
name = models.CharField(max_length=255, db_index=True) # name + location is unique
city = models.CharField(max_length=255)
location = models.ForeignKey(Location, blank=True, null=True)
tel = models.IntegerField(blank=True, null=True)
email = models.EmailField(blank=True, null=True)
about = models.TextField(blank=True, null=True)
nature_of_work = models.CharField(max_length=255)
founded = models.CharField(max_length=10)
def __unicode__(self):
return self.name
class PersonGroup(models.Model):
person = models.ForeignKey(Person, db_index=True)
group = models.ForeignKey(TheatreGroup, db_index=True)
is_admin = models.BooleanField(default=False)
role = models.CharField(max_length=255, blank=True)
class Language(models.Model):
code = models.CharField(max_length=3, db_index=True)
name = models.CharField(max_length=255)
# Create your models here.

View File

@ -1 +1,7 @@
# Create your views here. # Create your views here.
from models import *
from forms import *
from django.shortcuts import render_to_response
def person_form(request):
return render_to_response("test/person_form.html", {'form': PersonForm})

View File

@ -40,6 +40,10 @@ class PadmaVideo(ItfModel):
} }
@property
def padma_link(self):
return "http://%s/%s" % (PANDORA_BASE, self.padma_id,)
''' '''
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
embed_code = self.embed_code embed_code = self.embed_code
@ -114,4 +118,4 @@ class PadmaClip(ItfModel):
padmaVideo.get_padma_data(update_poster=created) #update poster only if video is freshly created padmaVideo.get_padma_data(update_poster=created) #update poster only if video is freshly created
padmaVideo.save() padmaVideo.save()
self.padmavideo = padmaVideo self.padmavideo = padmaVideo
super(PadmaClip, self).save(*args, **kwargs) super(PadmaClip, self).save(*args, **kwargs)

View File

@ -25,6 +25,7 @@ HAYSTACK_SITECONF = 'itf.search_sites'
HAYSTACK_SEARCH_ENGINE = 'whoosh' HAYSTACK_SEARCH_ENGINE = 'whoosh'
HAYSTACK_WHOOSH_PATH = join(PROJECT_PATH, "../whoosh/itf_index") HAYSTACK_WHOOSH_PATH = join(PROJECT_PATH, "../whoosh/itf_index")
CRISPY_TEMPLATE_PACK = 'uni_form'
CKEDITOR_MEDIA_PREFIX = "/static/ckeditor/" CKEDITOR_MEDIA_PREFIX = "/static/ckeditor/"
CKEDITOR_UPLOAD_PATH = join(PROJECT_PATH, "static/upload/images/") CKEDITOR_UPLOAD_PATH = join(PROJECT_PATH, "static/upload/images/")
@ -187,6 +188,8 @@ INSTALLED_APPS = (
'django_extensions', 'django_extensions',
'debug_toolbar', 'debug_toolbar',
'sorl.thumbnail', 'sorl.thumbnail',
'crispy_forms',
'floppyforms',
# 'south', # 'south',
'user', 'user',
'ckeditor', 'ckeditor',

View File

@ -90,9 +90,9 @@
</a> </a>
</span> </span>
{% endfor %} {% endfor %}
{% for v in talk.video %} {% for v in talk.videos.all %}
<span class="talkIcon"> <span class="talkIcon">
<a href="/static/{{v.file}}"> <a href="/static/{{ v.padmavideo.padma_link }}" class="padmaLink" data-video="http://pad.ma/{{ v.padmavideo.padma_id }}/480p.webm" target="_blank">
<img src="/static/images/VideoIcon.jpg" title="<span class='ttTitle'>Video: {{ talk.title }}.</span><span class='rightclickHelp'>(Right click and select 'Save Link As' to download)</span>"> <img src="/static/images/VideoIcon.jpg" title="<span class='ttTitle'>Video: {{ talk.title }}.</span><span class='rightclickHelp'>(Right click and select 'Save Link As' to download)</span>">
</a> </a>
</span> </span>
@ -100,16 +100,6 @@
</span> </span>
&nbsp;&nbsp; {{ talk.title }} by {{ talk.presenter }} &nbsp;&nbsp; {{ talk.title }} by {{ talk.presenter }}
{% ifnotequal talk.videos.all|length 0 %}
<div class="padmaVideos">
{% for v in talk.videos.all %}
<video controls="controls" src="{{ v.video_src }}" width="480"></video><br />
{% endfor %}
</div>
{% endifnotequal %}
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
@ -252,3 +242,22 @@
</script> </script>
<script type="text/javascript">
(function() {
var $video;
$('a.padmaLink').toggle(function(e) {
e.preventDefault();
var videoSrc = $(this).attr("data-video");
$video = $('<video>').attr("src", videoSrc).attr("autoplay", "autoplay").attr("controls", "controls").addClass("padmaVideo");
$(this).parents('.talks').eq(0).append($video);
//console.log("clicked in");
}, function(e) {
e.preventDefault();
//console.log("clicked out");
$video.remove();
});
})();
</script>

View File

@ -10,8 +10,8 @@ from itfprofiles.forms import ItfRegistrationForm
from django.contrib import admin from django.contrib import admin
admin.autodiscover() admin.autodiscover()
from api import actions #from api import actions
actions.autodiscover() #actions.autodiscover()
urlpatterns = patterns('', urlpatterns = patterns('',
# Example: # Example:
@ -39,20 +39,11 @@ urlpatterns = patterns('',
# Uncomment the admin/doc line below and add 'django.contrib.admindocs' # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation: # to INSTALLED_APPS to enable admin documentation:
#Core views: #Core views:
# (r'profile', 'itfcore.views.edit_profile'), (r'test_profile', 'itfprofiles.views.person_form'),
(r'i/', include('itfcore.urls')), (r'i/', include('itfcore.urls')),
(r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^admin/doc/', include('django.contrib.admindocs.urls')),
(r'^search/', include('haystack.urls')), (r'^search/', include('haystack.urls')),
(r'^markitup/', include('markitup.urls')), (r'^markitup/', include('markitup.urls')),
# (r'^mockup/', 'itfcore.views.mockup'),
# (r'x0news/', 'itfcore.views.allnews'),
# (r'x0disc/', 'itfcore.views.disc'),
# (r'x0multi/', 'itfcore.views.multi'),
# (r'x0resources/', 'itfcore.views.resources'),
# (r'x0erang/', 'itfcore.views.erang'),
# (r'x0profile/', 'itfcore.views.profile'),
(r'finalTest/', 'boxes.views.mainPage'),
(r'finalInner/', 'boxes.views.innerPage'),
(r'googlehostedservice.html', 'itfcore.views.googlehosted'), (r'googlehostedservice.html', 'itfcore.views.googlehosted'),
(r'emailsignuplist', 'festival.views.email_signups'), (r'emailsignuplist', 'festival.views.email_signups'),

View File

@ -16,3 +16,5 @@ django-registration
Whoosh Whoosh
django-haystack django-haystack
Markdown Markdown
django-crispy-forms
django-floppyforms