当前位置: 首页>>代码示例>>Python>>正文


Python Question.save方法代码示例

本文整理汇总了Python中models.Question.save方法的典型用法代码示例。如果您正苦于以下问题:Python Question.save方法的具体用法?Python Question.save怎么用?Python Question.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Question的用法示例。


在下文中一共展示了Question.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import save [as 别名]
	def save(self, commit=True):
#		question = super(AskForm, self).save(commit=False)
		question = Question(title=self.cleaned_data['title'],
				    text=self.cleaned_data['text'],
				    author=self._user)
		question.save()
		return question
开发者ID:alysenko,项目名称:education-web-tech,代码行数:9,代码来源:forms.py

示例2: save_scratch

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import save [as 别名]
def save_scratch(kind='', subject='', theme='', text='', answers=[]):
	'''
	save question from scratch to database
	'''
	q = Question(kind=kind, subject=subject, theme=theme, text=text, answers=answers)
	q.save()
	return True
开发者ID:Samael500,项目名称:owl,代码行数:9,代码来源:question_helper.py

示例3: upload_new_question

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import save [as 别名]
def upload_new_question(question_source, question, tags):
    new_question = Question(question = question, question_source=question_source)
    new_question.save()
    tags_final = []

    for tag in tags:
        try:
            search_tag = Tag.objects.get(tag=tag)
            tags_final.append(search_tag)
            continue
        except Tag.DoesNotExist:
            new_tag = Tag(tag=tag)
            new_tag.save()
            tags_final.append(new_tag)
            continue
        continue
    
    for tag in tags_final:
        print tag.tag

    for tag in tags_final:
        tag.questions.append(new_question)
        tag.save()
        continue

    return new_question.id
开发者ID:YNCHacks,项目名称:Qanda,代码行数:28,代码来源:views.py

示例4: askquestion

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import save [as 别名]
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("/")
开发者ID:NaomiGeng,项目名称:iforj,代码行数:33,代码来源:views.py

示例5: create_test_backup

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import save [as 别名]
def create_test_backup(request):
    test_obj = json.loads(request.body)
    test = Test()
    #import pdb; pdb.set_trace()
    if request.user.is_authenticated():
        owner = User_Profile.objects.filter(user = request.user)
        test.owner = owner[0]
        test.test_name = test_obj['PRE_TEST']['test_name']
        #test.subject = test_obj['PRE_TEST'].subject
        #test.target_exam = test_obj['PRE_TEST'].target_exam
        #test.topics = test_obj['PRE_TEST'].topics_included
        test.total_time = test_obj['PRE_TEST']['total_time']
        test.pass_criteria = test_obj['PRE_TEST']['pass_criteria']
        test.assoicated_class = Class.objects.get(pk=test_obj['CLASS_INFO'])
        test.save()
        try:
            for item in test_obj['QUESTIONS']:
                question = Question()
                question.question_text = item['question_text']
                question.explanation = item['explanation']
                question.options = json.dumps(item['options'])
                question.hint = item['hint']
                question.difficulty = item['difficulty_level']
                question.points = item['points']
                question.owner = owner[0]
                #question.target_exam = test.target_exam
                #question.subject = test.subject
                #question.topic = item.topic
                question.save()
                test.questions.add(question)
            data = {"status" : "success"}
            return JsonResponse(data)
        except Exception, e:
            raise e
开发者ID:adideshp,项目名称:Tutor,代码行数:36,代码来源:views.py

示例6: askquestion

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import save [as 别名]
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("/")
开发者ID:chengkeai,项目名称:iforj,代码行数:33,代码来源:views.py

示例7: create_question

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import save [as 别名]
def create_question(request):
    if request.method != 'POST':
        return HttpResponseNotAllowed(['POST']) 
    
    recording_url = request.POST['RecordingUrl']
    recording_url.replace('2010-04-01', '2008-08-01')
    to_number = request.POST['To']
    from_number = request.POST['From']
    
    number = PhoneNumber.objects.get(number=to_number)
    language = number.language
    
    log.debug(recording_url)
    
    q = Question(to_number=to_number,
                 from_number=from_number,
                 language=language, 
                 recording_url=recording_url)
    q.save()

    log.debug('Question Created: %s' % q)

    r = twiml.Response()
    r.hangup()
    
    return HttpResponse(r)
开发者ID:robboyle,项目名称:asesor,代码行数:28,代码来源:views.py

