本文整理汇总了Python中user.models.User.get_users方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_users方法的具体用法?Python User.get_users怎么用?Python User.get_users使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类user.models.User
的用法示例。
在下文中一共展示了User.get_users方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: members
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_users [as 别名]
def members(request, version, format):
if request.method == 'GET':
require_focus(request)
try:
if 'sherpa_id' in request.GET and 'medlemsnummer' in request.GET:
user = User.get_users(include_pending=True).get(id=request.GET['sherpa_id'], memberid=request.GET['medlemsnummer'])
elif 'sherpa_id' in request.GET:
user = User.get_users(include_pending=True).get(id=request.GET['sherpa_id'])
elif 'medlemsnummer' in request.GET:
try:
user = User.get_or_create_inactive(memberid=request.GET['medlemsnummer'], include_pending=True)
except (Enrollment.DoesNotExist, ValueError):
# No such member
raise User.DoesNotExist
else:
raise BadRequest(
u"You must supply either an 'sherpa_id' or 'medlemsnummer' parameter for member lookup",
code=error_codes.MISSING_REQUIRED_PARAMETER,
http_code=400
)
return HttpResponse(json.dumps(get_member_data(user)))
except (User.DoesNotExist, ValueError):
raise BadRequest(
u"A member matching that 'sherpa_id', 'medlemsnummer', or both if both were provided, does not exist.",
code=error_codes.RESOURCE_NOT_FOUND,
http_code=404
)
else:
raise BadRequest(
u"Unsupported HTTP verb",
code=error_codes.UNSUPPORTED_HTTP_VERB,
http_code=400
)
示例2: attempt_login
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_users [as 别名]
def attempt_login(request):
matches = authenticate_users(request.POST['email'], request.POST['password'])
if len(matches) == 1:
# Exactly one match, cool, just authenticate the user
user = authenticate(user=matches[0])
log_user_in(request, user)
return matches, None
elif len(matches) > 1:
# Multiple matches, let the caller handle this
return matches, None
elif len(matches) == 0:
# Incorrect credentials. Check if this is a user from the old userpage system
old_member = authenticate_sherpa2_user(request.POST['email'], request.POST['password'])
if old_member is not None:
# Actually, it is! Let's try to import them.
if User.get_users().filter(memberid=old_member.memberid, is_inactive=False).exists():
return matches, 'old_memberid_but_memberid_exists'
# Check if a pending user exists. This shouldn't ever happen (a pending user is recently
# enrolled, and an existing user will have been member for a long time).
if User.objects.filter(memberid=old_member.memberid, is_pending=True).exists():
# Give the same error ("user exists, you need to use your new password")
return matches, 'old_memberid_but_memberid_exists'
# Verify that they exist in the membersystem (this turned out to be an incorrect assumption)
if not Actor.get_personal_members().filter(memberid=old_member.memberid).exists():
# We're not quite sure why this can happen, so we'll just give them the invalid
# credentials message - but this might be confusing for those who were able to log
# in previously.
return matches, 'invalid_credentials'
# Create the new user
try:
# Check if the user's already created as inactive
user = User.get_users().get(memberid=old_member.memberid, is_inactive=True)
user.is_inactive = False
user.set_password(request.POST['password'])
user.save()
except User.DoesNotExist:
# New user
user = User(identifier=old_member.memberid, memberid=old_member.memberid)
user.set_password(request.POST['password'])
user.save()
# Update the email on this actor, in case it were to differ from the sherpa2 email
user.update_personal_data({'email': request.POST['email']})
# Import any fjelltreffen-annonser from the old system
import_fjelltreffen_annonser(user)
authenticate(user=user)
log_user_in(request, user)
return [user], None
else:
# No luck, just provide the error message
return matches, 'invalid_credentials'
示例3: search
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_users [as 别名]
def search(request):
if not request.is_ajax() or request.method != 'POST':
return redirect('admin.users.views.index')
if len(request.POST['q']) < settings.ADMIN_USER_SEARCH_CHAR_LENGTH:
raise PermissionDenied
local_users = User.get_users().filter(memberid__isnull=True)
for word in request.POST['q'].split():
local_users = local_users.filter(
Q(first_name__icontains=word) |
Q(last_name__icontains=word))
local_users = local_users.order_by('first_name')
actors = Actor.get_personal_members()
for word in request.POST['q'].split():
actors = actors.filter(
Q(first_name__icontains=word) |
Q(last_name__icontains=word) |
Q(memberid__icontains=word))
actors = actors.order_by('first_name')
# Match expired users only on memberid
expired_users = User.objects.all()
for word in request.POST['q'].split():
expired_users = expired_users.filter(memberid__icontains=word)
expired_users = [u for u in expired_users if not Actor.get_personal_members().filter(memberid=u.memberid).exists()]
# Pending users
pending_enrollment = Enrollment.get_active()
for word in request.POST['q'].split():
pending_enrollment = pending_enrollment.filter(
Q(first_name__icontains=word) |
Q(last_name__icontains=word) |
Q(memberid__icontains=word))
pending_enrollment = pending_enrollment.order_by('first_name')
members = User.get_users().filter(memberid__in=[a.memberid for a in actors])
pending_users = User.get_users(include_pending=True).filter(memberid__in=[e.memberid for e in pending_enrollment])
actors_without_user = [a for a in actors if a.memberid not in list(members.values_list('memberid', flat=True))]
users = list(local_users) + list(members) + list(pending_users)
context = RequestContext(request, {
'users': users,
'actors_without_user': actors_without_user,
'expired_users': expired_users
})
return HttpResponse(render_to_string('common/admin/users/user_results.html', context))
示例4: get_queryset
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_users [as 别名]
def get_queryset(self):
# This method uses Focus and local users to compile a search result
# containing users.
# See the comment on the class definition of the lazy_queryset variable
if self.lazy_queryset:
return self.lazy_queryset
SEARCH_MAX_HITS = 100
search = self.request.query_params.get('search', '').strip()
if len(search) < settings.ADMIN_USER_SEARCH_CHAR_LENGTH:
raise PermissionDenied
local_users = User.get_users()
for word in search.split():
local_users = local_users.filter(
Q(first_name__icontains=word) |
Q(last_name__icontains=word) |
Q(email__icontains=word))
local_users = local_users.order_by('first_name')[:SEARCH_MAX_HITS]
users = sorted(list(local_users), key=lambda u: u.get_full_name(True))
self.lazy_queryset = users
return users
示例5: login_chosen_user
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_users [as 别名]
def login_chosen_user(request):
if 'authenticated_users' not in request.session:
return redirect('user:login.login')
if 'user' not in request.POST:
del request.session['authenticated_users']
return redirect('user:login.login')
# Verify that the user authenticated for this user
if not int(request.POST['user']) in request.session['authenticated_users']:
del request.session['authenticated_users']
return redirect('user:login.login')
# All is swell, log the user in
user = User.get_users(include_pending=True).get(id=request.POST['user'], is_inactive=False)
user = authenticate(user=user)
log_user_in(request, user)
del request.session['authenticated_users']
if request.site.is_central():
return redirect(request.GET.get('next', reverse('user:home')))
else:
if 'sso_checked' in request.session:
del request.session['sso_checked']
return redirect(sso_login_url(
request.site,
request.user,
request.GET.get('next', reverse('user:home')),
))
示例6: users_remove_access
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_users [as 别名]
def users_remove_access(request, forening_id):
current_forening = Forening.objects.get(id=forening_id)
if current_forening not in request.user.all_foreninger():
raise PermissionDenied
# Verify that the user has admin access to the association
cur_user_is_valid = request.user.has_perm(
'sherpa/association/admin',
association_id=current_forening.id,
)
# ... or is Sherpa admin
if not cur_user_is_valid and not request.user.has_perm('sherpa/admin'):
raise PermissionDenied
other_user = User.get_users(
include_pending=True).get(id=request.POST['user'])
other_user.remove_perm(
'sherpa/association/user',
association_id=current_forening.id,
)
other_user.remove_perm(
'sherpa/association/admin',
association_id=current_forening.id,
)
messages.info(request, 'permission_deleted')
cache.delete('user.%s.all_foreninger' % other_user.id)
return redirect('admin:foreninger.users', current_forening.id)
示例7: _save__process_article__authors
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_users [as 别名]
def _save__process_article__authors(request, version, response):
"""Update authors for the article"""
publisher_list = json.loads(request.POST['authors'])
if len(publisher_list) > 0:
publishers = User.get_users().filter(id__in=publisher_list)
version.publishers = publishers
else:
response['author_error'] = 'no_authors'
示例8: signon_choose_authenticated_user
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_users [as 别名]
def signon_choose_authenticated_user(request):
if not 'authenticated_users' in request.session or not 'dntconnect' in request.session:
raise PermissionDenied
users = User.get_users(include_pending=True).filter(id__in=request.session['authenticated_users'], is_inactive=False)
context = {
'users': sorted(users, key=lambda u: u.get_first_name())
}
return render(request, 'central/connect/signon_choose_authenticated_user.html', context)
示例9: forening
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_users [as 别名]
def forening(request, version, format):
if request.method == 'GET':
require_focus(request)
librato.increment('sherpa.api.tailored.forening.request')
if 'bruker_sherpa_id' in request.GET or 'bruker_medlemsnummer' in request.GET:
try:
# Lookup by specified members' access
if 'bruker_sherpa_id' in request.GET and 'bruker_medlemsnummer' in request.GET:
user = User.get_users(include_pending=True).get(id=request.GET['bruker_sherpa_id'], memberid=request.GET['bruker_medlemsnummer'])
elif 'bruker_sherpa_id' in request.GET:
user = User.get_users(include_pending=True).get(id=request.GET['bruker_sherpa_id'])
elif 'bruker_medlemsnummer' in request.GET:
try:
user = User.get_or_create_inactive(memberid=request.GET['bruker_medlemsnummer'])
except (User.DoesNotExist, ValueError):
# No such member
raise User.DoesNotExist
foreninger = [get_forening_data(f) for f in user.all_foreninger()]
librato.increment('sherpa.api.tailored.forening.response.200')
return HttpResponse(json.dumps(foreninger))
except (User.DoesNotExist, ValueError):
librato.increment('sherpa.api.tailored.forening.response.404')
raise BadRequest(
"A member matching that 'sherpa_id', 'bruker_medlemsnummer', or both if both were provided, does not exist.",
code=error_codes.RESOURCE_NOT_FOUND,
http_code=404
)
else:
librato.increment('sherpa.api.tailored.forening.response.400')
raise BadRequest(
"You must supply either a 'bruker_sherpa_id' or 'bruker_medlemsnummer' parameter for forening lookup by member. Only this form of forening-lookup is implemented in this version.",
code=error_codes.MISSING_REQUIRED_PARAMETER,
http_code=400
)
else:
librato.increment('sherpa.api.tailored.forening.response.400')
raise BadRequest(
"Unsupported HTTP verb",
code=error_codes.UNSUPPORTED_HTTP_VERB,
http_code=400
)
示例10: add_family_member
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_users [as 别名]
def add_family_member(request):
if request.method != 'POST' \
or 'memberid' not in request.POST \
or 'country' not in request.POST \
or (request.POST['country'] == 'NO' and 'zipcode' not in request.POST):
return redirect('user:family')
try:
# Include pending users in order to give an explicit error message
new_family_member = User.get_users(include_pending=True).get(memberid=request.POST['memberid'])
except (User.DoesNotExist, ValueError):
messages.error(request, 'user_does_not_exist')
return redirect('user:family')
if not new_family_member.is_member():
messages.error(request, 'user_is_not_member')
return redirect('user:family')
if new_family_member.address.country.code != request.POST['country']:
messages.error(request, 'invalid_address')
return redirect('user:family')
if new_family_member.address.country.code == 'NO' \
and new_family_member.address.zipcode.zipcode != request.POST['zipcode']:
messages.error(request, 'invalid_address')
return redirect('user:family')
if new_family_member.is_pending:
messages.error(request, 'user_is_pending')
return redirect('user:family')
if new_family_member == request.user:
messages.error(request, 'user_is_current_user')
return redirect('user:family')
if new_family_member.has_family():
messages.error(request, 'user_has_family')
return redirect('user:family')
if new_family_member.is_lifelong_member():
messages.error(request, 'user_is_lifelong_member')
return redirect('user:family')
if new_family_member.get_dnt_age() >= settings.MEMBERSHIP['AGES']['MAIN'] \
and request.user.family.has_max_adult_members():
messages.error(request, 'user_is_adult_and_max_adults_reached')
return redirect('user:family')
assert request.user.has_family(), "User without family (single or not) should not be able to add family members"
try:
request.user.family.add_family_member(new_family_member)
librato.increment('sherpa.medlemmer.familiemedlemskap.legg_til.eksisterende')
except FocusServiceError:
messages.error(request, 'focus_service_error')
finally:
return redirect('user:family')
示例11: choose_authenticated_user
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_users [as 别名]
def choose_authenticated_user(request):
if not 'authenticated_users' in request.session:
return redirect('user.login.views.login')
users = User.get_users(include_pending=True).filter(id__in=request.session['authenticated_users'], is_inactive=False)
context = {
'users': sorted(users, key=lambda u: u.get_first_name()),
'next': request.GET.get('next')
}
return render(request, 'common/user/login/choose_authenticated_user.html', context)
示例12: memberid_sms
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_users [as 别名]
def memberid_sms(request, user_id):
try:
user = User.get_users(include_pending=True).get(id=user_id)
if user.get_phone_mobile() == '':
# This shouldn't happen, but handle it just in case
return HttpResponse(json.dumps({
'status': 'missing_number'
}))
return HttpResponse(json.dumps(send_sms_receipt(request, user)))
except User.DoesNotExist:
return HttpResponse()
示例13: edit_active_foreninger
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_users [as 别名]
def edit_active_foreninger(request, user):
user = User.get_users().get(id=user)
user.turleder_active_foreninger.clear()
if json.loads(request.POST['active_foreninger_all']):
user.turleder_active_foreninger = Forening.objects.filter(type='forening')
else:
for forening_id in json.loads(request.POST['active_forening_ids']):
user.turleder_active_foreninger.add(Forening.objects.get(id=forening_id))
messages.info(request, "success")
return redirect('%s#turledersertifikat' % reverse('admin:users.show', args=[user.id]))
示例14: edit_instruktor_roles
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_users [as 别名]
def edit_instruktor_roles(request, user):
user = User.get_users().get(id=user)
Instruktor.objects.filter(user=user).delete()
for role in Instruktor.ROLE_CHOICES:
if role['key'] in request.POST:
instruktor = Instruktor(user=user, role=role['key'])
instruktor.save()
cache.delete('admin.turleder_count')
messages.info(request, "success")
return redirect('%s#turledersertifikat' % reverse('admin:users.show', args=[user.id]))
示例15: login_chosen_user
# 需要导入模块: from user.models import User [as 别名]
# 或者: from user.models.User import get_users [as 别名]
def login_chosen_user(request):
if 'authenticated_users' not in request.session:
return redirect('user:login.login')
if 'user' not in request.POST:
del request.session['authenticated_users']
return redirect('user:login.login')
# Verify that the user authenticated for this user
if not int(request.POST['user']) in request.session['authenticated_users']:
del request.session['authenticated_users']
return redirect('user:login.login')
# All is swell, log the user in
user = User.get_users(include_pending=True).get(id=request.POST['user'], is_inactive=False)
user = authenticate(user=user)
log_user_in(request, user)
del request.session['authenticated_users']
if request.session.get('OAuth-authorization'):
try:
o = urlparse(request.GET.get('next', None))
client_id = [a[1] for a in parse_qsl(o.query) if a[0] == 'client_id'][0]
user.last_login_oauth_date = datetime.now()
user.save()
log, created = UserOauthActiveLog.objects.get_or_create(
user=user,
oauth_client_id=client_id,
defaults={
'first_date': user.last_login_oauth_date,
'last_date': user.last_login_oauth_date
})
if not created:
log.last_date = user.last_login_oauth_date
log.save()
except:
pass
else:
user.last_login_site_date = datetime.now()
user.save()
if request.site.is_central():
return redirect(request.GET.get('next', reverse('user:home')))
else:
if 'sso_checked' in request.session:
del request.session['sso_checked']
return redirect(sso_login_url(
request.site,
request.user,
request.GET.get('next', reverse('user:home')),
))