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 more user info to profiles #581

Merged
merged 5 commits into from
Apr 21, 2015
Merged
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
24 changes: 23 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,28 @@ 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>
${_('This user joined OSM ')} <span class="timeago" title="${creation_date}"></span>.
</p>
% 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