From edc6f63cd94c4ed510b9d224d80cad893d74cced Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 17 Jul 2012 18:32:26 +0530 Subject: [PATCH] profile form stuff --- itf/itfprofiles/forms.py | 15 ++++++++++++--- itf/itfprofiles/views.py | 27 +++++++++++++++++++++++++++ itf/templates/test/person_form.html | 3 +++ itf/urls.py | 1 + 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/itf/itfprofiles/forms.py b/itf/itfprofiles/forms.py index b144f27..1dc139d 100644 --- a/itf/itfprofiles/forms.py +++ b/itf/itfprofiles/forms.py @@ -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',) diff --git a/itf/itfprofiles/views.py b/itf/itfprofiles/views.py index 7b92957..a2e7c73 100644 --- a/itf/itfprofiles/views.py +++ b/itf/itfprofiles/views.py @@ -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: diff --git a/itf/templates/test/person_form.html b/itf/templates/test/person_form.html index b3f6cad..89255a2 100644 --- a/itf/templates/test/person_form.html +++ b/itf/templates/test/person_form.html @@ -152,6 +152,7 @@ $(function(){
+ {% csrf_token %}
@@ -166,6 +167,8 @@ $(function(){ {% crispy inline inline.form.helper %}
{% endfor %} +
+ diff --git a/itf/urls.py b/itf/urls.py index 8b6d000..37fd1ef 100755 --- a/itf/urls.py +++ b/itf/urls.py @@ -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')),