Skip to content

Commit

Permalink
Merge pull request #510 from PyBossa/issue-509-public-profile
Browse files Browse the repository at this point in the history
Issue 509 public profile
  • Loading branch information
teleyinex committed May 10, 2013
2 parents 1c2a59a + 9a27852 commit 26b2b8d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 34 deletions.
71 changes: 37 additions & 34 deletions pybossa/cache/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,40 +65,43 @@ def get_user_summary(name):
SELECT * from global_rank WHERE user_id=:user_id;
''')

results = db.engine.execute(sql, user_id=user['id'])
for row in results:
user['rank'] = row.rank
user['score'] = row.score
if user:
results = db.engine.execute(sql, user_id=user['id'])
for row in results:
user['rank'] = row.rank
user['score'] = row.score

# Get the APPs where the USER has participated
sql = text('''
SELECT app.id, app.name, app.short_name, app.info,
COUNT(task_run.app_id) AS n_answers FROM app, task_run
WHERE app.id=task_run.app_id AND
task_run.user_id=:user_id GROUP BY app.id
ORDER BY n_answers DESC;
''')
results = db.engine.execute(sql, user_id=user['id'])
apps = []
for row in results:
app = dict(id=row.id, name=row.name, info=dict(json.loads(row.info)),
short_name=row.short_name,
n_answers=row.n_answers)
apps.append(app)
# Get the APPs where the USER has participated
sql = text('''
SELECT app.id, app.name, app.short_name, app.info,
COUNT(task_run.app_id) AS n_answers FROM app, task_run
WHERE app.id=task_run.app_id AND
task_run.user_id=:user_id GROUP BY app.id
ORDER BY n_answers DESC;
''')
results = db.engine.execute(sql, user_id=user['id'])
apps = []
for row in results:
app = dict(id=row.id, name=row.name, info=dict(json.loads(row.info)),
short_name=row.short_name,
n_answers=row.n_answers)
apps.append(app)

# Get the CREATED APPS by the USER
sql = text('''
SELECT app.id, app.name, app.short_name, app.info, app.created
FROM app
WHERE app.owner_id=:user_id
ORDER BY app.created DESC;
''')
results = db.engine.execute(sql, user_id=user['id'])
apps_created = []
for row in results:
app = dict(id=row.id, name=row.name,
short_name=row.short_name,
info=dict(json.loads(row.info)))
apps_created.append(app)
# Get the CREATED APPS by the USER
sql = text('''
SELECT app.id, app.name, app.short_name, app.info, app.created
FROM app
WHERE app.owner_id=:user_id
ORDER BY app.created DESC;
''')
results = db.engine.execute(sql, user_id=user['id'])
apps_created = []
for row in results:
app = dict(id=row.id, name=row.name,
short_name=row.short_name,
info=dict(json.loads(row.info)))
apps_created.append(app)

return user, apps, apps_created
return user, apps, apps_created
else:
return None, None, None
6 changes: 6 additions & 0 deletions test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -1712,6 +1712,12 @@ def test_70_public_user_profile(self):
res = self.app.get(url, follow_redirects=True)
assert Fixtures.fullname in res.data, err_msg

# Should return 404 when a user does not exist
url = '/account/a-fake-name-that-does-not-exist/'
res = self.app.get(url, follow_redirects=True)
err_msg = "It should return a 404"
assert res.status_code == 404, err_msg

@patch('pybossa.view.importer.requests.get')
def test_71_bulk_epicollect_import_unauthorized(self, Mock):
"""Test WEB bulk import unauthorized works"""
Expand Down

0 comments on commit 26b2b8d

Please sign in to comment.