本文整理汇总了Python中mosu.home.models.get_or_none函数的典型用法代码示例。如果您正苦于以下问题:Python get_or_none函数的具体用法?Python get_or_none怎么用?Python get_or_none使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_or_none函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main_testpaper_post_room
def main_testpaper_post_room(request):
tp = get_or_none(TestPaper,id=int(request.POST.get('tpid',0)))
str_room = request.POST.get('rooms',None)
is_exported = request.POST.get('is_exported',None)
if is_exported :
tp.is_exported = True
tp.save()
if str_room :
arr_room = str_room.split(',')
tp.rooms.clear()
for room in arr_room:
sy = get_or_none(SchoolYear,id=int(room))
if sy : tp.rooms.add(sy)
tp.save()
rooms = SchoolYear.objects.filter(school=tp.school,year=tp.year).order_by('room')
context = {
'user': request.user,
'testpaper':tp,
'rooms':rooms
}
return render(request, 'main_testpaper_room.html', context)
示例2: main_testpaper_post_group
def main_testpaper_post_group(request):
user = request.user
tp = get_or_none(TestPaper,id=int(request.POST.get('tpid',0)))
str_group = request.POST.get('groups',None)
is_exported = request.POST.get('is_exported',None)
if is_exported :
tp.is_exported = True
tp.save()
if str_group :
arr_group = str_group.split(',')
tp.groups.clear()
for group in arr_group:
sy = get_or_none(Group,id=int(group))
if sy : tp.groups.add(sy)
tp.save()
groups = Group.objects.filter(union=tp.union,unionuser__user=user).order_by('id')
context = {
'user': user,
'testpaper':tp,
'groups':groups
}
return render(request, 'main_testpaper_group.html', context)
示例3: main_select_post_maketest
def main_select_post_maketest(request):
test_title = request.POST.get('title')
school = get_or_none(School,id=int(request.POST.get('school',0)))
year = request.POST.get('year')
tpid = request.POST.get('tpid')
str_questions = request.POST.get('questions')
purpose = int(request.POST.get('purpose', 0))
if tpid :
tpid = get_or_none(TestPaper,id=tpid)
tp = TestPaper.objects.create(form=tpid.form, user=request.user, title=test_title, school=school, year=year, purpose=purpose, is_exported=False)
if tp :
for question in reversed(tpid.get_questions()) :
TestPaperQuestion.objects.create(testpaper=tp,question=question)
else :
arr_questions = str_questions.split(',')
arr_questions = reversed(arr_questions)
form = get_or_none(TestPaperForm, id=1)
tp = TestPaper.objects.create(form=form, user=request.user, title=test_title, school=school, year=int(year), purpose=purpose, is_exported=False)
if tp :
for question in arr_questions :
TestPaperQuestion.objects.create(testpaper=tp,question=get_or_none(Question,id=question))
return main_testpaper(request,tp=tp)
示例4: get_question_feedback
def get_question_feedback(request):
user = get_or_none(User,id=request.GET.get('uid',0))
question = get_or_none(Question,id=request.GET.get('qid',0))
feedback = get_or_none(QuestionFeedback,user=user,question=question)
if feedback :
return HttpResponse(json.dumps([{'question':feedback.question.id, 'is_good':feedback.is_good}], default=date_handler), content_type="application/json")
return HttpResponse(json.dumps([{}], default=date_handler), content_type="application/json")
示例5: get_testpaper_question_list
def get_testpaper_question_list(request):
testpaper = get_or_none(TestPaper,id=request.GET.get('tpid',0))
user = get_or_none(User,id=request.GET.get('uid',0))
limit = request.GET.get('limit','')
arr = []
if limit == '':
tpqs = TestPaperQuestion.objects.filter(testpaper_id=testpaper).order_by('-id')
else :
limit = limit.split(':')
if limit : limit = [int(item) for item in limit]
else : limit = [0,0]
tpqs = TestPaperQuestion.objects.filter(testpaper_id=testpaper).order_by('-id')[limit[0]:limit[1]]
if testpaper.get_submit(user) : is_solved = 1
else : is_solved = 0
for tpq in tpqs :
if tpq.question :
arr.append({
"id":tpq.question.id,"type":tpq.question.type,"unit":tpq.question.unit.id,"unit_title":tpq.question.unit.title,
"src":tpq.question.src.url,"explain":tpq.question.explain.url,"keyword":tpq.question.keyword,
"video":tpq.question.video,"answer":tpq.question.answer,"is_active":tpq.question.is_active,
"items":tpq.question.items,"answer_mobile":tpq.question.answer_mobile,"is_solved":is_solved,
"purpose":testpaper.purpose,"date_created":"%s"%set_date(tpq.question.date_created),
})
return HttpResponse(json.dumps(arr), content_type="application/json")
示例6: main_testpaper_post_form
def main_testpaper_post_form(request):
tp = get_or_none(TestPaper,id=int(request.POST.get('tpid',0)))
form = get_or_none(TestPaperForm,id=int(request.POST.get('fid',0)))
tp.form = form
tp.save()
return main_testpaper(request,tp=tp)
示例7: get_invenroty
def get_invenroty(request):
user = get_or_none(User,id=request.GET.get('uid',0))
question = get_or_none(Question,id=request.GET.get('qid',0))
inventory = get_or_none(QuestionInventory, user=user,question=question)
if inventory : return HttpResponse(json.dumps([{'question':inventory.question.id}], default=date_handler), content_type="application/json")
else : return HttpResponse(json.dumps([{}], default=date_handler), content_type="application/json")
示例8: main_groupuser_post_groupuser_cancel
def main_groupuser_post_groupuser_cancel(request):
user = get_or_none(User,id=int(request.POST.get('uid',0)))
union = get_or_none(Union, id=request.POST.get('union_id',0))
unionuser = get_or_none(UnionUser, union=union, user=user)
this_group = get_or_none(Group,id=int(request.GET.get("id",0)))
if unionuser :
gu = get_or_none(GroupUser,unionuser=unionuser,group=this_group)
if gu :
gu.delete()
return main_groupuser(request)
示例9: main_dashboard_post_union_register
def main_dashboard_post_union_register(request):
user = request.user
union_id = int(request.POST.get("union_id",0))
union = get_or_none(Union,id=union_id)
if get_or_none(UnionUser, union=union, user=user) == None:
UnionUser.objects.get_or_create(union=union, user=user, is_active=False)
return HttpResponse("%d"%union.id)
return HttpResponse("0")
示例10: main_groupuser_post_groupuser_move
def main_groupuser_post_groupuser_move(request):
user = get_or_none(User,id=int(request.POST.get('uid',0)))
union = get_or_none(Union, id=request.POST.get('union_id',0))
unionuser = get_or_none(UnionUser, union=union, user=user)
this_group = get_or_none(Group,id=int(request.GET.get("id",0)))
if this_group.unionuser != unionuser :
gu, created = GroupUser.objects.get_or_create(unionuser=unionuser,group=this_group)
if gu :
unionuser.is_active = True
unionuser.save()
return main_groupuser(request)
示例11: get_inventory_list
def get_inventory_list(request):
user = get_or_none(User,id=request.GET.get('uid',0))
units = QuestionInventory.objects.filter(user=user).values('question__unit__unit__unit__unit').annotate(count=Count('question__unit__unit__unit__unit'))
arr = []
for unit in units:
unit2 = get_or_none(QuestionUnit2,id=unit["question__unit__unit__unit__unit"], is_active=True)
if unit2 :
arr.append({"id":unit2.id,"title":unit2.title,'count':unit['count']})
return HttpResponse(json.dumps(arr), content_type="application/json")
示例12: set_qna_answer
def set_qna_answer(request):
user = get_or_none(User,id=int(request.POST.get("user_id",0)))
question = get_or_none(QnAQuestion,id=int(request.POST.get("question_id",0)))
contents = request.POST.get("contents","")
images = request.FILES.getlist("image")
qnaanswer = QnAAnswer.objects.create(user=user, question=question, contents=contents, is_selected=False)
if qnaanswer :
for image in images:
qai = QnAAnswerImage.objects.create(qnaanswer=qnaanswer,src="/")
qai.src.save(image.name, ContentFile(image.read()))
return HttpResponse("OK", status=200)
return HttpResponse("Error", status=400)
示例13: main_testpaper_post_modify
def main_testpaper_post_modify(request):
tp = get_or_none(TestPaper,id=int(request.POST.get('tpid',0)))
str_questions = request.POST.get('questions')
arr_questions = str_questions.split(',')
arr_questions = reversed(arr_questions)
if tp :
tpqs = TestPaperQuestion.objects.filter(testpaper=tp)
for tpq in tpqs :
tpq.delete()
for question in arr_questions :
TestPaperQuestion.objects.create(testpaper=tp,question=get_or_none(Question,id=question))
return main_testpaper(request,tp=tp)
示例14: set_testpaper_submit
def set_testpaper_submit(request):
user = get_or_none(User,id=request.GET.get("uid",0))
testpaper = get_or_none(TestPaper,id=request.GET.get("tpid",0))
answer = request.POST.get("answer","")
jo = json.loads(answer)
for tq in testpaper.get_questions() :
TestPaperSubmit.objects.get_or_create(user=user,testpaper=testpaper,question=tq,answer=jo[str(tq.id)])
ts = list(TestPaperSubmit.objects.filter(user=user,testpaper=testpaper).values())
if ts : return HttpResponse(json.dumps({"state":1}), content_type="application/json")
return HttpResponse(json.dumps({"state":0}), content_type="application/json")
示例15: set_user_profilepic
def set_user_profilepic(request):
pictures = request.FILES.getlist("picture")
uid = int(request.GET.get("uid",0))
user = get_or_none(User,id=uid)
for picture in pictures:
user.profile.src.save("%s.jpg"%picture.name, ContentFile(picture.read()))
return get_user_info(request)