profile form stuff

This commit is contained in:
Sanj 2012-07-17 18:32:26 +05:30
parent 5c9eb1bbe4
commit edc6f63cd9
4 changed files with 43 additions and 3 deletions

View File

@ -7,11 +7,13 @@ from django.forms.models import inlineformset_factory
from django.contrib.contenttypes.generic import generic_inlineformset_factory
from padmavideos.models import PadmaVideo, PadmaClip
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
class ItfForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.form_tag = False
super(ItfForm, self).__init__(*args, **kwargs)
@ -98,14 +100,21 @@ class PersonForm(forms.ModelForm):
# inlines = [ConnectionsInline]
inlines = [ConnectionsInline, ProductionsInline, GroupsInline, PadmaClipsInline]
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.form_tag = False
self.helper.add_input(Submit('submit', 'Submit'))
super(PersonForm, self).__init__(*args, **kwargs)
class Meta:
exclude = ('connections', 'productions', 'groups', 'last_accessed',)
exclude = ('connections', 'productions', 'groups', 'last_accessed', 'occupations',)
model = Person
widgets = {
'first_name': forms.TextInput,
'last_name': forms.TextInput,
'occupations': forms.CheckboxSelectMultiple
# 'occupations': forms.CheckboxSelectMultiple
}
#exclude = ('connections', 'productions')
#exclude = ('connections', 'productions', 'occupations', 'groups',)

View File

@ -6,6 +6,8 @@ from ox.django.shortcuts import render_to_json_response
from django.core.paginator import Paginator, InvalidPage, EmptyPage
from django.template import RequestContext
from django.http import HttpResponse
from django.contrib.auth.decorators import login_required
def person_form(request):
person = Person.objects.all()[0]
@ -15,6 +17,31 @@ def person_form(request):
#pdb.set_trace()
return render_to_response("test/person_form.html", {'form': form, 'inlines': inlines})
@login_required
def edit_profile(request):
user = request.user
#person = Person.objects.get(user=user)
person = Person.objects.all()[0]
if request.POST:
form = PersonForm(request.POST, request.FILES, instance=person)
if form.is_valid():
instance = form.save()
form.save()
# inlines = [inline(request.POST, request.FILES, instance=person) for inline in form.inlines]
# for inline in inlines:
# if inline.is_valid():
# inline.save()
else:
form = PersonForm(instance=person)
inlines = [inline(instance=person) for inline in form.inlines]
context = RequestContext(request, {
'form': form,
'inlines': inlines
})
return render_to_response("test/person_form.html", context)
def personpopup(request):
form = PersonForm()
if request.POST:

View File

@ -152,6 +152,7 @@ $(function(){
</div>
<div id="searchContainer">
<form id="formItf" action="" class="uniForm" method="POST">
{% csrf_token %}
<div>
<!-- <input type="hidden" data-placeholder="Choose Connections" id="id_connections" name="connections" style="width:600px" /> -->
</div>
@ -166,6 +167,8 @@ $(function(){
{% crispy inline inline.form.helper %}
</div>
{% endfor %}
<br />
<input type="submit" value="Submit" />
</form>
</div>

View File

@ -42,6 +42,7 @@ urlpatterns = patterns('',
# to INSTALLED_APPS to enable admin documentation:
#Test views:
(r'test_profile', 'itfprofiles.views.person_form'),
(r'edit_profile', 'itfprofiles.views.edit_profile'),
(r'^autocompletes/itfprofiles/$', 'itfprofiles.views.autocomplete'),
(r'^popup/person', 'itfprofiles.views.personpopup'),
# (r'i/', include('itfcore.urls')),