Opened 13 years ago

Last modified 13 years ago

#44 closed defect (FIXED)

Basic user profile page, also bios

Reported by: Christopher Allan Webber Owned by: Caleb Davis
Priority: minor Milestone: 0.0.3
Component: programming Keywords:
Cc: Parent Tickets:

Description

Say we have the user cwebber, and we want to find out all about
cwebber! A little bio, what are the latest images, etc.

Accessing:

[http://mediagoblin.example.org/\ :sub:`cwebber/](http://mediagoblin.example.org/`\ cwebber/)

Should show a few of the latest images (not all, that's
[http://mediagoblin.example.org/\ :sub:`cwebber/gallery/](http://mediagoblin.example.org/`\ cwebber/gallery/)
) and also a personal bio, if a user has provided one.

Additionally
`http://mediagoblin.example.org/settings/profile/ <http://mediagoblin.example.org/settings/profile/>`_
should allow me to change my profile (for now, just adding a simple
bio is fine). It would be great to wrap that work into this
ticket.



Attachments (2)

0001-Improve-user-homepage.patch (3.4 KB ) - added by Sebastian Spaeth 13 years ago.
0001-Improve-user-homepage.patch
0001-Improve-user-homepage.patch.1 (3.8 KB ) - added by Sebastian Spaeth 13 years ago.
0001-Improve-user-homepage.patch

Download all attachments as: .zip

Change History (27)

comment:1 by Christopher Allan Webber, 13 years ago

Owner: set to Ami Ganguli
Assigning this to Ami Ganguli.

Ami, as said, I know this is a tough first bug, so don't worry if
it's a bit hard, and don't be afraid to ask for guidance on IRC.

Thanks for working on this!



comment:2 by Christopher Allan Webber, 13 years ago

Sebastean Spaeth did some staring work on this, but it's not really
ready or finished.

::

    def user_home(request):
        """'Homepage' of a User()""" 
        user = request.db.User.find_one(
            {'username': request.matchdict['user']})
    
        medias = request.db.MediaEntry.find()
        [...]

It looks like "medias" is not being filtered here by user.



comment:3 by Ami Ganguli, 13 years ago

Ah, that's a useful bit. My next step was figuring out how to the
DB queries work :-).

The task seems simple enough - the biggest job is understanding the
architecture and doing it the "right" way.



by Sebastian Spaeth, 13 years ago

0001-Improve-user-homepage.patch

comment:4 by Sebastian Spaeth, 13 years ago

Hi there, I don't want to take anyone's work, so sorry if I am
stepping on anyone's toes.

Attached a smallish patch that improves the current placeholder
with something actually semi-useful :)

You can pull this from

::

    git://gitorious.org/~spaetz/mediagoblin/spaetz-mediagoblin.git

branch: \_bug315\_user*page*

::

        Improve user homepage
    
        1) Only consider user's with 'status': 'active'. We don't want to
           display unconfirmed/blocked users, right?
        2) Actually query user's media in the view and display on their home
           page.
        3) Throw an error 404 if we don't find a valid user, rather than saying,
           "User not found" (from within the template).
        4) Pass in medias as media_entries to remain compatible with the 'root'
           page.

I am unsure about change `#3 </issues/3>`_. Do we want to throw an
error 404 if we call a user page that e.g. does not exist or is not
"active"? Or do we want to render the template (HTTP CODE 200)
saying, "user does not exist"? Ideally, we'd render that template
with a return code 404 :)

A side effect of this patch is that we import "exc" which actually
makes the 404 error on the media homepage work. exc is used there
but never imported ;).

Again, sorry if I duplicate work. Ami, feel free to build on this
or to discard it.



by Sebastian Spaeth, 13 years ago

0001-Improve-user-homepage.patch

comment:5 by Sebastian Spaeth, 13 years ago

Latest version, ignore previous one.



comment:6 by Christopher Allan Webber, 13 years ago

About to look at the patches, thanks Spaeth.

Ami, half of this task is still remaining and is fairly bitesized.
If you need help with that, I suggest looking at the auth views
which show some stuff about changing properties and saving and
requiring an active user (via a decorator).



comment:7 by Ami Ganguli, 13 years ago

Yup, will look at it again on the weekend and try to finish up
anything that hasn't been addressed.

Not so much time during the week (at least this week),
unfortunately.



comment:8 by Christopher Allan Webber, 13 years ago

Milestone: 0.0.2

comment:8 by Christopher Allan Webber, 13 years ago

Spaetz, just reviewed: looks great, merged.



comment:9 by Elrond, 13 years ago

What exactly needs to be done to address this issue?



comment:10 by Christopher Allan Webber, 13 years ago

-  description type bio
-  homepage

and both have a page where they can set that info and also allow
that to be displayed on the user pages that we already have. :)



comment:11 by Elrond, 13 years ago

Milestone: 0.0.20.0.3
bios for 0.0.3.
Joar Wandborg is interested in this, it seems (from todays
meeting).



comment:12 by Elrond, 13 years ago

Component: Programming
Owner: changed from Ami Ganguli to Joar Wandborg
As per Chris Webber reassigning to Joar.



