本文整理汇总了Python中pybossa.cache.users.get_user_summary函数的典型用法代码示例。如果您正苦于以下问题:Python get_user_summary函数的具体用法?Python get_user_summary怎么用?Python get_user_summary使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_user_summary函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: warm_cache
def warm_cache(): # pragma: no cover
"""Background job to warm cache."""
from pybossa.core import create_app
app = create_app(run_as_server=False)
projects_cached = []
import pybossa.cache.projects as cached_projects
import pybossa.cache.categories as cached_cat
import pybossa.cache.users as cached_users
import pybossa.cache.project_stats as stats
from pybossa.util import rank
from pybossa.core import user_repo
def warm_project(_id, short_name, featured=False):
if _id not in projects_cached:
#cached_projects.get_project(short_name)
#cached_projects.n_tasks(_id)
#n_task_runs = cached_projects.n_task_runs(_id)
#cached_projects.overall_progress(_id)
#cached_projects.last_activity(_id)
#cached_projects.n_completed_tasks(_id)
#cached_projects.n_volunteers(_id)
#cached_projects.browse_tasks(_id)
#if n_task_runs >= 1000 or featured:
# # print ("Getting stats for %s as it has %s task runs" %
# # (short_name, n_task_runs))
stats.update_stats(_id, app.config.get('GEO'))
projects_cached.append(_id)
# Cache top projects
projects = cached_projects.get_top()
for p in projects:
warm_project(p['id'], p['short_name'])
# Cache 3 pages
to_cache = 3 * app.config['APPS_PER_PAGE']
projects = rank(cached_projects.get_all_featured('featured'))[:to_cache]
for p in projects:
warm_project(p['id'], p['short_name'], featured=True)
# Categories
categories = cached_cat.get_used()
for c in categories:
projects = rank(cached_projects.get_all(c['short_name']))[:to_cache]
for p in projects:
warm_project(p['id'], p['short_name'])
# Users
users = cached_users.get_leaderboard(app.config['LEADERBOARD'])
for user in users:
# print "Getting stats for %s" % user['name']
print user_repo
u = user_repo.get_by_name(user['name'])
cached_users.get_user_summary(user['name'])
cached_users.projects_contributed_cached(u.id)
cached_users.published_projects_cached(u.id)
cached_users.draft_projects_cached(u.id)
return True
示例2: _show_own_profile
def _show_own_profile(user):
rank_and_score = cached_users.rank_and_score(user.id)
user.rank = rank_and_score['rank']
user.score = rank_and_score['score']
user.total = cached_users.get_total_users()
projects_contributed = cached_users.projects_contributed_cached(user.id)
projects_published, projects_draft = _get_user_projects(user.id)
cached_users.get_user_summary(user.name)
return render_template('account/profile.html', title=gettext("Profile"),
projects_contrib=projects_contributed,
projects_published=projects_published,
projects_draft=projects_draft,
user=user)
示例3: settings
def settings():
#user = User.query.get_or_404(current_user.id)
user, apps, apps_created = cached_users.get_user_summary(current_user.name)
title = "User: %s · Settings" % user['fullname']
return render_template('account/settings.html',
title=title,
user=user)
示例4: _show_own_profile
def _show_own_profile(user):
user_dict = cached_users.get_user_summary(user.name)
rank_and_score = cached_users.rank_and_score(user.id)
user.rank = rank_and_score['rank']
user.score = rank_and_score['score']
user.total = cached_users.get_total_users()
projects_contributed = cached_users.public_projects_contributed_cached(user.id)
projects_published, projects_draft = _get_user_projects(user.id)
cached_users.get_user_summary(user.name)
response = dict(template='account/profile.html', title=gettext("Profile"),
projects_contrib=projects_contributed,
projects_published=projects_published,
projects_draft=projects_draft,
user=user_dict)
return handle_content_type(response)
示例5: test_get_user_summary_returns_fields
def test_get_user_summary_returns_fields(self):
"""Test CACHE USERS get_user_summary all the fields in the dict"""
UserFactory.create(name='user')
fields = ('id', 'name', 'fullname', 'created', 'api_key',
'twitter_user_id', 'google_user_id', 'facebook_user_id',
'info', 'email_addr', 'n_answers', 'rank', 'score', 'total')
user = cached_users.get_user_summary('user')
for field in fields:
assert field in user.keys(), field
示例6: test_get_user_summary_user_exists
def test_get_user_summary_user_exists(self):
"""Test CACHE USERS get_user_summary returns a dict with the user data
if the user exists"""
UserFactory.create(name='zidane')
UserFactory.create(name='figo')
zizou = cached_users.get_user_summary('zidane')
assert type(zizou) is dict, type(zizou)
assert zizou != None, zizou
示例7: settings
def settings():
"""
Configure user settings.
Returns a Jinja2 template.
"""
# user = User.query.get_or_404(current_user.id)
user, apps, apps_created = cached_users.get_user_summary(current_user.name)
title = "User: %s · Settings" % user["fullname"]
return render_template("account/settings.html", title=title, user=user)
示例8: public_profile
def public_profile(name):
"""Render the public user profile"""
user, apps, apps_created = cached_users.get_user_summary(name)
if user:
title = "%s · User Profile" % user['fullname']
return render_template('/account/public_profile.html',
title=title,
user=user,
apps=apps,
apps_created=apps_created)
else:
abort(404)
示例9: _show_public_profile
def _show_public_profile(user):
user_dict = cached_users.get_user_summary(user.name)
projects_contributed = cached_users.projects_contributed_cached(user.id)
projects_created = cached_users.published_projects_cached(user.id)
if current_user.is_authenticated() and current_user.admin:
draft_projects = cached_users.draft_projects(user.id)
projects_created.extend(draft_projects)
title = "%s · User Profile" % user_dict['fullname']
return render_template('/account/public_profile.html',
title=title,
user=user_dict,
projects=projects_contributed,
projects_created=projects_created)
示例10: _show_public_profile
def _show_public_profile(user):
user_dict = cached_users.get_user_summary(user.name)
apps_contributed = cached_users.apps_contributed_cached(user.id)
apps_created = cached_users.published_apps_cached(user.id)
if current_user.is_authenticated() and current_user.admin:
apps_hidden = cached_users.hidden_apps(user.id)
apps_created.extend(apps_hidden)
if user_dict:
title = "%s · User Profile" % user_dict['fullname']
return render_template('/account/public_profile.html',
title=title,
user=user_dict,
apps=apps_contributed,
apps_created=apps_created)
示例11: _show_own_profile
def _show_own_profile(user):
rank_and_score = cached_users.rank_and_score(user.id)
user.rank = rank_and_score['rank']
user.score = rank_and_score['score']
user.total = cached_users.get_total_users()
apps_contributed = cached_users.apps_contributed_cached(user.id)
apps_published, apps_draft = _get_user_apps(user.id)
apps_published.extend(cached_users.hidden_apps(user.id))
return render_template('account/profile.html', title=gettext("Profile"),
apps_contrib=apps_contributed,
apps_published=apps_published,
apps_draft=apps_draft,
user=cached_users.get_user_summary(user.name))
示例12: add_metadata
def add_metadata(name):
"""
Admin can save metadata for selected user
Redirects to public profile page for selected user.
"""
user = user_repo.get_by_name(name=name)
form = UserPrefMetadataForm(request.form)
form.set_upref_mdata_choices()
if not form.validate():
if current_user.id == user.id:
user_dict = cached_users.get_user_summary(user.name)
else:
user_dict = cached_users.public_get_user_summary(user.name)
projects_contributed = cached_users.projects_contributed_cached(user.id)
projects_created = cached_users.published_projects_cached(user.id)
if current_user.is_authenticated() and current_user.admin:
draft_projects = cached_users.draft_projects(user.id)
projects_created.extend(draft_projects)
title = "%s · User Profile" % user.name
flash("Please fix the errors", 'message')
can_update = current_user.admin
return render_template('/account/public_profile.html',
title=title,
user=user_dict,
projects=projects_contributed,
projects_created=projects_created,
form=form,
can_update=can_update,
input_form=True)
user_pref, metadata = get_user_pref_and_metadata(name, form)
user.info['metadata'] = metadata
user.user_pref = user_pref
user_repo.update(user)
cached_users.delete_user_pref_metadata(user.name)
flash("Input saved successfully", "info")
return redirect(url_for('account.profile', name=name))
示例13: delete_user
def delete_user(name, confirmed):
"""
Deletes a user on pybossa
- Only admins will be able to delete other users.
- Does not let delete admin users.
Admin users will have to remove the user from the admin lists before they can delete then
- Marks all the task_runs of the specific user as anonymous
- Changes the ownership of all the projects owned by the user to the current_user
TODO: Clean this feature up and push this feature to pybossa core
"""
"""
Get the user object and contributed projects object from cache to enable
global helper functions to render it in a uniform way.
But Obtain the results from the non-memoized functions to get the latest state
"""
target_user = cached_users.get_user_summary(name)
if current_user.admin and target_user != None and current_user.id != target_user['id'] :
user_page_redirect = request.args.get('user_page_redirect')
if not user_page_redirect:
user_page_redirect = 1
if confirmed == "unconfirmed":
published_projects = cached_users.published_projects(target_user['id'])
draft_projects = cached_users.draft_projects(target_user['id'])
owned_projects = published_projects + draft_projects
return render_template('geotagx/users/delete_confirmation.html', \
target_user = target_user,
owned_projects = owned_projects,
user_page_redirect=user_page_redirect
)
elif confirmed == "confirmed":
"""
Retrieval of the User object necessary as the target_user object
obtained from `cached_users.get_user_summary` doesnot expose
the `admin` check that is necessary to prevent the user from
deleting other admin users, and also the SQLAlchemy `delete`
function
"""
user_object = User.query.filter_by(id=target_user['id']).first()
if user_object.admin:
# It is not allowed to delete other admin users
abort(404)
"""
Mark all task runs by the user as anonymous
Mark the user_ip field in the task_run by the username instead
to retain user identity for analytics
"""
task_runs = TaskRun.query.filter_by(user_id=target_user['id']).all()
for task_run in task_runs:
task_run.user_id = None
task_run.user_ip = "deleted_user_"+target_user['name']
db.session.commit()
"""
Change the ownership of all projects owned by the target user
to that of the current user
"""
projects = Project.query.filter_by(owner_id=target_user['id']).all()
for project in projects:
project.owner_id = current_user.id
db.session.commit()
"""
Clean cached data about the project
"""
cached_projects.clean_project(project.id)
"""
Delete the user from the database
"""
db.session.delete(user_object)
db.session.commit()
"""
Clean user data from the cache
Force Update current_user's data in the cache
"""
cached_users.delete_user_summary(target_user['id'])
cached_users.delete_user_summary(current_user.id)
flash("User <strong>"+target_user['name']+"</strong> has been successfully deleted, and all the projects owned by the user have been transferred to you.", 'success')
return redirect(url_for('geotagx-admin.manage_users', page=user_page_redirect))
else:
abort(404)
else:
abort(404)
示例14: update_profile
def update_profile(name):
"""
Update user's profile.
Returns Jinja2 template.
"""
user = User.query.filter_by(name=name).first()
if not user:
return abort(404)
require.user.update(user)
show_passwd_form = True
if user.twitter_user_id or user.google_user_id or user.facebook_user_id:
show_passwd_form = False
usr = cached_users.get_user_summary(name)
# Extend the values
current_user.rank = usr.get('rank')
current_user.score = usr.get('score')
# Title page
title_msg = "Update your profile: %s" % current_user.fullname
# Creation of forms
update_form = UpdateProfileForm(obj=user)
update_form.set_locales(current_app.config['LOCALES'])
avatar_form = AvatarUploadForm()
password_form = ChangePasswordForm()
external_form = update_form
if request.method == 'GET':
return render_template('account/update.html',
title=title_msg,
user=usr,
form=update_form,
upload_form=avatar_form,
password_form=password_form,
external_form=external_form,
show_passwd_form=show_passwd_form)
else:
# Update user avatar
if request.form.get('btn') == 'Upload':
avatar_form = AvatarUploadForm()
if avatar_form.validate_on_submit():
file = request.files['avatar']
coordinates = (avatar_form.x1.data, avatar_form.y1.data,
avatar_form.x2.data, avatar_form.y2.data)
prefix = time.time()
file.filename = "%s_avatar.png" % prefix
container = "user_%s" % current_user.id
uploader.upload_file(file,
container=container,
coordinates=coordinates)
# Delete previous avatar from storage
if current_user.info.get('avatar'):
uploader.delete_file(current_user.info['avatar'], container)
current_user.info = {'avatar': file.filename,
'container': container}
db.session.commit()
cached_users.delete_user_summary(current_user.name)
flash(gettext('Your avatar has been updated! It may \
take some minutes to refresh...'), 'success')
return redirect(url_for('.update_profile', name=current_user.name))
else:
flash("You have to provide an image file to update your avatar",
"error")
return render_template('/account/update.html',
form=update_form,
upload_form=avatar_form,
password_form=password_form,
external_form=external_form,
title=title_msg,
show_passwd_form=show_passwd_form)
# Update user profile
elif request.form.get('btn') == 'Profile':
update_form = UpdateProfileForm()
update_form.set_locales(current_app.config['LOCALES'])
if update_form.validate():
current_user.id = update_form.id.data
current_user.fullname = update_form.fullname.data
current_user.name = update_form.name.data
current_user.email_addr = update_form.email_addr.data
current_user.privacy_mode = update_form.privacy_mode.data
current_user.locale = update_form.locale.data
db.session.commit()
cached_users.delete_user_summary(current_user.name)
flash(gettext('Your profile has been updated!'), 'success')
return redirect(url_for('.update_profile', name=current_user.name))
else:
flash(gettext('Please correct the errors'), 'error')
title_msg = 'Update your profile: %s' % current_user.fullname
return render_template('/account/update.html',
form=update_form,
upload_form=avatar_form,
password_form=password_form,
external_form=external_form,
title=title_msg,
show_passwd_form=show_passwd_form)
# Update user password
elif request.form.get('btn') == 'Password':
# Update the data because passing it in the constructor does not work
#.........这里部分代码省略.........
示例15: update_profile
def update_profile(name):
"""
Update user's profile.
Returns Jinja2 template.
"""
user = user_repo.get_by_name(name)
if not user:
return abort(404)
ensure_authorized_to('update', user)
show_passwd_form = True
if user.twitter_user_id or user.google_user_id or user.facebook_user_id or user.wechat_user_id or user.weibo_user_id:
show_passwd_form = False
usr = cached_users.get_user_summary(name)
# Extend the values
user.rank = usr.get('rank')
user.score = usr.get('score')
btn = request.body.get('btn', 'None').capitalize()
if btn != 'Profile':
update_form = UpdateProfileForm(formdata=None, obj=user)
else:
update_form = UpdateProfileForm(obj=user)
update_form.set_locales(current_app.config['LOCALES'])
avatar_form = AvatarUploadForm()
password_form = ChangePasswordForm()
title_msg = "Update your profile: %s" % user.fullname
if request.method == 'POST':
# Update user avatar
succeed = False
btn = request.body.get('btn', 'None').capitalize()
if btn == 'Upload':
succeed = _handle_avatar_update(user, avatar_form)
# Update user profile
elif btn == 'Profile':
succeed = _handle_profile_update(user, update_form)
# Update user password
elif btn == 'Password':
succeed = _handle_password_update(user, password_form)
# Update user external services
elif btn == 'External':
succeed = _handle_external_services_update(user, update_form)
# Otherwise return 415
else:
return abort(415)
if succeed:
cached_users.delete_user_summary(user.name)
return redirect_content_type(url_for('.update_profile',
name=user.name),
status=SUCCESS)
else:
data = dict(template='/account/update.html',
form=update_form,
upload_form=avatar_form,
password_form=password_form,
title=title_msg,
show_passwd_form=show_passwd_form)
return handle_content_type(data)
data = dict(template='/account/update.html',
form=update_form,
upload_form=avatar_form,
password_form=password_form,
title=title_msg,
show_passwd_form=show_passwd_form)
return handle_content_type(data)