From fe23498b2e266c2366252e79aeea8cee813f214a Mon Sep 17 00:00:00 2001 From: ethan-nelson Date: Thu, 22 Jan 2015 22:43:22 -0600 Subject: [PATCH 1/5] adding user info to page --- osmtm/templates/user.mako | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/osmtm/templates/user.mako b/osmtm/templates/user.mako index d9341aa2..6c70760e 100644 --- a/osmtm/templates/user.mako +++ b/osmtm/templates/user.mako @@ -18,7 +18,7 @@ else:

${_('User: ${username}', mapping={'username': contributor.username})}

-
+
% if user == contributor:

${_('This is You!')|n} @@ -29,6 +29,30 @@ else: [OSM]${_('OSM Profile')}

+
+ % if creation_date: +

+ ${_('This user joined OSM on ${join_date}.', mapping={'join_date':creation_date[5:7] + \ + '/' + creation_date[8:10] + '/' + \ + creation_date[0:4]})} +

+ % endif +
+
+
+ +
+ % if changeset_count: +

+ ${_('This user has submitted ${changes} total changesets.', mapping={'changes':changeset_count})} +

+ % endif +
From 522fdec682f60b682b402ea304623aa456b09fb6 Mon Sep 17 00:00:00 2001 From: ethan-nelson Date: Thu, 22 Jan 2015 22:43:57 -0600 Subject: [PATCH 2/5] adding user info definitions --- osmtm/views/user.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/osmtm/views/user.py b/osmtm/views/user.py index 5dae2c27..cc6e8922 100644 --- a/osmtm/views/user.py +++ b/osmtm/views/user.py @@ -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): @@ -157,3 +160,22 @@ 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] + changesets_count = changesets_el.getAttribute('count') + + except: + # don't lock application if no reponse can be received from OSM API + pass + + return creation_date, changesets_count From 4ebea009f06b8433d076c011c3e9efbb3c49bab5 Mon Sep 17 00:00:00 2001 From: ethan-nelson Date: Thu, 22 Jan 2015 23:06:44 -0600 Subject: [PATCH 3/5] error handling fixes --- osmtm/templates/user.mako | 4 ++-- osmtm/views/user.py | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/osmtm/templates/user.mako b/osmtm/templates/user.mako index 6c70760e..7ed9bf75 100644 --- a/osmtm/templates/user.mako +++ b/osmtm/templates/user.mako @@ -30,7 +30,7 @@ else:

- % if creation_date: + % if creation_date != 'null':

${_('This user joined OSM on ${join_date}.', mapping={'join_date':creation_date[5:7] + \ '/' + creation_date[8:10] + '/' + \ @@ -47,7 +47,7 @@ else:

- % if changeset_count: + % if changeset_count != 'null':

${_('This user has submitted ${changes} total changesets.', mapping={'changes':changeset_count})}

diff --git a/osmtm/views/user.py b/osmtm/views/user.py index cc6e8922..61b61850 100644 --- a/osmtm/views/user.py +++ b/osmtm/views/user.py @@ -172,10 +172,12 @@ def get_addl_user_info(user_id): creation_date = user_el.getAttribute('account_created') changesets_el = xmldoc.getElementsByTagName('changesets')[0] - changesets_count = changesets_el.getAttribute('count') + changeset_count = changesets_el.getAttribute('count') except: # don't lock application if no reponse can be received from OSM API - pass + creation_date = 'null' + chageset_count = 'null' + + return creation_date, changeset_count - return creation_date, changesets_count From 540d66065245d186d54ffe7c5c755e653a44c69d Mon Sep 17 00:00:00 2001 From: Ethan Date: Thu, 22 Jan 2015 23:17:25 -0600 Subject: [PATCH 4/5] fix typo throwing travis error --- osmtm/views/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osmtm/views/user.py b/osmtm/views/user.py index 61b61850..3d95cbe5 100644 --- a/osmtm/views/user.py +++ b/osmtm/views/user.py @@ -177,7 +177,7 @@ def get_addl_user_info(user_id): except: # don't lock application if no reponse can be received from OSM API creation_date = 'null' - chageset_count = 'null' + changeset_count = 'null' return creation_date, changeset_count From 0bbb2e9a488e7bc0ccd04068cc0d327c7c4057e7 Mon Sep 17 00:00:00 2001 From: Ethan Date: Thu, 22 Jan 2015 23:25:05 -0600 Subject: [PATCH 5/5] flake8 fixes --- osmtm/views/user.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osmtm/views/user.py b/osmtm/views/user.py index 3d95cbe5..4fed1c3b 100644 --- a/osmtm/views/user.py +++ b/osmtm/views/user.py @@ -119,7 +119,7 @@ def user(request): projects = __get_projects(user.id) return dict(page_id="user", contributor=user, projects=projects, - creation_date=creation_date, changeset_count=changeset_count) + creation_date=creation_date, changeset_count=changeset_count) def __get_projects(user_id): @@ -180,4 +180,3 @@ def get_addl_user_info(user_id): changeset_count = 'null' return creation_date, changeset_count -