Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding additional user info to user page #538

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion osmtm/templates/user.mako
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ else:
<div class="container">
<div class="row">
<h3>${_('User: ${username}', mapping={'username': contributor.username})}</h3>
<div class="col-md-12">
<div class="col-md-6">
% if user == contributor:
<p>
${_('This is <b>You</b>!')|n}
Expand All @@ -29,6 +29,30 @@ else:
<img src="http://www.openstreetmap.org/favicon.ico" alt="[OSM]" />${_('OSM Profile')}</a>
</p>
</div>
<div class="col-md-6">
% if creation_date != 'null':
<p title=${creation_date}>
${_('This user joined OSM on ${join_date}.', mapping={'join_date':creation_date[5:7] + \
'/' + creation_date[8:10] + '/' + \
creation_date[0:4]})}
</p>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be great to have localized dates.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Acknowledged. Will work on this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't forgotten about this :) got busy with work, but will get back to this soon.

% endif
</div>
</div>
<div class="row">
<div class="col-md-6">
<p>
<a href="http://www.openstreetmap.org/user/${contributor.username}/history" title="${_('OSM User Changeset History')}">
${_('OSM Edit History')}</a>
</p>
</div>
<div class="col-md-6">
% if changeset_count != 'null':
<p>
${_('This user has submitted ${changes} total changesets.', mapping={'changes':changeset_count})}
</p>
% endif
</div>
</div>
<div class="row">
<div class="col-md-12">
Expand Down
25 changes: 24 additions & 1 deletion osmtm/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,16 @@ def user(request):
return HTTPFound(location=route_path('users', request))

user = check_user_name(user)
creation_date, changeset_count = get_addl_user_info(user.id)

# username has changed
if user.username != username:
return HTTPFound(location=route_path('user', request,
username=user.username))

projects = __get_projects(user.id)
return dict(page_id="user", contributor=user, projects=projects)
return dict(page_id="user", contributor=user, projects=projects,
creation_date=creation_date, changeset_count=changeset_count)


def __get_projects(user_id):
Expand Down Expand Up @@ -157,3 +160,23 @@ def username_to_userid(username):
id_ = DBSession.query(User.id).filter(User.username == username).scalar()

return str(id_) if id_ else username


def get_addl_user_info(user_id):
''' Get the number of changesets by a user from OSM API.'''
try:
url = 'http://www.openstreetmap.org/api/0.6/user/%s' % user_id
usock = urllib2.urlopen(url)
xmldoc = minidom.parse(usock)
user_el = xmldoc.getElementsByTagName('user')[0]
creation_date = user_el.getAttribute('account_created')

changesets_el = xmldoc.getElementsByTagName('changesets')[0]
changeset_count = changesets_el.getAttribute('count')

except:
# don't lock application if no reponse can be received from OSM API
creation_date = 'null'
changeset_count = 'null'

return creation_date, changeset_count