本文整理汇总了Python中account.models.User方法的典型用法代码示例。如果您正苦于以下问题:Python models.User方法的具体用法?Python models.User怎么用?Python models.User使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类account.models
的用法示例。
在下文中一共展示了models.User方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sign_in
# 需要导入模块: from account import models [as 别名]
# 或者: from account.models import User [as 别名]
def sign_in(request):
if request.method == "POST":
uf = UserForm(request.POST)
if uf.is_valid():
email = uf.cleaned_data['email']
password = uf.cleaned_data['password']
user = User.objects.filter(email=email, password=password)
if user:
tip = "????"
return render_to_response('sign_in.html', {'uf':uf, 'tip':tip})
else:
tip = "???????"
return render_to_response('sign_in.html', {'uf':uf, 'tip':tip})
else:
uf = UserForm()
return render_to_response('sign_in.html', {'uf':uf})
示例2: sign_up
# 需要导入模块: from account import models [as 别名]
# 或者: from account.models import User [as 别名]
def sign_up(request):
if request.method == "POST":
uf = UserForm(request.POST)
if uf.is_valid():
email = uf.cleaned_data['email']
password = uf.cleaned_data['password']
user = User.objects.get(email=email)
if user:
tip = "??????????"
return render_to_response('sign_up.html', {'uf':uf, 'tip':tip})
else:
user = User()
user.email = email
user.password = password
user.save()
tip = "???????????"
return render_to_response('sign_up.html',{'uf':uf, 'tip':tip})
else:
uf = UserForm()
return render_to_response('sign_up.html',{'uf':uf})
示例3: user
# 需要导入模块: from account import models [as 别名]
# 或者: from account.models import User [as 别名]
def user(self, db):
user = mixer.blend(User)
return user
示例4: create
# 需要导入模块: from account import models [as 别名]
# 或者: from account.models import User [as 别名]
def create(self, validated_data):
"""
Create a new user from the serializer's validated data.
This also sends out an email to the user confirming their email
address.
Args:
validated_data:
The data to create the new user from.
Returns:
The newly created ``User`` instance.
"""
logger.info(
'Registering new user with email: %s',
validated_data['email'])
user = User.objects.create_user(**validated_data)
email = EmailAddress.objects.create(
email=self.validated_data['email'],
user=user)
confirmation = EmailConfirmation.objects.create(email=email)
confirmation.send_confirmation()
return user
示例5: create_submission
# 需要导入模块: from account import models [as 别名]
# 或者: from account.models import User [as 别名]
def create_submission(problem, author: User, code, lang, contest=None, status=SubmissionStatus.WAITING, ip=''):
if not 6 <= len(code) <= 65536:
raise ValueError("Code is too short or too long.")
if author.submission_set.exists() and (
datetime.now() - author.submission_set.first().create_time).total_seconds() < 10:
raise ValueError("Please don't resubmit in 10 seconds.")
if isinstance(problem, (int, str)):
return Submission.objects.create(lang=lang, code=code, author=author, problem_id=problem, contest=contest,
status=status, status_private=status, ip=ip)
else:
return Submission.objects.create(lang=lang, code=code, author=author, problem=problem, contest=contest,
status=status, status_private=status, ip=ip)
示例6: query_user
# 需要导入模块: from account import models [as 别名]
# 或者: from account.models import User [as 别名]
def query_user(kw):
results = list()
if kw and len(kw) >= 3:
for user in User.objects.filter(username__icontains=kw, is_active=True).all().only('username')[:5]:
results.append(dict(title=user.username, url=reverse('generic', kwargs=dict(pk=user.pk))))
return dict(name='User', results=results)
示例7: get
# 需要导入模块: from account import models [as 别名]
# 或者: from account.models import User [as 别名]
def get(self, request):
kw = request.GET.get('kw')
results = list()
if kw:
for user in User.objects.filter(username__icontains=kw, is_active=True).all().only('username', 'pk')[:5]:
results.append(dict(name=user.username, value=user.pk))
return Response(dict(success=True, results=results))
示例8: get_queryset
# 需要导入模块: from account import models [as 别名]
# 或者: from account.models import User [as 别名]
def get_queryset(self):
self.user = get_object_or_404(User, pk=self.kwargs.get('pk'))
qs = self.user.blog_set.all().with_likes().with_likes_flag(self.request.user)
if not is_admin_or_root(self.request.user) and not self.request.user == self.user:
qs = qs.filter(visible=True)
return qs
示例9: post
# 需要导入模块: from account import models [as 别名]
# 或者: from account.models import User [as 别名]
def post(self, request):
user = get_object_or_404(User, username=request.POST['name'])
return HttpResponseRedirect(reverse('generic', kwargs={'pk': user.pk}))
示例10: add_users
# 需要导入模块: from account import models [as 别名]
# 或者: from account.models import User [as 别名]
def add_users(self, *users: User):
for user in users:
UserConversation.objects.create(conversation=self, user=user)
示例11: submission_count_api
# 需要导入模块: from account import models [as 别名]
# 或者: from account.models import User [as 别名]
def submission_count_api(request, name):
user = get_object_or_404(User, username=name)
now = datetime.datetime.now()
one_year_ago = now.replace(year=now.year - 1)
submissions = Submission.objects.filter(author=user, create_time__gte=one_year_ago)
result = {submission.create_time.timestamp(): 1 for submission in submissions}
return JsonResponse(result)
示例12: update_rank
# 需要导入模块: from account import models [as 别名]
# 或者: from account.models import User [as 别名]
def update_rank(self, submission):
if not submission.contest_id or submission.contest_id != self.contest_id:
raise ValueError("Error submission type")
if User.objects.get(id=submission.user_id).admin_type == SUPER_ADMIN:
logger.warning("SUPER_ADMIN is cheating in the contest!")
return
if submission.result == result["system_error"]:
logger.warning("submission " + submission.id + " result is system error, update rank operation is ignored")
return
# ????????
if str(submission.problem_id) in self.submission_info:
info = self.submission_info[str(submission.problem_id)]
# ???????? ac ????
if info["is_ac"]:
return
self.total_submission_number += 1
if submission.result == result["accepted"]:
self.total_ac_number += 1
info["is_ac"] = True
info["ac_time"] = (submission.create_time - self.contest.start_time).total_seconds()
# ??????????????????????????????????
self.total_time += (info["ac_time"] + info["error_number"] * 20 * 60)
problem = ContestProblem.objects.get(id=submission.problem_id)
# ????????? ???1
if problem.total_accepted_number == 1:
info["is_first_ac"] = True
else:
info["error_number"] += 1
info["is_ac"] = False
else:
# ?????????
self.total_submission_number += 1
info = {"is_ac": False, "ac_time": 0, "error_number": 0, "is_first_ac": False}
if submission.result == result["accepted"]:
self.total_ac_number += 1
info["is_ac"] = True
info["ac_time"] = (submission.create_time - self.contest.start_time).total_seconds()
self.total_time += info["ac_time"]
problem = ContestProblem.objects.get(id=submission.problem_id)
if problem.total_accepted_number == 1:
info["is_first_ac"] = True
else:
info["is_ac"] = False
info["error_number"] = 1
self.submission_info[str(submission.problem_id)] = info
self.save()