comment:13 by Elrond, 13 years ago

Owner: set to Joar Wandborg
Joar is a bit too busy. :-)



comment:14 by Caleb Davis, 13 years ago

I added an is315 branch, and will see how far I get on this!



comment:15 by Caleb Davis, 13 years ago

I'm not sure if the route to edit the profile goes in ../edit or
../user\_pages.

../edit seems intuitive, but it's currently not in use.



comment:16 by Christopher Allan Webber, 13 years ago

Put it in edit. Thanks!



comment:17 by Caleb Davis, 13 years ago

enter a url and bio for your user page. It's primitive, but it
works :)

[https://gitorious.org/\ :sub:`cfdv/mediagoblin/cfdvs-mediagoblin/commits/is315](https://gitorious.org/`\ cfdv/mediagoblin/cfdvs-mediagoblin/commits/is315)



comment:18 by Caleb Davis, 13 years ago

-  mediagoblin/templates/mediagoblin/root.html has the 'edit
   profile' link
-  link route = mediagoblin.edit.profile
-  route in mediagoblin/edit/routing.py points to controller
-  controller = mediagoblin.edit.views:edit\_profile
-  edit\_profile controller in mediagoblin/edit/views.py
-  receives incoming EditProfileForm fields set and validated in
   mediagoblin/edit/forms.py
-  if incoming form fields validate then save to database
   *\* url and bio fields added to User table in mediagoblin/db/models.py*
   *\* then return to the root.html page where you started*
-  otherwise render a form using
   mediagoblin/edit/edit*profile.html template*\*
   wtforms\_util.render*divs(form) does this*
   \_\* the action of the form is to send the form fields to
   edit*profile controller*



comment:19 by Christopher Allan Webber, 13 years ago

Owner: set to Caleb Davis
This is looking really great. There's only one thing this is
missing and that's migrations. See db/migrations.py and
`http://namlook.github.com/mongokit/migration.html <http://namlook.github.com/mongokit/migration.html>`_

and absolutely feel free to ping me on IRC if this is confusing :)



comment:20 by Caleb Davis, 13 years ago

huh, what a great idea - migrations...

Not sure how to test whether this works, but here's what I did -
[https://gitorious.org/\ :sub:`cfdv/mediagoblin/cfdvs-mediagoblin/commit/e36ecab0931f25d65169bfcf26d8a56d33eef02a](https://gitorious.org/`\ cfdv/mediagoblin/cfdvs-mediagoblin/commit/e36ecab0931f25d65169bfcf26d8a56d33eef02a)



comment:21 by Christopher Allan Webber, 13 years ago

That looks right, though not sure why you're checking for whether
or not 'username' exists.

Nitpicks :)

Align like:

::

            self.target = {'username': {'$exists': True},
                           'url': {'$exists': False},
                           'bio': {'$exists': False}}

Add a space here between the two strings:

::

    MIGRATE_CLASSES = ['MediaEntry', 'User']

Did you have any users that you created before you added these
changes? (If not, check out a revision prior to your adding the
migration, add a user, switch back to your current branch
post-migration... just look in your git history for the git id of
the commit prior to migration and do "git checkout
ab53515acblablabla" and then git checkout your branchname again
when done). What you'll want to do is this:

::

    $ ./bin/gmg shell
    >>> list(db.User.find({'url': {'$exists': False}}))
    # your pre-migration users should show up here
    >>> exit()
    $ ./bin/gmg migrate
    # migrations should run
    $ ./bin/gmg shell
    >>> list(db.User.find({'url': {'$exists': False}}))
    # should be empty
    >>> list(db.User.find())
    # you should see some users with the migrations applied

Make sense?

Looking good!



comment:22 by Caleb Davis, 13 years ago

Christopher Webber wrote:

    That looks right, though not sure why you're checking for whether
    or not 'username' exists.


Not for any good reason, so I took out the username check

Whitespace fixed

After adding a migration\_handler to the User model the tests you
suggested passed.

::

    >>> list(db.User.find({'url': {'$exists': False}}))
    [{u'username': u'dev_user2', u'pw_hash': ... }]
    >>> list(db.User.find({'url': {'$exists': True}}))
    [{u'username': u'dev_user', u'pw_hash': ... }]
    >>> exit()
    
    
    
    
    
    
    $ ./bin/gmg migrate
    Applying migrations...
    UserMigration : allmigration01_add_bio_and_url_profile >>> deprecated
    ... done.
    $ ./bin/gmg shell
    
    
    
    
    
    
    >>> list(db.User.find({'url': {'$exists': False}}))
    []
    >>> list(db.User.find())
    [{u'username': u'dev_user', u'pw_hash': ... }, {u'username': u'dev_user2', u'pw_hash': ... }]



comment:23 by Christopher Allan Webber, 13 years ago

Status: NewClosed
It works! Thanks for your work on this :)

I've merged the branch and pushed it!



comment:24 by Will Kahn-Greene, 12 years ago

The original url for this bug was http://bugs.foocorp.net/issues/315 .

Note: See TracTickets for help on using tickets.