示例8: ask_display

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import save [as 别名]
def ask_display(request):
        if not request.user.is_authenticated():
            raise PermissionDenied

        if request.method == 'POST':

            request_title = request.POST.get('title')
            request_text = request.POST.get('text')
            request_tags = request.POST.get('tags')
            
            if request_title == '' or request_text == '':
                return render(request, 'ask.html', {'page_title': 'New Question', 'errors': '1'})
            
            new_question = Question(title = request_title, 
                date = datetime.datetime.now(), 
                author = UserProfile.objects.get(user_account = request.user),
                text = request_text)
            
            new_question.save()
            
            for tag_str in request_tags.split(','):
                if Tag.objects.filter(name = tag_str).exists():
                    tag = Tag.objects.get(name = tag_str)
                    new_question.tags.add(tag)
                else:
                    new_tag = Tag(name = tag_str)
                    new_tag.save()
                    new_question.tags.add(new_tag)
            
            return HttpResponseRedirect('/question/{}'.format(new_question.id))
            
        return render(request, 'ask.html', {'page_title': 'New Question', 'errors': '0'})
开发者ID:TimeEscaper,项目名称:Ask_AI_TP-mail.ru,代码行数:34,代码来源:views.py

示例9: dummy

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import save [as 别名]
def dummy(count):
    words = [
        'why','do','federer','nadal','elena','deepak','rudra','go','live','love','startup','india',
        'near', 'far', 'about','give', 'take', 'bird', 'lion', 'window','door', 'try', 'yoda', 'prestige',
        'star', 'sun', 'father', 'mother'
    ]

    ans = [
        'maybe', 'yes', 'no', 'never', 'do', 'lie', 'cheat', 'steal',
        'run', 'whatever', 'see', 'eat', 'why', 'not'
    ]

    topics = Topic.objects.all()

    for i in xrange(count):
        q = Question()
        q.question_text = ' '.join(random.sample(words, random.randint(8,15)))
        q.topic = topics[random.randint(0,len(topics)-1)]
        q.user = random.sample(User.objects.all(), 1)[0]
        q.save()

        choice_count = random.randint(2,6)
        for j in xrange(choice_count):
            ch = Choice()
            ch.choice_text = ' '.join(random.sample(ans, random.randint(2,4)))
            ch.question = q
            ch.save()
开发者ID:krdeepak,项目名称:djmysite,代码行数:29,代码来源:util.py

示例10: ask

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import save [as 别名]
def ask(request):
    if request.method == 'POST':
        form = QuestionForm(request.POST)
        if form.is_valid():
            q = Question(
                created_by=request.user,
                author=request.user,
                category=form.cleaned_data['category'],
                title=form.cleaned_data['title'],
                text=form.cleaned_data['text'],
            )
            q.save()

            return redirect(reverse('support:question', args=(q.id,)))
    else:
        form = QuestionForm()

    c = {
        'form': form,
        'search_form': SearchForm(),

        'categories': p.CATEGORIES,

        'title': _("Ask a question"),
        'site_title': g.SITE_TITLE,
    }

    return render(request, 'support/ask.html', c)
开发者ID:rokj,项目名称:sellout,代码行数:30,代码来源:views.py

示例11: test_get_user

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import save [as 别名]
def test_get_user():
    user = User()
    user.username = u"test"
    user.set_password("test123")

    assert user.save()
    assert user._id

    q = Question()
    q.question = u"test"
    q.author = u"anon"
    q.user = user.username

    assert q.save(validate=True)
    assert q._id

    user_from_question = q.get_user()

    assert user_from_question._id == user._id

    q.user = u"anon!"

    q.save()

    assert not q.get_user()
开发者ID:fernandotakai,项目名称:questions,代码行数:27,代码来源:question_tests.py

示例12: get_question

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import save [as 别名]
def get_question():
    questions = Question.all()
    if questions.count() == 0:
        new_question = Question(text="Dummy text")
        new_question.save()
    else:
        new_question = questions[0]
    return new_question
开发者ID:soswow,项目名称:yet-another-one-poll-on-app-engine,代码行数:10,代码来源:views.py

示例13: save

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import save [as 别名]
    def save(self):
	if self._user.is_anonymous():
    	    self.cleaned_data['author_id'] = 1
	else:     
    	    self.cleaned_data['author'] = self._user
	question = Question(**self.cleaned_data)
	question.save()
	return question
开发者ID:igorlutsenko,项目名称:stepic_web_project_6,代码行数:10,代码来源:forms.py

示例14: save

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import save [as 别名]
 def save(self):
     question = Question(**self.cleaned_data)
     if question.author_id:
         question.author_id += 1
     else:
         question.author_id = 1
     question.save()
     return question
开发者ID:padznich,项目名称:web,代码行数:10,代码来源:forms.py

示例15: question_add

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import save [as 别名]
def question_add(request):
    survey_add=Survey.objects.get(id=int(request.session['current_survey']))
    new_question=Question()
    new_question.question_text=request.POST['question_text']
    survey_add.question_set.add(new_question)
    new_question.save()
    survey_add.save()
    request.session['current_question']=new_question.id
    return redirect('admin-choice-add-view')
开发者ID:ryanyue123,项目名称:Django,代码行数:11,代码来源:views.py


注:本文中的models.Question.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。