From 795c65a99912f0b3cdde319adc0a776f2c158dd3 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sat, 21 Apr 2012 16:05:01 +0530 Subject: [PATCH] test profile form + padma video --- itf/app/models.py | 19 ++- itf/itfcore/models.py | 3 + itf/itfprofiles/forms.py | 23 ++- itf/itfprofiles/models.py | 167 +++++++++++++++++++- itf/itfprofiles/views.py | 6 + itf/padmavideos/models.py | 6 +- itf/settings.py | 3 + itf/templates/modules/festival/meeting.html | 33 ++-- itf/urls.py | 15 +- requirements.txt | 2 + 10 files changed, 245 insertions(+), 32 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index 4662751..8125d35 100755 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -56,7 +56,9 @@ class ItfModel(models.Model): return {} 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): return self.get(self.title_field) @@ -66,6 +68,7 @@ class ItfModel(models.Model): tab = ModuleTab.objects.filter(model=modelextra)[0] return tab + #TODO: Get rid off and use .get_forms() instead @classmethod def get_add_form(cls): try: @@ -78,6 +81,20 @@ class ItfModel(models.Model): except: 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): try: diff --git a/itf/itfcore/models.py b/itf/itfcore/models.py index 3b14714..70a72c9 100755 --- a/itf/itfcore/models.py +++ b/itf/itfcore/models.py @@ -11,6 +11,9 @@ GENDER_CHOICES = ( ) class Person(models.Model): + #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) diff --git a/itf/itfprofiles/forms.py b/itf/itfprofiles/forms.py index fd00c3d..f6ae78d 100644 --- a/itf/itfprofiles/forms.py +++ b/itf/itfprofiles/forms.py @@ -1,6 +1,6 @@ -from django import forms +import floppyforms as forms from registration.forms import RegistrationForm -from models import ItfProfile +from models import * from registration.models import RegistrationProfile class ItfRegistrationForm(RegistrationForm): @@ -11,3 +11,22 @@ class ItfRegistrationForm(RegistrationForm): new_profile = ItfProfile(user=new_user, subscribed=self.cleaned_data['subscribe']) new_profile.save() 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') + + diff --git a/itf/itfprofiles/models.py b/itf/itfprofiles/models.py index 2e6d1d2..c6754be 100644 --- a/itf/itfprofiles/models.py +++ b/itf/itfprofiles/models.py @@ -1,13 +1,172 @@ from django.db import models from app.models import ItfModel 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): - user = models.ForeignKey(User, null=True) - subscribed = models.BooleanField(default=True) +class Occupation(models.Model): + name = models.CharField(max_length=255) + 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. diff --git a/itf/itfprofiles/views.py b/itf/itfprofiles/views.py index 60f00ef..f18804e 100644 --- a/itf/itfprofiles/views.py +++ b/itf/itfprofiles/views.py @@ -1 +1,7 @@ # 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}) \ No newline at end of file diff --git a/itf/padmavideos/models.py b/itf/padmavideos/models.py index c56e52b..23f723d 100644 --- a/itf/padmavideos/models.py +++ b/itf/padmavideos/models.py @@ -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): 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.save() self.padmavideo = padmaVideo - super(PadmaClip, self).save(*args, **kwargs) \ No newline at end of file + super(PadmaClip, self).save(*args, **kwargs) diff --git a/itf/settings.py b/itf/settings.py index 427c921..69e7787 100755 --- a/itf/settings.py +++ b/itf/settings.py @@ -25,6 +25,7 @@ HAYSTACK_SITECONF = 'itf.search_sites' HAYSTACK_SEARCH_ENGINE = 'whoosh' HAYSTACK_WHOOSH_PATH = join(PROJECT_PATH, "../whoosh/itf_index") +CRISPY_TEMPLATE_PACK = 'uni_form' CKEDITOR_MEDIA_PREFIX = "/static/ckeditor/" CKEDITOR_UPLOAD_PATH = join(PROJECT_PATH, "static/upload/images/") @@ -187,6 +188,8 @@ INSTALLED_APPS = ( 'django_extensions', 'debug_toolbar', 'sorl.thumbnail', + 'crispy_forms', + 'floppyforms', # 'south', 'user', 'ckeditor', diff --git a/itf/templates/modules/festival/meeting.html b/itf/templates/modules/festival/meeting.html index 661e407..42df672 100755 --- a/itf/templates/modules/festival/meeting.html +++ b/itf/templates/modules/festival/meeting.html @@ -90,9 +90,9 @@ {% endfor %} - {% for v in talk.video %} + {% for v in talk.videos.all %} - + @@ -100,16 +100,6 @@    {{ talk.title }} by {{ talk.presenter }} - {% ifnotequal talk.videos.all|length 0 %} -
- {% for v in talk.videos.all %} -
- - - {% endfor %} -
- {% endifnotequal %} - {% endfor %} @@ -252,3 +242,22 @@ + + + diff --git a/itf/urls.py b/itf/urls.py index 38991b3..46c3e7a 100755 --- a/itf/urls.py +++ b/itf/urls.py @@ -10,8 +10,8 @@ from itfprofiles.forms import ItfRegistrationForm from django.contrib import admin admin.autodiscover() -from api import actions -actions.autodiscover() +#from api import actions +#actions.autodiscover() urlpatterns = patterns('', # Example: @@ -39,20 +39,11 @@ urlpatterns = patterns('', # Uncomment the admin/doc line below and add 'django.contrib.admindocs' # to INSTALLED_APPS to enable admin documentation: #Core views: -# (r'profile', 'itfcore.views.edit_profile'), + (r'test_profile', 'itfprofiles.views.person_form'), (r'i/', include('itfcore.urls')), (r'^admin/doc/', include('django.contrib.admindocs.urls')), (r'^search/', include('haystack.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'emailsignuplist', 'festival.views.email_signups'), diff --git a/requirements.txt b/requirements.txt index d2aa5b0..ef21a14 100755 --- a/requirements.txt +++ b/requirements.txt @@ -16,3 +16,5 @@ django-registration Whoosh django-haystack Markdown +django-crispy-forms +django-floppyforms