Exemple #1
0
def askquestion(request):
    """提问模板"""
    name =request.session.get('name')
    if request.method == "POST" and request.is_ajax():

        form = QuestionForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            title = data['title']
            text = data['text']
            qtype = data['q_type'].lower()
            user = User.objects.get(name=name.split()[0])
            try:
                questiontype = QuestionType.objects.get(name=qtype)
            except QuestionType.DoesNotExist:
                questiontype = QuestionType(name=qtype)
                questiontype.save()

            question = Question(user=user, title=title, text=text, q_type=questiontype)
            question.save()


            # return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
            return JsonResponse({'status':'ok'})
        else:
            # return HttpResponse(request.POST.get('title'))
            return render(request, 'askquestion.html')
    if name:
        return render(request,'askquestion.html',{'QuestionForm':QuestionForm, 'name':name.split()})
    else:
        return HttpResponseRedirect("/")
Exemple #2
0
def askquestion(request):
    """提问模板"""
    name = request.session.get('name')
    if request.method == "POST":
        form = QuestionForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            title = data['title']
            text = data['text']
            qtype = data['q_type']
            user = User.objects.get(name=name.split()[0])
            questiontype = QuestionType(name=qtype)
            questiontype.save()
            question = Question(user=user, title=title, text=text, q_type=questiontype)
            question.save()
            # return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
            return JsonResponse({'status':'ok'})
        else:
            # return HttpResponse(request.POST.get('title'))
            return render(request, 'askquestion.html')
    if name:
        access_key = "wmN715-Lo5SC1jYIkuqObCLl1bhZoURTxewUGyq2"
        secret_key = "IXXeA4-Rzu9RB6nkf687UjQt9YCOp1JpWptm0C0y"
        bucket_name = "iforj"
        q = qiniu.Auth(access_key, secret_key)
        token = q.upload_token(bucket_name)
        return render(request, 'askquestion.html', {'QuestionForm': QuestionForm, 'uptoken': token, 'name':name.split()})
    else:
        return HttpResponseRedirect("/")
Exemple #3
0
def questionTypeAdd():
    tmp={}
    if request.method == 'POST':
        ttype=request.values.get("type")
        identity=request.values.get('identity')
        if not ttype:
            tmp['status']='001'
        elif identity!='1':
            # 无权限
            tmp['status']='002'
        elif identity=='1':
            questionType = QuestionType(type=ttype)
            db.session.add(questionType)
            try:
                db.session.commit()
                tmp['status']='100'
            except:
                db.session.rollback()
                tmp['status']='003'
            db.session.close()
    else:
        tmp['status']='004'
    return json.dumps(tmp,ensure_ascii=False)
Exemple #4
-1
def askquestion(request):
    """提问模板"""
    name = request.session.get("name")
    if request.method == "POST":
        form = QuestionForm(request.POST)
        if form.is_valid():
            data = form.cleaned_data
            title = data["title"]
            text = data["text"]
            qtype = data["q_type"]
            user = User.objects.get(name=name.split()[0])
            questiontype = QuestionType(name=qtype)
            questiontype.save()
            question = Question(user=user, title=title, text=text, q_type=questiontype)
            question.save()
            # return HttpResponseRedirect(request.META.get('HTTP_REFERER', '/'))
            return JsonResponse({"status": "ok"})
        else:
            # return HttpResponse(request.POST.get('title'))
            return render(request, "askquestion.html")
    if name:
        access_key = "wmN715-Lo5SC1jYIkuqObCLl1bhZoURTxewUGyq2"
        secret_key = "IXXeA4-Rzu9RB6nkf687UjQt9YCOp1JpWptm0C0y"
        bucket_name = "iforj"
        q = qiniu.Auth(access_key, secret_key)
        token = q.upload_token(bucket_name)
        return render(
            request, "askquestion.html", {"QuestionForm": QuestionForm, "uptoken": token, "name": name.split()}
        )
    else:
        return HttpResponseRedirect("/")