On Wed, Aug 20, 2008 at 5:13 PM, Burr Settles <[EMAIL PROTECTED]> wrote:

>
> I recently came back to a project I put on hold for a couple weeks,
> and after updating the Django trunk, all my references to
> "request.user.id" are broken. Here is an example view for a rating
> widget:
>
> 1 @login_required
> 2 def rate(request, song_id):
> 3     song = get_object_or_404(Song, pk=song_id)
> 4     if 'rating' not in request.GET or request.GET['rating'] not in
> range(1,5):
> 5         HttpResponseRedirect(song.get_absolute_url())
> 6     rating = Rating.objects.get_or_create(user__pk=request.user.id,
> song__pk=song.id)
> 7     rating.rating = int(request.GET['rating'])
> 8     rating.save()
> 9     return HttpResponseRedirect(song.get_absolute_url())
>
> This throws an "IntegrityError" if the user is logged in, presumably
> complaining that request.user.id is NULL (at line 6).


Presumably?  I suspect you are guessing wrong here, but it would be best to
make sure.  There's lots of information available on the deubg page when
something like an IntegrityError is thrown, have you checked the values of
local variables to see what request.user.id actually is?


> But it passes
> the @login_required constraint just fine. I'm having similar problems
> with other views that use request.user.
>
> Does anyone know if the user API has recently changed? I've scoured
> the latest online documentation, and can't seem to find any alternate
> way to access the ID of the currently logged in user. Any help is
> appreciated.
>

I do not think anything has changed with request.user.  It seems more likely
something is going wrong in get_or_create.  Such as the get fails to find an
existing record so it tries to insert one but that is violating an integrity
constraint.   What, exactly, does the IntegrityError message say?  Usually
it will give some indication of what it is objecting to, which could provide
a clue.

Karen

--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to