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


Python Question.user方法代码示例

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


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

示例1: test_get_user

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import user [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

示例2: dummy

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import user [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

示例3: api_poll_create

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import user [as 别名]
def api_poll_create(request):
    api_result = {"api": "poll_create", "status": "success"}
    try:
        token = request.POST["token"]
        user = get_user_from_token(token)
        if not user:
            api_result["status"] = "failure"
            api_result["error"] = "user not found"
        else:
            question = request.POST["question"]
            choice_text = request.POST["choices"]
            group_id = request.POST["group_id"]
            if group_id == "0":
                group = None
            else:
                group = Group.objects.get(pk=group_id)

            choices = set(choice_text.split("##"))
            if "" in choices:
                choices.remove("")

            try:
                topic = Topic.objects.get(name=request.POST["topic"])
            except:
                topic = Topic.objects.get(name="others")

            if len(question) == 0 or len(choices) < 2:
                raise ValueError("invalid poll arguments")

            q = Question()
            q.question_text = question.strip()
            q.user = user
            q.topic_id = topic.id
            q.group = group
            # q.pub_date = datetime.now(pytz.timezone("Asia/Calcutta"))

            q.save()

            for choice in choices:
                c = Choice()
                c.choice_text = choice
                c.question = q
                c.votes = 0
                c.save()
                print c.id

            print q.id
            api_result["question_id"] = q.id

    except Exception as e:
        api_result["status"] = "failure"
        api_result["error"] = e.message

    return JsonResponse(api_result)
开发者ID:krdeepak,项目名称:djmysite,代码行数:56,代码来源:views.py

示例4: create

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import user [as 别名]
def create(request):
    topics = Topic.objects.all()
    context = {}
    context["topics"] = topics
    if request.method == "POST":
        print "inside"
        print request.POST
        try:
            question = request.POST["question"]
            print "question", question
            choices = set(request.POST["choices"].split("##"))
            if "" in choices:
                choices.remove("")
            print "choices", choices
            topic_id = request.POST["topic_id"]
            print "topic_id", topic_id
            if len(question) == 0 or len(choices) < 2:
                raise ValueError("invalid poll arguments")

            q = Question()
            q.question_text = question.strip()
            q.user = request.user
            q.topic_id = topic_id
            # q.pub_date = datetime.now(pytz.timezone("Asia/Calcutta"))

            q.save()

            for choice in choices:
                c = Choice()
                c.choice_text = choice
                c.question = q
                c.votes = 0
                c.save()
                print c.id

            print q.id
            data = {}
            data["question_id"] = q.id
            return JsonResponse(data)

        except Exception as e:
            print e.errno
            print e.strerror

            context["error"] = "Please enter valid question and at least two choices"
            return render(request, "polls/v1_create.html", context)

    else:
        return render(request, "polls/v1_create.html", context)
开发者ID:krdeepak,项目名称:djmysite,代码行数:51,代码来源:views.py

示例5: saveQuestionByForm

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import user [as 别名]
def saveQuestionByForm(request, form):
    question = Question(title=form.cleaned_data['qs_title'],
                        description=form.cleaned_data['content'],)
    
    questionType = Question_Type.objects.get(id=form.cleaned_data['qs_type']);#@UndefinedVariable
    question.type = questionType
    question.user = request.user
    question.save()
    
    tag_list = form.cleaned_data['qs_tags'].split(',');
    for tag_ele in tag_list:
        questionTag = Question_Tag.objects.filter(tag_name=tag_ele) #@UndefinedVariable
        if(questionTag.count() > 0):
            questionTag = questionTag[0]
        else:
            questionTag = Question_Tag(tag_name=tag_ele)
            questionTag.save()
        question.tags.add(questionTag)
开发者ID:zhiaixuexi,项目名称:data_service_aggregation,代码行数:20,代码来源:ctrls.py

示例6: test_get_unanswered_questions

# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import user [as 别名]
def test_get_unanswered_questions():
    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_db = User.one({'username': 'test'})

    assert user_from_db.unanswered_questions().count() == 1
开发者ID:fernandotakai,项目名称:questions,代码行数:21,代码来源:user_tests.py


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