Patrick, thanks for your reply. I had actually tried similar methods to what you wrote -- the trouble was with using the default Manipulators, since they need the passed request collection to have the proper names, and since I was "injecting" my PK via a template, the trouble was there... no idea why this was not triggered in my local environment (maybe Sqlite is not as picky ;-)
Regards and thanks again, Carlos On 10/6/06, patrickk <[EMAIL PROTECTED]> wrote: > > don´t know if this might help, but: > > let´s say you have this in your manipulator: > > def save(self, data): > temp = UserExtendedProfile( > user = data['user'], > .... > ) > temp.save() > > you could also use this: > > def save(self, data): > temp = UserExtendedProfile( > user_id = data['user_id'], > .... > ) > temp.save() > > so, depending on which version you choose ... your view could look > like this: > > new_data = request.POST.copy() > new_data['user'] = request.user > errors = manipulator.get_validation_errors(new_data) > > or this: > > new_data = request.POST.copy() > new_data['user_id'] = request.user.id > errors = manipulator.get_validation_errors(new_data) > > patrick. > > > > Am 06.10.2006 um 09:04 schrieb Carlos Yoder: > > > > > Here you go Gábor, it's three views. my_data(request) find out what to > > do (change or add), and calls the proper view, either userprofile_add > > or userprofile_change. > > > > Hope the python code is not too ugly! > > > > Thanks a million for taking the time to help, köszönöm szépen! > > > > > > def my_data(request): > > """ allow a logged user to change his data. proxy view that > > calls proper views (add or change) """ > > > > if request.user.is_anonymous(): > > return redirect_to_login(request.path) > > > > u = User.objects.get(pk=request.user.id) > > try: > > up = u.userprofile # trigger exception, if not found > > return userprofile_change(request, u.id) > > except UserProfile.DoesNotExist: > > return userprofile_add(request) > > > > def userprofile_add(request): > > """ Handle adding new userprofiles (one2one rel to User > > objects) """ > > > > from django import forms > > > > manipulator = UserProfile.AddManipulator() > > > > if request.POST: > > # If data was POSTed, we're trying to create a new > > UserProfile. > > new_data = request.POST.copy() > > user_id = request.user.id > > > > # Check for errors. > > errors = manipulator.get_validation_errors(new_data) > > > > if not errors: > > # No errors. This means we can save the data! > > manipulator.do_html2python(new_data) > > if new_data['user_id']: > > pass > > else: > > new_data['user_id'] = user_id > > new_userprofile = manipulator.save(new_data) > > > > # Redirect to the object's "edit" page. Always > > use a redirect > > # after POST data, so that reloads don't > > accidently create > > # duplicate entires, and so users don't see > > the confusing > > # "Repost POST data?" alert box in their > > browsers. > > return HttpResponseRedirect("/my_data/") > > else: > > # No POST, so we want a brand new form without any > > data or errors. > > errors = new_data = {} > > > > # Create the FormWrapper, template, context, response. > > form = forms.FormWrapper(manipulator, new_data, errors) > > > > rc = RequestContext(request, { > > 'form': form, > > }) > > return render_to_response('userprofile.html', rc) > > > > > > def userprofile_change(request, userprofile_id): > > """ Handle editing userprofiles (one2one rel to User > > objects) """ > > from django import forms > > > > from django.http import Http404 > > > > try: > > manipulator = UserProfile.ChangeManipulator > > (userprofile_id) > > except UserProfile.DoesNotExist: > > raise Http404 > > > > # Grab the object in question for future use. > > userprofile = manipulator.original_object > > > > if request.POST: > > new_data = request.POST.copy() > > errors = manipulator.get_validation_errors(new_data) > > if not errors: > > manipulator.do_html2python(new_data) > > manipulator.save(new_data) > > # Do a post-after-redirect so that reload > > works, etc. > > return HttpResponseRedirect("/my_data/") > > else: > > errors = {} > > # This makes sure the form accurately represents the > > fields of the object. > > new_data = manipulator.flatten_data() > > > > form = forms.FormWrapper(manipulator, new_data, errors) > > > > rc = RequestContext(request, { > > 'form': form, > > 'userprofile': userprofile, > > }) > > > > return render_to_response('userprofile.html', rc) > > > > Best regards, > > > > -- > > Carlos Yoder > > http://blog.argentinaslovenia.com/ > > > > > >> Carlos Yoder wrote: > >>> I'm really sorry to bug you like this, but I don't know what to > >>> do -- > >>> being a newbie to both Python and Django, debugging for me is more > >>> like 'aha, the problem should be around here', but nothing concrete > >>> about fixing! > >>> > >> > >> hi, > >> > >> could you also post your view code? > >> > >> gabor > > > > > > > > > > -- Carlos Yoder http://blog.argentinaslovenia.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---