本文整理汇总了Python中mosu.home.models.get_or_none函数的典型用法代码示例。如果您正苦于以下问题:Python get_or_none函数的具体用法?Python get_or_none怎么用?Python get_or_none使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_or_none函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:pck886,项目名称:7oclock_for_teacher,代码行数:25,代码来源:views.py
示例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)
开发者ID:7oclock,项目名称:7oclock_for_teacher,代码行数:26,代码来源:views.py
示例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)
开发者ID:pck886,项目名称:7oclock_for_teacher,代码行数:27,代码来源:views.py
示例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")
开发者ID:7oclock,项目名称:7oclock_for_teacher,代码行数:7,代码来源:views.py
示例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")
开发者ID:7oclock,项目名称:7oclock_for_teacher,代码行数:29,代码来源:views.py
示例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)
开发者ID:pck886,项目名称:7oclock_for_teacher,代码行数:8,代码来源:views.py
示例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")
开发者ID:7oclock,项目名称:7oclock_for_teacher,代码行数:8,代码来源:views.py
示例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)
开发者ID:7oclock,项目名称:7oclock_for_teacher,代码行数:10,代码来源:views.py
示例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")
开发者ID:7oclock,项目名称:7oclock_for_teacher,代码行数:10,代码来源:views.py
示例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)
开发者ID:7oclock,项目名称:7oclock_for_teacher,代码行数:11,代码来源:views.py
示例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")
开发者ID:7oclock,项目名称:7oclock_for_teacher,代码行数:12,代码来源:views.py
示例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)
开发者ID:7oclock,项目名称:7oclock_for_teacher,代码行数:13,代码来源:views.py
示例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)
开发者ID:pck886,项目名称:7oclock_for_teacher,代码行数:14,代码来源:views.py
示例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")
开发者ID:7oclock,项目名称:7oclock_for_teacher,代码行数:14,代码来源:views.py
示例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)
开发者ID:7oclock,项目名称:7oclock_for_teacher,代码行数:7,代码来源:views.py
示例16: main_payment
def main_payment(request):
union_id = int(request.POST.get("union_id", 0))
union = get_or_none(Union, id=union_id)
return HttpResponse('True')
开发者ID:7oclock,项目名称:7oclock_for_teacher,代码行数:7,代码来源:views.py
示例17: main_dashboard
def main_dashboard(request):
union = get_or_none(Union, id=request.POST.get('union_id',0))
context = {
'user': request.user,
'union':union,
}
return render(request, 'main_dashboard.html', context)
开发者ID:7oclock,项目名称:7oclock_for_teacher,代码行数:7,代码来源:views.py
示例18: get_qna_answers
def get_qna_answers(request):
qnaquestion = get_or_none(QnAQuestion,id=int(request.GET.get("qid",0)))
limit = request.GET.get("limit",None)
if limit : limit = limit.split(":")
answers = QnAAnswer.objects.filter(question=qnaquestion).order_by('is_selected','-id')
if limit : questions = answers[limit[0]:limit[1]]
arr = []
for answer in answers :
arr.append({
'id':answer.id
,'user_src':answer.user.profile.get_src()
,'username':answer.user.first_name
,'user_id':answer.user.id
,'src':answer.get_srcs()
,'contents':answer.contents
,'is_selected':int(answer.is_selected)
,'date_created':unixtime(answer.date_created)
})
return HttpResponse(json.dumps(arr, default=date_handler), content_type="application/json")
开发者ID:7oclock,项目名称:7oclock_for_teacher,代码行数:25,代码来源:views.py
示例19: get_user_info
def get_user_info(request):
uid = int(request.GET.get("uid",0))
user = get_or_none(User,id=uid)
if user.id :
school_id, school_name, school_year, school_room = 0, '', '', ''
if user.profile.school :
school_id = user.profile.school.id
school_name = user.profile.school.title
if user.profile.schoolyear :
school_id = user.profile.schoolyear.school.id
school_name = user.profile.schoolyear.school.title
school_year = user.profile.schoolyear.year
school_room = user.profile.schoolyear.room
arr = [{
'id':user.id,
'username':user.username,
'email':user.email,
'first_name':user.first_name,
'school_id':school_id,
'school_name':school_name,
'school_year':school_year,
'school_room':school_room,
'src':user.profile.src.url,
'phone':user.profile.phone,
'gender':user.profile.get_gender()
}]
return HttpResponse(json.dumps(arr, default=date_handler), content_type="application/json")
else:
return HttpResponse(json.dumps([{}], default=date_handler), content_type="application/json")
return HttpResponse(json.dumps([{}], default=date_handler), content_type="application/json")
开发者ID:pck886,项目名称:7oclock_for_teacher,代码行数:30,代码来源:views.py
示例20: main_testpaper_modify
def main_testpaper_modify(request):
arr = []
q = request.GET.get('q','')
tp = get_or_none(TestPaper,id=request.GET.get('tpid'))
u1 = get_or_none(QuestionUnit1,id=request.GET.get('unit1',0))
u2 = get_or_none(QuestionUnit2,id=request.GET.get('unit2',0))
u3 = get_or_none(QuestionUnit3,id=request.GET.get('unit3',0))
u4 = get_or_none(QuestionUnit4,id=request.GET.get('unit4',0))
unit1, unit2, unit3, unit4 = None, None, None, None
unit1 = QuestionUnit1.objects.filter(is_active=True)
query = None
if u1 :
unit2 = QuestionUnit2.objects.filter(unit=u1,is_active=True)
query = None
if u2 :
unit3 = QuestionUnit3.objects.filter(unit=u2,is_active=True)
query = Q(unit__unit__unit__unit=u2)
if u3 :
unit4 = QuestionUnit4.objects.filter(unit=u3,is_active=True)
query = query&Q(unit__unit__unit=u3)
if u4 :
query = query&Q(unit__unit=u4)
questions = []
if query :
questions = Question.objects.filter(query).values('unit').annotate(count=Count('unit'))
for question in questions:
tmp = Question.objects.filter(unit=question['unit'])
if tmp :
type_0 = tmp.filter(unit=tmp[0].unit, type=0)
type_1 = tmp.filter(unit=tmp[0].unit, type=1)
arr.append({'count':question['count'],'unit':tmp[0].unit,'element':tmp[0],'type_0':type_0,'type_1':type_1})
context = {
'user': request.user,
'query':q,
'unit1':unit1,'unit2':unit2,'unit3':unit3,'unit4':unit4,
'u1':u1,'u2':u2,'u3':u3,'u4':u4,
'questions':arr,
'testpaper':tp
}
return render(request, 'main_testpaper_modify.html', context)
开发者ID:pck886,项目名称:7oclock_for_teacher,代码行数:47,代码来源:views.py
注:本文中的mosu.home.models.get_or_none函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论