本文整理汇总了Python中website.project.model.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
super(TestUserGet, self).setUp()
User.remove()
self.user_1 = AuthUserFactory()
self.auth = Auth(user=self.user_1)
self.project = ProjectFactory(creator=self.user_1)
self.project.add_unregistered_contributor(email="[email protected]", fullname="Weezy F. Baby", auth=self.auth)
self.user_3 = AuthUserFactory()
self.user_3.date_confirmed = None
self.user_3.save()
self.user_4 = AuthUserFactory()
示例2: remove_2_factor
def remove_2_factor(request, guid):
user = User.load(guid)
try:
user.delete_addon('twofactor')
except AttributeError:
page_not_found(request)
return redirect(reverse_user(guid))
示例3: serialize_simple_user
def serialize_simple_user(user_info):
user = User.load(user_info[0])
return {
'id': user._id,
'name': user.fullname,
'permission': reduce_permissions(user_info[1]) if user_info[1] else None,
}
示例4: form_valid
def form_valid(self, form):
osf_id = form.cleaned_data.get('osf_id')
osf_user = User.load(osf_id)
try:
osf_user.system_tags.append(PREREG_ADMIN_TAG)
except AttributeError:
raise Http404(('OSF user with id "{}" not found.'
' Please double check.').format(osf_id))
new_user = MyUser.objects.create_user(
email=form.cleaned_data.get('email'),
password=form.cleaned_data.get('password1')
)
new_user.first_name = form.cleaned_data.get('first_name')
new_user.last_name = form.cleaned_data.get('last_name')
new_user.osf_id = osf_id
for group in form.cleaned_data.get('group_perms'):
new_user.groups.add(group)
new_user.save()
reset_form = PasswordRecoveryForm(
data={'username_or_email': new_user.email}
)
if reset_form.is_valid():
send = Recover()
send.request = self.request
send.form_valid(reset_form)
messages.success(self.request, 'Registration successful!')
return super(RegisterUser, self).form_valid(form)
示例5: get_context_data
def get_context_data(self, **kwargs):
user = User.load(self.kwargs.get('guid'))
try:
self.initial.setdefault('emails', [(r, r) for r in user.emails])
except AttributeError:
raise
kwargs.setdefault('guid', user.pk)
return super(ResetPasswordView, self).get_context_data(**kwargs)
示例6: get_object
def get_object(self, queryset=None):
customer_id = self.kwargs.get('user_id', None)
customer = User.load(customer_id)
email = customer.emails[0]
desk = DeskClient(self.request.user)
params = {'email': email}
customer = desk.find_customer(params)
return customer
示例7: get_queryset
def get_queryset(self):
customer_id = self.kwargs.get('user_id', None)
customer = User.load(customer_id)
email = customer.emails[0]
desk = DeskClient(self.request.user)
params = {
'email': email,
}
queryset = desk.cases(params)
return queryset
示例8: get_context_data
def get_context_data(self, **kwargs):
self.guid = self.kwargs.get('guid', None)
try:
user = User.load(self.guid)
except AttributeError:
raise
self.initial.setdefault('emails', [(r, r) for r in user.emails])
kwargs.setdefault('guid', self.guid)
kwargs.setdefault('form', self.get_form()) # TODO: 1.9 xx
return super(ResetPasswordView, self).get_context_data(**kwargs)
示例9: get_active_user_count
def get_active_user_count(time):
query = (
Q('date_registered', 'lt', time) &
Q('is_registered', 'eq', True) &
Q('password', 'ne', None) &
Q('merged_by', 'eq', None) &
Q('date_confirmed', 'ne', None) &
Q('date_disabled', ' eq', None)
)
return User.find(query).count()
示例10: _validate_reports
def _validate_reports(value, *args, **kwargs):
for key, val in value.iteritems():
if not User.load(key):
raise ValidationValueError('Keys must be user IDs')
if not isinstance(val, dict):
raise ValidationTypeError('Values must be dictionaries')
if ('category' not in val or 'text' not in val or 'date' not in val or 'retracted' not in val):
raise ValidationValueError(
('Values must include `date`, `category`, ',
'`text`, `retracted` keys')
)
示例11: get_context_data
def get_context_data(self, **kwargs):
user = User.load(self.kwargs.get('guid'))
try:
self.initial.setdefault('emails', [(r, r) for r in user.emails])
except AttributeError:
raise Http404(
'{} with id "{}" not found.'.format(
self.context_object_name.title(),
self.kwargs.get('guid')
))
kwargs.setdefault('guid', user.pk)
return super(ResetPasswordView, self).get_context_data(**kwargs)
示例12: serialize_comment
def serialize_comment(comment, full=False):
reports = serialize_reports(comment.reports)
author_abs_url = furl(OSF_DOMAIN)
author_abs_url.path.add(comment.user.url)
return {
'id': comment._id,
'author': User.load(comment.user._id),
'author_path': author_abs_url.url,
'date_created': comment.date_created,
'date_modified': comment.date_modified,
'content': comment.content,
'has_children': bool(getattr(comment, 'commented', [])),
'modified': comment.modified,
'is_deleted': comment.is_deleted,
'reports': reports,
'node': comment.node,
'category': reports[0]['category'],
}
示例13: delete
def delete(self, request, *args, **kwargs):
user_ids = [
uid for uid in request.POST.keys()
if uid != 'csrfmiddlewaretoken'
]
for uid in user_ids:
user = User.load(uid)
if 'spam_flagged' in user.system_tags:
user.system_tags.remove('spam_flagged')
user.system_tags.append('spam_confirmed')
user.save()
update_admin_log(
user_id=self.request.user.id,
object_id=uid,
object_repr='User',
message='Confirmed SPAM: {}'.format(uid),
action_flag=CONFIRM_SPAM
)
return redirect('users:flagged-spam')
示例14: revoke_oauth_access
def revoke_oauth_access(self, external_account, auth, save=True):
"""Revoke all access to an ``ExternalAccount``.
TODO: This should accept node and metadata params in the future, to
allow fine-grained revocation of grants. That's not yet been needed,
so it's not yet been implemented.
"""
for node in self.get_nodes_with_oauth_grants(external_account):
try:
node.get_addon(external_account.provider, deleted=True).deauthorize(auth=auth)
except AttributeError:
# No associated addon settings despite oauth grant
# Remove grant in `for` loop below
pass
if User.find(Q('external_accounts', 'eq', external_account._id)).count() == 1:
# Only this user is using the account, so revoke remote access as well.
self.revoke_remote_oauth_access(external_account)
for key in self.oauth_grants:
self.oauth_grants[key].pop(external_account._id, None)
if save:
self.save()
示例15: serialize_comment
def serialize_comment(comment):
reports = [
serialize_report(user, report)
for user, report in comment.reports.iteritems()
]
author_abs_url = furl(OSF_DOMAIN)
author_abs_url.path.add(comment.user.url)
return {
'id': comment._id,
'author': User.load(comment.user._id),
'author_id': comment.user._id,
'author_path': author_abs_url.url,
'date_created': comment.date_created,
'date_modified': comment.date_modified,
'content': comment.content,
'has_children': bool(getattr(comment, 'commented', [])),
'modified': comment.modified,
'is_deleted': comment.is_deleted,
'spam_status': comment.spam_status,
'reports': reports,
'node': comment.node,
'category': reports[0]['category'],
}