Yep, here is the ProfileForm class

from django import forms
from django.forms import ModelForm
from django.contrib.auth.models import User

class ProfileForm(ModelForm):

    def __init__(self, *args, **kwargs):
        super(ProfileForm, self).__init__(*args, **kwargs)
        try:
            self.fields['email'].initial = self.instance.user.email
            self.fields['first_name'].initial =
self.instance.user.first_name
            self.fields['last_name'].initial =
self.instance.user.last_name
        except User.DoesNotExist:
            pass

    email = forms.EmailField(label="Primary email",help_text='')
    first_name = forms.CharField(label="First Name",help_text='')
    last_name = forms.CharField(label="Last Name",help_text='')

    class Meta:
      model = User
      exclude = ('user',)

    def save(self, *args, **kwargs):
        """
        Update the primary email address, first and last names on the
related User object as well.
        """
        u = self.instance.user
        u.email = self.cleaned_data['email']
        u.first_name = self.cleaned_data['first_name']
        u.last_name = self.cleaned_data['last_name']
        u.save()
        profile = super(ProfileForm, self).save(*args,**kwargs)
        return profile

And the view (which is just the default from the Profile app):

def edit_profile(request, form_class=None, success_url=None,
                 template_name='profiles/edit_profile.html',
                 extra_context=None):
    """
    Edit the current user's profile.

    If the user does not already have a profile (as determined by
    ``User.get_profile()``), a redirect will be issued to the
    :view:`profiles.views.create_profile` view; if no profile model
    has been specified in the ``AUTH_PROFILE_MODULE`` setting,
    ``django.contrib.auth.models.SiteProfileNotAvailable`` will be
    raised.

    **Optional arguments:**

    ``extra_context``
        A dictionary of variables to add to the template context. Any
        callable object in this dictionary will be called to produce
        the end result which appears in the context.

    ``form_class``
        The form class to use for validating and editing the user
        profile. This form class must operate similarly to a standard
        Django ``ModelForm`` in that it must accept an instance of the
        object to be edited as the keyword argument ``instance`` to
        its constructor, and it must implement a method named
        ``save()`` which will save the updates to the object. If this
        argument is not specified, this view will use a ``ModelForm``
        generated from the model specified in the
        ``AUTH_PROFILE_MODULE`` setting.

    ``success_url``
        The URL to redirect to following a successful edit. If not
        specified, this will default to the URL of
        :view:`profiles.views.profile_detail` for the profile object
        being edited.

    ``template_name``
        The template to use when displaying the profile-editing
        form. If not specified, this will default to
        :template:`profiles/edit_profile.html`.

    **Context:**

    ``form``
        The form for editing the profile.

    ``profile``
         The user's current profile.

    **Template:**

    ``template_name`` keyword argument or
    :template:`profiles/edit_profile.html`.

    """
    try:
        profile_obj = request.user.get_profile()
    except ObjectDoesNotExist:
        return
HttpResponseRedirect(reverse('profiles_create_profile'))


I should have said that I am passing the form class like so:

from django.conf.urls.defaults import *
from profiles import views
from django.contrib.auth.decorators import login_required
from userinfo.forms import ProfileForm


#the urls for the login sections of the site


urlpatterns = patterns('',
                       url(r'^edit/$',
                           login_required(views.edit_profile),
{'form_class':ProfileForm},
                           name='profiles_edit_profile'),
                       url(r'^(?P<username>\w+)/$',
                           login_required(views.profile_detail),
                           name='profiles_profile_detail'),
                       )



On Jul 15, 2:40 am, Subhranath Chunder <subhran...@gmail.com> wrote:
> Could you provide the code for the custom ProfileForm class and the views
> first.
>
> Thanks,
> Subhranath Chunder.
>
> On Thu, Jul 15, 2010 at 2:49 AM, Ricko <rickentr...@gmail.com> wrote:
> > Using ubernostroms Django Registration app coupled with his Profile
> > app, both highly recommended, got the default app up and running no
> > problems at all.
> > I'm unable to override any default behaviour the proper way, as I
> > can't seem to pass any extra parameters through the urls.py file. Here
> > is my urls:
>
> > from django.conf.urls.defaults import *
> > from profiles import views
> > from django.contrib.auth.decorators import login_required
> > from userinfo.forms import ProfileForm
>
> > urlpatterns = patterns('',
> >                       url(r'^edit/$',
> >                           login_required(views.edit_profile),
> > {'form_class' : ProfileForm},
> >                           name='profiles_edit_profile'),
> >                       url(r'^(?P<username>\w+)/$',
> >                           login_required(views.profile_detail),
> >                           name='profiles_profile_detail'),
> >                       )
>
> > I have my custom form class ProfileForm. When I try this I get a
> > stack:
>
> > Original Traceback (most recent call last):
> >  File "/Library/Python/2.5/site-packages/django/template/debug.py",
> > line 71, in render_node
> >    result = node.render(context)
> >  File "/Library/Python/2.5/site-packages/django/template/
> > defaulttags.py", line 155, in render
> >    nodelist.append(node.render(context))
> >  File "/Library/Python/2.5/site-packages/django/template/debug.py",
> > line 87, in render
> >    output = force_unicode(self.filter_expression.resolve(context))
> >  File "/Library/Python/2.5/site-packages/django/utils/encoding.py",
> > line 71, in force_unicode
> >    s = unicode(s)
> > TypeError: unbound method __unicode__() must be called with
> > ProfileForm instance as first argument (got nothing instead)
>
> > Now, the docs say to pass in the Class name, and the stack seems to be
> > saying I need an Instance? Whatever extra parameter I pass I get the
> > same error.
>
> > What am I doing wrong?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to