Opened 11 years ago

Closed 10 years ago

#686 closed enhancement (fixed)

Create User.url_for_self() method and use it

Reported by: Elrond Owned by:
Priority: major Milestone:
Component: programming Keywords: bitesized
Cc: ben@… Parent Tickets:

Description

The User object should have a .url_for_self method like the media entries or collections already have.

With the new redirect_obj it should then be as easy as

return redirect_obj(request, user)

to redirect to the user's main page.

So use redirect_obj or at least the .url_for_self around the sources.

Attachments (2)

trac#686-user.url_for_self.diff (614 bytes ) - added by Ben Sturmfels 11 years ago.
Add url_for_self function to User.
trac#686-usermixin.url_for_self.diff (560 bytes ) - added by Ben Sturmfels 11 years ago.
Add url_for_self function to UserMixin.

Download all attachments as: .zip

Change History (12)

comment:1 by Ben Sturmfels, 11 years ago

Status: newreview

I've attached a patch to add the User.url_for_self function. This is my first patch to MediaGoblin, so I'd appreciate some feedback.

I'm a bit unsure about the urlgen function. I can see that it's a reference to the build_proxy function of a Request in mediagoblin.app.call_backend, but it's not clear to me what it actually is. build_proxy could do with some docs in this regard.

I'm also not sure whether it's useful to allow **kwargs on url_to_self - I'm doing this because this is how it's done in mixin.MediaEntryMixin.url_for_self.

by Ben Sturmfels, 11 years ago

Add url_for_self function to User.

comment:2 by Ben Sturmfels, 11 years ago

Cc: ben@… added

comment:3 by rodney757, 11 years ago

It is useful to have **kwargs because you could add qualified=true or query strings.

This looks good to me, but I would say that this should go in mediagoblin.db.mixin.py instead of models.py

comment:4 by rodney757, 11 years ago

Status: reviewaccepted

by Ben Sturmfels, 11 years ago

Add url_for_self function to UserMixin.

comment:5 by Ben Sturmfels, 11 years ago

I've attached an updated patch moving the url_for_self function to UserMixin.

This appears to be all that's needed and existing tests pass, but I'm unclear on the best way to verify that it does indeed work, since it needs the urlgen parameter. Is there a way to get hold of urlgen without running the whole stack?

PS. My username is Sturm rather than Strum, but I appreciate the mention in previous commits anyway. :)

comment:6 by Ben Sturmfels, 11 years ago

Status: acceptedreview

in reply to:  5 comment:7 by Ben Sturmfels, 11 years ago

Replying to Sturm:

This appears to be all that's needed and existing tests pass, but I'm unclear on the best way to verify that it does indeed work, since it needs the urlgen parameter. Is there a way to get hold of urlgen without running the whole stack?

I should point out that I have verified that the new url_for_self method works, but only by adding a PDB call inside a view like user_home and running user.url_for_self(request.urlgen). That produces /u/ben/, which is the expected value. I just wondered if there was a neater way to do this.

comment:8 by rodney757, 11 years ago

Owner: set to Ben Sturmfels
Status: reviewin_progress

So this looks good.

It would be nice if you could write a test for this. I think it could go in test_modelmethods.py. I think you would need to do a GET request and then pull the request object out of the response, which you could then pass to the url_for_self method and verify that it does the correct thing. You can take a look at test_submission.py for an example of a test using request.urlgen.

If you could write that test, I will merge this.

comment:9 by berkerpeksag, 10 years ago

Owner: Ben Sturmfels removed
Status: in_progressreview

I've created issue686-url_for_self branch for this issue on Gitorious. The patch also has a test.

https://gitorious.org/mediagoblin/berkerpeksag-mediagoblin/source/1760aa94ff8fe6125bcade6411028fc19e162957:

comment:10 by Christopher Allan Webber, 10 years ago

Resolution: fixed
Status: reviewclosed

Merged. Great job berker!

Also added a small note to the merge:

    *Note from cwebber on merge of this branch:*
      Thanks also to Sturm who provided an early version of this patch.
Note: See TracTickets for help on using tickets.