本文整理汇总了Python中utils.shortcuts.success_response函数的典型用法代码示例。如果您正苦于以下问题:Python success_response函数的具体用法?Python success_response怎么用?Python success_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了success_response函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: put
def put(self, request):
"""
同意或者拒绝加入小组请求
---
request_serializer: PutJoinGroupRequestSerializer
"""
serializer = PutJoinGroupRequestSerializer(data=request.data)
if serializer.is_valid():
data = serializer.data
try:
join_request = JoinGroupRequest.objects.get(id=data["request_id"], group__admin=request.user,
status=False)
except JoinGroupRequest.DoesNotExist:
return error_response(u"请求不存在")
join_request.status = True
join_request.save()
if data["status"]:
if join_group(join_request.user, join_request.group):
join_request.accepted = True
join_request.save()
return success_response(u"加入成功")
else:
return error_response(u"加入失败,已经在本小组内")
else:
return success_response(u"已拒绝")
else:
return serializer_invalid_response(serializer)
开发者ID:isheng5,项目名称:OnlineJudge,代码行数:29,代码来源:views.py
示例2: post
def post(self, request):
"""
加入某个小组的api
---
request_serializer: CreateJoinGroupRequestSerializer
"""
serializer = CreateJoinGroupRequestSerializer(data=request.data)
if serializer.is_valid():
data = serializer.data
try:
group = Group.objects.get(id=data["group_id"])
except Group.DoesNotExist:
return error_response(u"小组不存在")
if group.join_group_setting == 0:
if join_group(request.user, group):
return success_response(u"你已经成功的加入该小组")
else:
return error_response(u"你已经是小组成员了")
elif group.join_group_setting == 1:
if not data["message"]:
return error_response(u"message : 该字段是必填项。")
try:
JoinGroupRequest.objects.get(user=request.user, group=group, status=False)
return error_response(u"你已经提交过申请了,请等待审核")
except JoinGroupRequest.DoesNotExist:
JoinGroupRequest.objects.create(user=request.user, group=group, message=data["message"])
return success_response(u"申请提交成功,请等待审核")
elif group.join_group_setting == 2:
return error_response(u"该小组不允许任何人加入")
else:
return serializer_invalid_response(serializer)
开发者ID:isheng5,项目名称:OnlineJudge,代码行数:31,代码来源:views.py
示例3: post
def post(self, request):
"""
用户登录json api接口
---
request_serializer: UserLoginSerializer
"""
serializer = UserLoginSerializer(data=request.data)
if serializer.is_valid():
data = serializer.data
user = auth.authenticate(username=data["username"], password=data["password"])
# 用户名或密码错误的话 返回None
if user:
if not user.two_factor_auth:
auth.login(request, user)
return success_response(u"登录成功")
# 没有输入两步验证的验证码
if user.two_factor_auth and "tfa_code" not in data:
return success_response("tfa_required")
if OtpAuth(user.tfa_token).valid_totp(data["tfa_code"]):
auth.login(request, user)
return success_response(u"登录成功")
else:
return error_response(u"验证码错误")
else:
return error_response(u"用户名或密码错误")
else:
return serializer_invalid_response(serializer)
开发者ID:ArchFeh,项目名称:OnlineJudge,代码行数:29,代码来源:views.py
示例4: get
def get(self, request):
"""
判断用户登录是否需要验证码
---
"""
username = request.GET.get("username", None)
if username:
try:
User.objects.get(username=username, admin_type__gt=0)
except User.DoesNotExist:
return success_response({"applied_captcha": False})
return success_response({"applied_captcha": True})
return success_response({"applied_captcha": False})
开发者ID:hujingguang,项目名称:OnlineJudge,代码行数:13,代码来源:views.py
示例5: post
def post(self, request):
"""
检测邮箱是否存在,存在返回True,不存在返回False
---
request_serializer: EmailCheckSerializer
"""
serializer = EmailCheckSerializer(data=request.data)
if serializer.is_valid():
try:
User.objects.get(email=serializer.data["email"])
return success_response(True)
except User.DoesNotExist:
return success_response(False)
else:
return serializer_invalid_response(serializer)
开发者ID:pathminer,项目名称:OnlineJudge,代码行数:15,代码来源:views.py
示例6: post
def post(self, request):
"""
提交请求重置密码
---
request_serializer: ApplyResetPasswordSerializer
"""
serializer = ApplyResetPasswordSerializer(data=request.data)
if serializer.is_valid():
data = serializer.data
captcha = Captcha(request)
if not captcha.check(data["captcha"]):
return error_response(u"验证码错误")
try:
user = User.objects.get(email=data["email"])
except User.DoesNotExist:
return error_response(u"用户不存在")
if user.reset_password_token_create_time and (now() - user.reset_password_token_create_time).total_seconds() < 20 * 60:
return error_response(u"20分钟内只能找回一次密码")
user.reset_password_token = rand_str()
user.reset_password_token_create_time = now()
user.save()
email_template = codecs.open(settings.TEMPLATES[0]["DIRS"][0] + "utils/reset_password_email.html", "r", "utf-8").read()
email_template = email_template.replace("{{ username }}", user.username).\
replace("{{ website_name }}", settings.WEBSITE_INFO["website_name"]).\
replace("{{ link }}", request.scheme + "://" + request.META['HTTP_HOST'] + "/reset_password/t/" + user.reset_password_token)
send_email(settings.WEBSITE_INFO["website_name"],
user.email,
user.username,
settings.WEBSITE_INFO["website_name"] + u" 登录信息找回邮件",
email_template)
return success_response(u"邮件发送成功,请前往您的邮箱查收")
else:
return serializer_invalid_response(serializer)
开发者ID:adamwen829,项目名称:OnlineJudge,代码行数:35,代码来源:views.py
示例7: get
def get(self, request):
"""
题目分页json api接口
---
response_serializer: ProblemSerializer
"""
problem_id = request.GET.get("problem_id", None)
if problem_id:
try:
# 普通管理员只能获取自己创建的题目
# 超级管理员可以获取全部的题目
problem = Problem.objects.get(id=problem_id)
if request.user.admin_type != SUPER_ADMIN and problem.created_by != request.user:
return error_response(u"题目不存在")
return success_response(ProblemSerializer(problem).data)
except Problem.DoesNotExist:
return error_response(u"题目不存在")
# 获取问题列表
problems = Problem.objects.all().order_by("-create_time")
if request.user.admin_type != SUPER_ADMIN:
problems = problems.filter(created_by=request.user)
visible = request.GET.get("visible", None)
if visible:
problems = problems.filter(visible=(visible == "true"))
keyword = request.GET.get("keyword", None)
if keyword:
problems = problems.filter(Q(title__contains=keyword) |
Q(description__contains=keyword))
return paginate(request, problems, ProblemSerializer)
开发者ID:8cbx,项目名称:OnlineJudge,代码行数:33,代码来源:views.py
示例8: put
def put(self, request):
"""
比赛题目编辑json api接口
---
request_serializer: EditContestProblemSerializer
response_serializer: ContestProblemSerializer
"""
serializer = EditContestProblemSerializer(data=request.data)
if serializer.is_valid():
data = serializer.data
try:
contest_problem = ContestProblem.objects.get(id=data["id"])
except ContestProblem.DoesNotExist:
return error_response(u"该比赛题目不存在!")
contest = Contest.objects.get(id=contest_problem.contest_id)
if request.user.admin_type != SUPER_ADMIN and contest.created_by != request.user:
return error_response(u"比赛不存在")
contest_problem.title = data["title"]
contest_problem.description = data["description"]
contest_problem.input_description = data["input_description"]
contest_problem.output_description = data["output_description"]
contest_problem.test_case_id = data["test_case_id"]
contest_problem.time_limit = data["time_limit"]
contest_problem.memory_limit = data["memory_limit"]
contest_problem.samples = json.dumps(data["samples"])
contest_problem.hint = data["hint"]
contest_problem.visible = data["visible"]
contest_problem.sort_index = data["sort_index"]
contest_problem.last_update_time = now()
contest_problem.save()
return success_response(ContestProblemSerializer(contest_problem).data)
else:
return serializer_invalid_response(serializer)
开发者ID:adamwen829,项目名称:OnlineJudge,代码行数:34,代码来源:views.py
示例9: post
def post(self, request):
serializer = SubmissionRejudgeSerializer(data=request.data)
if serializer.is_valid():
submission_id = serializer.data["submission_id"]
try:
submission = Submission.objects.get(id=submission_id)
except Submission.DoesNotExist:
return error_response(u"提交不存在")
# 目前只考虑前台公开题目的重新判题
try:
problem = Problem.objects.get(id=submission.problem_id)
except Problem.DoesNotExist:
return error_response(u"题目不存在")
try:
judge.delay(submission_id, problem.time_limit, problem.memory_limit, problem.test_case_id)
except Exception as e:
logger.error(e)
return error_response(u"提交判题任务失败")
# 增加redis 中判题队列长度的计数器
r = redis.Redis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"])
r.incr("judge_queue_length")
return success_response(u"任务提交成功")
else:
return serializer_invalid_response(serializer)
开发者ID:Timeship,项目名称:OnlineJudge-QDU,代码行数:25,代码来源:views.py
示例10: post
def post(self, request):
"""
创建比赛的提交
---
request_serializer: CreateContestSubmissionSerializer
"""
serializer = CreateContestSubmissionSerializer(data=request.data)
if serializer.is_valid():
data = serializer.data
contest = Contest.objects.get(id=data["contest_id"])
try:
problem = ContestProblem.objects.get(contest=contest, id=data["problem_id"])
# 更新题目提交计数器
problem.total_submit_number += 1
problem.save()
except ContestProblem.DoesNotExist:
return error_response(u"题目不存在")
submission = Submission.objects.create(user_id=request.user.id, language=int(data["language"]),
contest_id=contest.id, code=data["code"], problem_id=problem.id)
try:
judge.delay(submission.id, problem.time_limit, problem.memory_limit, problem.test_case_id)
except Exception:
return error_response(u"提交判题任务失败")
# 增加redis 中判题队列长度的计数器
r = redis.Redis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"])
r.incr("judge_queue_length")
return success_response({"submission_id": submission.id})
else:
return serializer_invalid_response(serializer)
开发者ID:hujingguang,项目名称:OnlineJudge,代码行数:29,代码来源:views.py
示例11: post
def post(self, request):
"""
用户登录json api接口
---
request_serializer: UserLoginSerializer
"""
serializer = UserLoginSerializer(data=request.data)
if serializer.is_valid():
data = serializer.data
if "captcha" not in data:
return error_response(u"请填写验证码!")
captcha = Captcha(request)
if not captcha.check(data["captcha"]):
return error_response(u"验证码错误")
user = auth.authenticate(username=data["username"], password=data["password"])
# 用户名或密码错误的话 返回None
if user:
auth.login(request, user)
return success_response(u"登录成功")
else:
return error_response(u"用户名或密码错误")
else:
return serializer_invalid_response(serializer)
开发者ID:eduStack,项目名称:OnlineJudge,代码行数:25,代码来源:views.py
示例12: get
def get(self, request):
"""
比赛分页json api接口
---
response_serializer: ContestSerializer
"""
contest_id = request.GET.get("contest_id", None)
if contest_id:
try:
# 普通管理员只能获取自己创建的题目
# 超级管理员可以获取全部的题目
contest = Contest.objects.get(id=contest_id)
if request.user.admin_type != SUPER_ADMIN:
contest_set = Contest.objects.filter(groups__in=request.user.managed_groups.all())
if contest not in contest_set:
return error_response(u"比赛不存在")
return success_response(ContestSerializer(contest).data)
except Contest.DoesNotExist:
return error_response(u"比赛不存在")
if request.user.admin_type == SUPER_ADMIN:
contest = Contest.objects.all().order_by("-create_time")
else:
contest = Contest.objects.filter(groups__in=request.user.managed_groups.all()).distinct().order_by("-create_time")
visible = request.GET.get("visible", None)
if visible:
contest = contest.filter(visible=(visible == "true"))
keyword = request.GET.get("keyword", None)
if keyword:
contest = contest.filter(Q(title__contains=keyword) |
Q(description__contains=keyword))
return paginate(request, contest, ContestSerializer)
开发者ID:adamwen829,项目名称:OnlineJudge,代码行数:32,代码来源:views.py
示例13: post
def post(self, request):
"""
创建比赛的提交
---
request_serializer: CreateContestSubmissionSerializer
"""
serializer = CreateContestSubmissionSerializer(data=request.data)
if serializer.is_valid():
data = serializer.data
contest = Contest.objects.get(id=data["contest_id"])
try:
problem = ContestProblem.objects.get(contest=contest, id=data["problem_id"])
except ContestProblem.DoesNotExist:
return error_response(u"题目不存在")
submission = Submission.objects.create(user_id=request.user.id,
language=int(data["language"]),
contest_id=contest.id,
code=data["code"],
problem_id=problem.id)
try:
_judge.delay(submission.id, problem.time_limit, problem.memory_limit, problem.test_case_id,
problem.spj, problem.spj_language, problem.spj_code, problem.spj_version)
except Exception as e:
logger.error(e)
return error_response(u"提交判题任务失败")
return success_response({"submission_id": submission.id})
else:
return serializer_invalid_response(serializer)
开发者ID:mcmdhr,项目名称:CSOJ,代码行数:28,代码来源:views.py
示例14: _submit_code
def _submit_code(user, problem_id, language, code):
controller = BucketController(user_id=user.id,
redis_conn=redis.Redis(host=settings.REDIS_CACHE["host"],
port=settings.REDIS_CACHE["port"],
db=settings.REDIS_CACHE["db"]),
default_capacity=settings.TOKEN_BUCKET_DEFAULT_CAPACITY)
bucket = TokenBucket(fill_rate=settings.TOKEN_BUCKET_FILL_RATE,
capacity=settings.TOKEN_BUCKET_DEFAULT_CAPACITY,
last_capacity=controller.last_capacity,
last_timestamp=controller.last_timestamp)
if bucket.consume():
controller.last_capacity -= 1
else:
return error_response(u"您提交的频率过快, 请等待%d秒" % int(bucket.expected_time() + 1))
try:
problem = Problem.objects.get(id=problem_id)
except Problem.DoesNotExist:
return error_response(u"题目不存在")
submission = Submission.objects.create(user_id=user.id,
language=language,
code=code,
problem_id=problem.id)
try:
_judge.delay(submission.id, problem.time_limit, problem.memory_limit, problem.test_case_id,
problem.spj, problem.spj_language, problem.spj_code, problem.spj_version)
except Exception as e:
logger.error(e)
return error_response(u"提交判题任务失败")
return success_response({"submission_id": submission.id})
开发者ID:mcmdhr,项目名称:CSOJ,代码行数:31,代码来源:views.py
示例15: post
def post(self, request):
"""
公告发布json api接口
---
request_serializer: CreateAnnouncementSerializer
"""
serializer = CreateAnnouncementSerializer(data=request.data)
if serializer.is_valid():
data = serializer.data
groups = []
# 如果不是全局公告,就去查询一下小组的id 列表中的内容,注意用户身份
if not data["is_global"]:
if request.user.admin_type == SUPER_ADMIN:
groups = Group.objects.filter(id__in=data["groups"])
else:
groups = Group.objects.filter(id__in=data["groups"], admin=request.user)
if not groups.count():
return error_response(u"至少选择一个小组")
else:
if request.user.admin_type != SUPER_ADMIN:
return error_response(u"只有超级管理员可以创建全局公告")
announcement = Announcement.objects.create(title=data["title"],
content=data["content"],
created_by=request.user,
is_global=data["is_global"])
announcement.groups.add(*groups)
return success_response(u"公告发布成功!")
else:
return serializer_invalid_response(serializer)
开发者ID:uestcxl,项目名称:OnlineJudge,代码行数:31,代码来源:views.py
示例16: post
def post(self, request):
problem_id = request.data.get("problem_id", -1)
try:
problem = ContestProblem.objects.get(id=problem_id, is_public=False)
problem.is_public = True
problem.save()
except ContestProblem.DoesNotExist:
return error_response(u"比赛不存在")
if problem.contest.status != CONTEST_ENDED:
return error_response(u"比赛还没有结束,不能公开题目")
Problem.objects.create(
title=problem.title,
description=problem.description,
input_description=problem.input_description,
output_description=problem.output_description,
samples=problem.samples,
test_case_id=problem.test_case_id,
hint=problem.hint,
created_by=problem.created_by,
time_limit=problem.time_limit,
memory_limit=problem.memory_limit,
visible=False,
difficulty=-1,
source=problem.contest.title,
)
problem.is_public = True
problem.save()
return success_response(u"创建成功")
开发者ID:8cbx,项目名称:OnlineJudge,代码行数:28,代码来源:views.py
示例17: put
def put(self, request):
"""
用户编辑json api接口
---
request_serializer: EditUserSerializer
response_serializer: UserSerializer
"""
serializer = EditUserSerializer(data=request.data)
if serializer.is_valid():
data = serializer.data
try:
user = User.objects.get(id=data["id"])
except User.DoesNotExist:
return error_response(u"该用户不存在!")
try:
user = User.objects.get(username=data["username"])
if user.id != data["id"]:
return error_response(u"昵称已经存在")
except User.DoesNotExist:
pass
user.username = data["username"]
user.real_name = data["real_name"]
user.email = data["email"]
user.admin_type = data["admin_type"]
if data["password"]:
user.set_password(data["password"])
user.save()
return success_response(UserSerializer(user).data)
else:
return serializer_invalid_response(serializer)
开发者ID:hujingguang,项目名称:OnlineJudge,代码行数:30,代码来源:views.py
示例18: get
def get(self, request):
"""
查询小组列表或者单个小组的信息,查询单个小组需要传递group_id参数,否则返回全部
---
response_serializer: GroupSerializer
"""
group_id = request.GET.get("group_id", None)
# 根据 id 查询小组信息
if group_id:
try:
group = self.get_group(request, group_id)
return success_response(GroupSerializer(group).data)
except Group.DoesNotExist:
return error_response(u"小组不存在")
else:
groups = self.get_groups(request)
# 搜索小组
if request.GET.get("keyword", None):
groups = groups.filter(name__contains=request.GET["keyword"])
# 只返回我创建的小组 适用于超级管理员
if request.GET.get("my_group", None):
groups = groups.filter(admin=request.user)
# 只返回指定用户的小组 适用于管理员
elif request.GET.get("admin_id", None):
groups = groups.filter(admin__id=request.GET["admin_id"])
return paginate(request, groups, GroupSerializer)
开发者ID:isheng5,项目名称:OnlineJudge,代码行数:26,代码来源:views.py
示例19: get
def get(self, request):
r = redis.Redis(host=redis_config["host"], port=redis_config["port"], db=redis_config["db"])
waiting_number = r.get("judge_queue_length")
if waiting_number is None:
waiting_number = 0
now = datetime.datetime.now()
return success_response({"time": ":".join([str(now.hour), str(now.minute), str(now.second)]),
"count": waiting_number})
开发者ID:localfunction,项目名称:OnlineJudge,代码行数:8,代码来源:views.py
注:本文中的utils.shortcuts.success_response函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论