本文整理汇总了Python中pybossa.model.user.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: manage_user
def manage_user(access_token, user_data, next_url):
"""Manage the user after signin"""
# We have to store the oauth_token in the session to get the USER fields
user = user_repo.get_by(google_user_id=user_data['id'])
# user never signed on
if user is None:
google_token = dict(oauth_token=access_token)
info = dict(google_token=google_token)
name = user_data['name'].encode('ascii', 'ignore').lower().replace(" ", "")
user = user_repo.get_by_name(name)
email = user_repo.get_by(email_addr=user_data['email'])
if ((user is None) and (email is None)):
user = User(fullname=user_data['name'],
name=user_data['name'].encode('ascii', 'ignore')
.lower().replace(" ", ""),
email_addr=user_data['email'],
google_user_id=user_data['id'],
info=info)
user_repo.save(user)
return user
else:
return None
else:
# Update the name to fit with new paradigm to avoid UTF8 problems
if type(user.name) == unicode or ' ' in user.name:
user.name = user.name.encode('ascii', 'ignore').lower().replace(" ", "")
user_repo.update(user)
return user
开发者ID:chamaa,项目名称:pybossa,代码行数:32,代码来源:google.py
示例2: manage_user
def manage_user(access_token, user_data):
"""Manage the user after signin"""
# We have to store the oauth_token in the session to get the USER fields
user = user_repo.get_by(google_user_id=user_data['id'])
# user never signed on
if user is None:
google_token = dict(oauth_token=access_token)
info = dict(google_token=google_token)
name = username_from_full_name(user_data['name'])
user = user_repo.get_by_name(name)
email = user_repo.get_by(email_addr=user_data['email'])
if ((user is None) and (email is None)):
user = User(fullname=user_data['name'],
name=name,
email_addr=user_data['email'],
google_user_id=user_data['id'],
info=info)
user_repo.save(user)
if newsletter.is_initialized():
newsletter.subscribe_user(user)
return user
else:
return None
else:
# Update the name to fit with new paradigm to avoid UTF8 problems
if type(user.name) == unicode or ' ' in user.name:
user.name = username_from_full_name(user.name)
user_repo.update(user)
return user
开发者ID:Skytim,项目名称:pybossa,代码行数:33,代码来源:google.py
示例3: manage_user
def manage_user(access_token, user_data):
"""Manage the user after signin"""
user = user_repo.get_by(facebook_user_id=user_data['id'])
facebook_token = dict(oauth_token=access_token)
if user is None:
info = dict(facebook_token=facebook_token)
name = username_from_full_name(user_data['name'])
user_exists = user_repo.get_by_name(name) is not None
# NOTE: Sometimes users at Facebook validate their accounts without
# registering an e-mail (see this http://stackoverflow.com/a/17809808)
email_exists = (user_data.get('email') is not None and
user_repo.get_by(email_addr=user_data['email']) is not None)
if not user_exists and not email_exists:
if not user_data.get('email'):
user_data['email'] = name
user = User(fullname=user_data['name'],
name=name,
email_addr=user_data['email'],
facebook_user_id=user_data['id'],
info=info)
user_repo.save(user)
if newsletter.is_initialized() and user.email_addr != name:
newsletter.subscribe_user(user)
return user
else:
return None
else:
user.info['facebook_token'] = facebook_token
user_repo.save(user)
return user
开发者ID:anukat2015,项目名称:pybossa,代码行数:32,代码来源:facebook.py
示例4: public_get_user_summary
def public_get_user_summary(name):
"""Sanitize user summary for public usage"""
private_user = get_user_summary(name)
public_user = None
if private_user is not None:
u = User()
public_user = u.to_public_json(data=private_user)
return public_user
开发者ID:influencerplus123,项目名称:tinybee.ai,代码行数:8,代码来源:users.py
示例5: create_users
def create_users(cls):
root = User(
email_addr = cls.root_addr,
name = cls.root_name,
passwd_hash = cls.root_password,
fullname = cls.fullname,
api_key = cls.root_api_key)
root.set_password(cls.root_password)
user = User(
email_addr = cls.email_addr,
name = cls.name,
passwd_hash = cls.password,
fullname = cls.fullname,
api_key = cls.api_key)
user.set_password(cls.password)
user2 = User(
email_addr = cls.email_addr2,
name = cls.name2,
passwd_hash = cls.password + "2",
fullname = cls.fullname2,
api_key=cls.api_key_2)
user2.set_password(cls.password)
return root, user, user2
开发者ID:PyBossa,项目名称:pybossa,代码行数:28,代码来源:default.py
示例6: fixtures
def fixtures():
'''Create some fixtures!'''
with app.app_context():
user = User(
name=u'tester',
email_addr=u'[email protected]',
api_key='tester'
)
user.set_password(u'tester')
db.session.add(user)
db.session.commit()
开发者ID:TMoneyZ,项目名称:pybossa,代码行数:11,代码来源:cli.py
示例7: test_user_public_info_keys
def test_user_public_info_keys(self):
"""Test public info keys works."""
user = User(
email_addr="[email protected]",
name="johndoe",
fullname="John Doe",
info=dict(avatar='image.png', container='foldr3', token='security'),
locale="en")
public_info_keys = ['avatar', 'container']
user.set_password("juandiso")
assert public_info_keys.sort() == user.public_info_keys().sort()
data = user.to_public_json()
err_msg = "There are some keys that should not be public"
assert data.get('info').keys().sort() == public_info_keys.sort(), err_msg
开发者ID:PyBossa,项目名称:pybossa,代码行数:15,代码来源:test_model_user.py
示例8: test_user_errors
def test_user_errors(self):
"""Test USER model errors."""
user = User(
email_addr="[email protected]",
name="johndoe",
fullname="John Doe",
locale="en")
# User.name should not be nullable
user.name = None
db.session.add(user)
assert_raises(IntegrityError, db.session.commit)
db.session.rollback()
# User.fullname should not be nullable
user.name = "johndoe"
user.fullname = None
db.session.add(user)
assert_raises(IntegrityError, db.session.commit)
db.session.rollback()
# User.email_addr should not be nullable
user.name = "johndoe"
user.fullname = "John Doe"
user.email_addr = None
db.session.add(user)
assert_raises(IntegrityError, db.session.commit)
db.session.rollback()
开发者ID:PyBossa,项目名称:pybossa,代码行数:28,代码来源:test_model_user.py
示例9: test_all
def test_all(self):
"""Test MODEL works"""
username = u'test-user-1'
user = User(name=username, fullname=username, email_addr=username)
info = {
'total': 150,
'long_description': 'hello world'}
app = App(
name=u'My New Project',
short_name=u'my-new-app',
description=u'description',
info=info)
category = Category(name=u'cat', short_name=u'cat', description=u'cat')
app.category = category
app.owner = user
task_info = {
'question': 'My random question',
'url': 'my url'}
task = Task(info=task_info)
task_run_info = {'answer': u'annakarenina'}
task_run = TaskRun(info=task_run_info)
task.app = app
task_run.task = task
task_run.app = app
task_run.user = user
db.session.add_all([user, app, task, task_run])
db.session.commit()
app_id = app.id
db.session.remove()
app = db.session.query(App).get(app_id)
assert app.name == u'My New Project', app
# year would start with 201...
assert app.created.startswith('201'), app.created
assert app.long_tasks == 0, app.long_tasks
assert app.hidden == 0, app.hidden
assert app.time_estimate == 0, app
assert app.time_limit == 0, app
assert app.calibration_frac == 0, app
assert app.bolt_course_id == 0
assert len(app.tasks) == 1, app
assert app.owner.name == username, app
out_task = app.tasks[0]
assert out_task.info['question'] == task_info['question'], out_task
assert out_task.quorum == 0, out_task
assert out_task.state == "ongoing", out_task
assert out_task.calibration == 0, out_task
assert out_task.priority_0 == 0, out_task
assert len(out_task.task_runs) == 1, out_task
outrun = out_task.task_runs[0]
assert outrun.info['answer'] == task_run_info['answer'], outrun
assert outrun.user.name == username, outrun
user = User.by_name(username)
assert user.apps[0].id == app_id, user
开发者ID:IdahoInstitute,项目名称:pybossa,代码行数:56,代码来源:test_model_base.py
示例10: test_get_users_page_returns_fields
def test_get_users_page_returns_fields(self):
user = UserFactory.create()
TaskRunFactory.create(user=user)
fields = User.public_attributes()
users = cached_users.get_users_page(1)
for field in fields:
assert field in users[0].keys(), field
assert len(users[0].keys()) == len(fields)
开发者ID:PyBossa,项目名称:pybossa,代码行数:10,代码来源:test_cache_users.py
示例11: test_get_leaderboard_returns_fields
def test_get_leaderboard_returns_fields(self):
"""Test CACHE USERS get_leaderboard returns user fields"""
user = UserFactory.create()
TaskRunFactory.create(user=user)
fields = User.public_attributes()
update_leaderboard()
leaderboard = cached_users.get_leaderboard(1)
for field in fields:
assert field in leaderboard[0].keys(), field
assert len(leaderboard[0].keys()) == len(fields)
开发者ID:PyBossa,项目名称:pybossa,代码行数:12,代码来源:test_cache_users.py
示例12: get_users_page
def get_users_page(page, per_page=24):
"""Return users with a paginator."""
offset = (page - 1) * per_page
sql = text('''SELECT "user".id, "user".name,
"user".fullname, "user".email_addr,
"user".created, "user".info, COUNT(task_run.id) AS task_runs
FROM task_run, "user"
WHERE "user".id=task_run.user_id GROUP BY "user".id
ORDER BY "user".created DESC LIMIT :limit OFFSET :offset''')
results = session.execute(sql, dict(limit=per_page, offset=offset))
accounts = []
u = User()
for row in results:
user = dict(id=row.id, name=row.name, fullname=row.fullname,
email_addr=row.email_addr, created=row.created,
task_runs=row.task_runs, info=row.info,
registered_ago=pretty_date(row.created))
tmp = u.to_public_json(data=user)
accounts.append(tmp)
return accounts
开发者ID:influencerplus123,项目名称:tinybee.ai,代码行数:22,代码来源:users.py
示例13: test_user_public_attributes
def test_user_public_attributes(self):
"""Test public attributes works."""
user = User(
email_addr="[email protected]",
name="johndoe",
pro=1,
fullname="John Doe",
locale="en")
public_attributes = ['created', 'name', 'fullname', 'locale', 'info',
'task_runs', 'registered_ago', 'rank', 'score']
user.set_password("juandiso")
assert public_attributes.sort() == user.public_attributes().sort()
data = user.to_public_json()
err_msg = "There are some keys that should not be public"
assert data.keys().sort() == public_attributes.sort(), err_msg
all_attributes = user.dictize().keys()
s = set(public_attributes)
private_attributes = [x for x in all_attributes if x not in s]
for attr in private_attributes:
err_msg = "This attribute should be private %s" % attr
assert data.get(attr) is None, err_msg
开发者ID:PyBossa,项目名称:pybossa,代码行数:22,代码来源:test_model_user.py
示例14: test_domain_object_error
def test_domain_object_error(self):
"""Test DomainObject errors work."""
user = User()
user.name = "John"
d = user.dictize()
user.undictize(d)
开发者ID:IdahoInstitute,项目名称:pybossa,代码行数:6,代码来源:test_model_base.py
注:本文中的pybossa.model.user.User类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论