def profile_edit(request, profile_slug=None, **kwargs): """ profile_edit """ template_name = kwargs.pop("template_name", "idios/profile_edit.html") form_class = kwargs.pop("form_class", None) if request.is_ajax(): template_name = kwargs.get( "template_name_facebox", "idios/profile_edit_facebox.html" ) group, bridge = group_and_bridge(kwargs) # @@@ not group-aware (need to look at moving to profile model) profile_class = get_profile_model(profile_slug) if profile_class is None: raise Http404 profile = profile_class.objects.get(user=request.user) if form_class is None: form_class = get_profile_form(profile_class) if request.method == "POST": profile_form = form_class(request.POST, instance=profile) if profile_form.is_valid(): profile = profile_form.save(commit=False) profile.user = request.user profile.save() return HttpResponseRedirect(profile.get_absolute_url(group=group)) else: profile_form = form_class(instance=profile) ctx = group_context(group, bridge) ctx.update({ "profile": profile, "profile_form": profile_form, }) return render_to_response(template_name, RequestContext(request, ctx))
def profile_edit(request, profile_slug=None, **kwargs): """ profile_edit """ template_name = kwargs.pop("template_name", "idios/profile_edit.html") form_class = kwargs.pop("form_class", None) if request.is_ajax(): template_name = kwargs.get("template_name_facebox", "idios/profile_edit_facebox.html") group, bridge = group_and_bridge(kwargs) # @@@ not group-aware (need to look at moving to profile model) profile_class = get_profile_model(profile_slug) if profile_class is None: raise Http404 profile = profile_class.objects.get(user=request.user) if form_class is None: form_class = get_profile_form(profile_class) if request.method == "POST": profile_form = form_class(request.POST, instance=profile) if profile_form.is_valid(): profile = profile_form.save(commit=False) profile.user = request.user profile.save() return HttpResponseRedirect(profile.get_absolute_url(group=group)) else: profile_form = form_class(instance=profile) ctx = group_context(group, bridge) ctx.update({ "profile": profile, "profile_form": profile_form, }) return render_to_response(template_name, RequestContext(request, ctx))
def profile_create(request, profile_slug=None, **kwargs): """ profile_create """ template_name = kwargs.pop("template_name", "idios/profile_create.html") form_class = kwargs.pop("form_class", None) if request.is_ajax(): template_name = kwargs.get( "template_name_facebox", "idios/profile_create_facebox.html" ) group, bridge = group_and_bridge(kwargs) profile_class = get_profile_model(profile_slug) if profile_class is None: raise Http404 if form_class is None: form_class = get_profile_form(profile_class) # @@@ is this the same for edit/create if request.method == "POST": profile_form = form_class(request.POST) if profile_form.is_valid(): profile = profile_form.save(commit=False) profile.user = request.user profile.save() return HttpResponseRedirect(profile.get_absolute_url(group=group)) else: profile_form = form_class() ctx = group_context(group, bridge) ctx.update({ "profile_form": profile_form, }) return render_to_response(template_name, RequestContext(request, ctx))
def profile_create(request, profile_slug=None, **kwargs): """ profile_create """ template_name = kwargs.pop("template_name", "idios/profile_create.html") form_class = kwargs.pop("form_class", None) if request.is_ajax(): template_name = kwargs.get("template_name_facebox", "idios/profile_create_facebox.html") group, bridge = group_and_bridge(kwargs) profile_class = get_profile_model(profile_slug) if profile_class is None: raise Http404 if form_class is None: form_class = get_profile_form( profile_class) # @@@ is this the same for edit/create if request.method == "POST": profile_form = form_class(request.POST) if profile_form.is_valid(): profile = profile_form.save(commit=False) profile.user = request.user profile.save() return HttpResponseRedirect(profile.get_absolute_url(group=group)) else: profile_form = form_class() ctx = group_context(group, bridge) ctx.update({ "profile_form": profile_form, }) return render_to_response(template_name, RequestContext(request, ctx))
def get_form(cls): return get_profile_form(cls)
def test_alt_profile_form(self): form_class = utils.get_profile_form(SecretIdentityProfile) form = form_class(data={}) self.assertEqual(form.is_valid(), False) self.assertEqual(form.errors["super_power"], [u"This field is required."])
def test_profile_form(self): form_class = utils.get_profile_form() form = form_class(data={}) self.assertEqual(form.is_valid(), False) self.assertEqual(form.errors["name"], [u"This field is required."])
from django import forms from idios.utils import get_profile_form from sw.decorators import autostrip from sw.models import Interest from uni_form.helpers import FormHelper, Submit, Reset from uni_form.helpers import Layout, Fieldset, Row, HTML BaseProfileForm = get_profile_form() @autostrip class ProfileForm(BaseProfileForm): interests = forms.ModelMultipleChoiceField( queryset=Interest.objects.all(), required=False, widget=forms.CheckboxSelectMultiple) helper = FormHelper() layout = Layout( Fieldset('Online Name/Nickname', 'preferred_name', ), Fieldset('Real Name', Row('first_name', 'last_name'), 'name_privacy', ), Fieldset('More about yourself', 'zip_code',