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


Python models.Poll类代码示例

本文整理汇总了Python中poll.models.Poll的典型用法代码示例。如果您正苦于以下问题:Python Poll类的具体用法?Python Poll怎么用?Python Poll使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_view_can_handle_votes_via_POST

    def test_view_can_handle_votes_via_POST(self):
        # set up a poll with choices
        poll1 = Poll(question='6 times 7', pub_date=timezone.now())
        poll1.save()
        choice1 = Choice(poll=poll1, choice='42', votes=1)
        choice1.save()
        choice2 = Choice(poll=poll1, choice='The Ultimate Answer', votes=3)
        choice2.save()

        # set up our POST data - keys and values are strings
        post_data = {'vote': str(choice2.id)}

        # make our request to the view
        poll_url = '/poll/polls/%d/' % (poll1.id,)
        response = self.client.post(poll_url, data=post_data)

        # retrieve the updated choice from the database
        choice_in_db = Choice.objects.get(pk=choice2.id)

        # check it's votes have gone up by 1
        self.assertEquals(choice_in_db.votes, 4)
        self.assertEquals(choice_in_db.percentage(), 80)

        # always redirect after a POST - even if, in this case, we go back
        # to the same page.
        self.assertRedirects(response, poll_url)
开发者ID:mebusw,项目名称:lotr-django-rest,代码行数:26,代码来源:test_views.py

示例2: get_mocked_step_with_poll_question

 def get_mocked_step_with_poll_question(self, question, script_slug='registration_script'):
     mocked_poll = Poll()
     mocked_poll.question = question
     poll_step = ScriptStep()
     poll_step.poll = mocked_poll
     poll_step.script = Script(slug=script_slug)
     return poll_step
开发者ID:techoutlooks,项目名称:rapidsms-ureport,代码行数:7,代码来源:registration_steps_test.py

示例3: test_simple_poll_responses

    def test_simple_poll_responses(self):
        p = Poll.create_with_bulk(
                'test poll1',
                Poll.TYPE_TEXT,
                'test?',
                'test!',
                Contact.objects.filter(pk__in=[self.contact1.pk]),
                self.user)
        p.start()
        # starting a poll should send out a message
        self.assertEquals(Message.objects.count(), 1)
        self.assertEquals(Message.objects.all()[0].text, 'test?')

        self.assertInteraction(self.connection1, "test poll response", "test!")
        self.assertEqual(Response.objects.count(), 1)
        self.assertEqual(Response.objects.all()[0].eav.poll_text_value, 'test poll response')

        p2 = Poll.create_with_bulk(
                'test poll2',
                 Poll.TYPE_NUMERIC,
                 'test?',
                 '#test!',
                 Contact.objects.filter(pk__in=[self.contact2.pk]),
                 self.user)
        p2.start()

        self.assertInteraction(self.connection2, '3.1415', '#test!')
        self.assertEqual(Response.objects.count(), 2)
        # There should only be one response for a numeric type poll, 
        # and it should have the value
        # we just sent in
        self.assertEqual(Response.objects.filter(poll__type=Poll.TYPE_NUMERIC)[0].eav.poll_number_value, 3.1415)
开发者ID:catalpainternational,项目名称:HarukaSMS,代码行数:32,代码来源:tests.py

示例4: pollSave

def pollSave(request):
#    if request.method == 'POST':
#        if not request.POST.get('subject', ''):
#            errors.append('Enter a subject.')
#        if not request.POST.get('message', ''):
#            errors.append('Enter a message.')
#        if request.POST.get('email') and '@' not in request.POST['email']:
#            errors.append('Enter a valid e-mail address.')
#        if not errors:
#            send_mail(
#                request.POST['subject'],
#                request.POST['message'],
#                request.POST.get('email', '[email protected]'),
#                ['[email protected]'],
#            )
#            return HttpResponseRedirect('/contact/thanks/')
    title = request.POST.get('title', '')
    remark = request.POST.get('remark', '')
    poll = Poll(title=title, remark=remark, createTime=datetime.now())
    poll.save()

    itemIds = request.POST.get('item_ids', '')
    ids = itemIds.split(',')
    for id in ids:
        pollItem = PollItem(title=request.POST.get('item_title' + id, ''), poll=poll)
        pollItem.save()

    return render_to_response('pollSave.html')
开发者ID:air2013,项目名称:huapuyu,代码行数:28,代码来源:views.py

示例5: test_response_type_handling

    def test_response_type_handling(self):
        #test allow all
        poll1 = Poll.create_with_bulk(
                'test response type handling',
                Poll.TYPE_TEXT,
                'ureport is bored.what would u like it 2 do?',
                'yikes :(',
                Contact.objects.all(),
                self.user)
        poll1.start()
        self.assertInteraction(self.connection1, 'get me a kindle :)', 'yikes :(')
        self.assertInteraction(self.connection1, 'get me a kindle :)', 'yikes :(')
        self.assertInteraction(self.connection1, 'get me an ipad :)', 'yikes :(')
        self.assertInteraction(self.connection1, 'Arrest Bush :)', 'yikes :(')
        self.assertEqual(Response.objects.filter(contact=self.contact1).count(), 4)
        poll1.end()


        #test ignore dups
        poll2 = Poll.create_with_bulk(
                'test response type handling',
                Poll.TYPE_TEXT,
                'ureport is bored.what would u like it 2 do?',
                'yikes :(',
                Contact.objects.all(),
                self.user)
        poll2.response_type=Poll.RESPONSE_TYPE_NO_DUPS
        poll2.save()

        poll2.start()
        self.assertInteraction(self.connection1, 'get me a kindle :)', 'yikes :(')
        self.fake_incoming(self.connection1, 'get me a kindle :)')
        self.assertInteraction(self.connection1, 'get me an ipad :)', 'yikes :(')
        self.assertInteraction(self.connection1, 'Arrest Bush :)', 'yikes :(')
        self.assertEqual(Response.objects.filter(contact=self.contact1,poll=poll2).count(), 3)
        poll2.end()
        #test allow one

        poll3 = Poll.create_with_bulk(
                'test response type handling',
                Poll.TYPE_TEXT,
                'Are u cool?',
                'yikes :(',
                Contact.objects.all(),
                self.user)
        poll3.response_type=Poll.RESPONSE_TYPE_ONE
        poll3.add_yesno_categories()
        poll3.save()
        poll3.start()
        self.fake_incoming(self.connection1, 'what?')
        self.assertEqual(Response.objects.filter(contact=self.contact1,poll=poll3).count(), 1)
        self.assertInteraction(self.connection1, 'yes', 'yikes :(')
        self.assertEqual(Response.objects.filter(contact=self.contact1,poll=poll3).count(), 1)
        self.fake_incoming(self.connection1, 'get me a kindle :)')
        self.fake_incoming(self.connection1, 'get me an ipad :)')
        self.fake_incoming(self.connection1, 'Arrest Bush :)')
        self.assertEqual(Response.objects.filter(contact=self.contact1,poll=poll3).count(), 1)
        self.assertEqual(Response.objects.filter(contact=self.contact1,poll=poll3)[0].message.text, 'yes')
开发者ID:catalpainternational,项目名称:HarukaSMS,代码行数:58,代码来源:tests.py

示例6: if_it_exists_delete_poll_called

def if_it_exists_delete_poll_called(poll_name):
    try:
        poll = Poll.objects.get(name=poll_name)
        Poll.delete(poll)
    except Poll.DoesNotExist:
        pass

    if_exists_delete_group()
    if_exists_delete_user()
开发者ID:riccardost,项目名称:ureport,代码行数:9,代码来源:create_poll_utils.py

示例7: gen_poll

    def gen_poll(self):
        from poll.models import Poll
        poll = Poll()

        candidates = list(self.profile.all())
        for elected in self.elected.all():
            try:
                candidates.remove(elected)
            except ValueError:
                pass

        # Option A: candidates <= available posts -> yes/no/abstention
        if len(candidates) <= self.posts - self.elected.count():
            poll.optiondecision = True
        else:
            poll.optiondecision = False

        # Option B: candidates == 1 -> yes/no/abstention
        #if self.profile.count() == 1:
        #    poll.optiondecision = True
        #else:
        #    poll.optiondecision = False

        poll.assignment = self
        poll.description = self.polldescription
        poll.save()
        for candidate in candidates:
            poll.add_option(candidate)
        return poll
开发者ID:piratenmv,项目名称:openslides,代码行数:29,代码来源:models.py

示例8: test_should_choose_batch_status_based_on_feature_flag

    def test_should_choose_batch_status_based_on_feature_flag(self):
        p = Poll()

        self.assertEqual(p.get_start_poll_batch_status(), "Q")

        settings.FEATURE_PREPARE_SEND_POLL = True

        self.assertEqual(p.get_start_poll_batch_status(), "P")

        settings.FEATURE_PREPARE_SEND_POLL = False

        self.assertEqual(p.get_start_poll_batch_status(), "Q")
开发者ID:ILMServices,项目名称:rapidsms-polls,代码行数:12,代码来源:test_polls.py

示例9: setUp

    def setUp(self):
        self.user,created = User.objects.get_or_create(username='admin')

        self.backend = Backend.objects.create(name='test')
        self.user2=User.objects.create_user('foo', '[email protected]', 'barbar')

        self.contact1 = Contact.objects.create(name='John Jonny')
        self.connection1 = Connection.objects.create(backend=self.backend, identity='8675309', contact=self.contact1)

        self.contact2 = Contact.objects.create(name='gowl')
        self.connection2 = Connection.objects.create(backend=self.backend, identity='5555555', contact=self.contact2)
        self.test_msg=Message.objects.create(text="hello",direction="I",connection=self.connection1)
        self.poll = Poll.create_with_bulk(
            'test poll1',
            Poll.TYPE_TEXT,
            'test?',
            'test!',
            Contact.objects.filter(pk__in=[self.contact1.pk]),
            self.user)
        self.poll.start_date=datetime.datetime.now()
        self.cat1=self.poll.categories.create(name="cat1")
        self.cat2=self.poll.categories.create(name="cat2")
        self.cat3=self.poll.categories.create(name="cat3")
        self.resp = Response.objects.create(poll=self.poll, message=self.test_msg, contact=self.contact1, date=self.test_msg.date)
        self.flag=Flag.objects.create(name="jedi",words="luke,sky,walker,jedi",rule=2)
开发者ID:askpaul,项目名称:rapidsms-ureport,代码行数:25,代码来源:view_tests.py

示例10: test_numeric_polls

 def test_numeric_polls(self):
     p = Poll.create_with_bulk('test poll numeric', Poll.TYPE_NUMERIC,
                               'how old are you?', ':) go yo age!',
                               Contact.objects.all(), self.user)
     p.start()
     self.assertInteraction(self.connection2, '19years', ':) go yo age!')
     self.assertEqual(Response.objects.filter(poll=p).count(), 1)
开发者ID:krelamparo,项目名称:edtrac,代码行数:7,代码来源:tests.py

示例11: perform

    def perform(self, request, results):
        if not len(results):
            return ('No contacts selected', 'error')
        name = self.cleaned_data['poll_name']
        poll_type = self.cleaned_data['poll_type']
        poll_type = self.cleaned_data['poll_type']
        if poll_type == NewPollForm.TYPE_YES_NO:
            poll_type = Poll.TYPE_TEXT

        question = self.cleaned_data.get('question').replace('%',
                u'\u0025')
        default_response = self.cleaned_data['default_response']
        response_type = self.cleaned_data['response_type']
        contacts=Contact.objects.filter(pk__in=results)
        poll = Poll.create_with_bulk(
            name=name,
            type=poll_type,
            question=question,
            default_response=default_response,
            contacts=contacts,
            user=request.user
            )

        poll.response_type = response_type
        if self.cleaned_data['poll_type'] == NewPollForm.TYPE_YES_NO:
            poll.add_yesno_categories()
        poll.save()

        if settings.SITE_ID:
            poll.sites.add(Site.objects.get_current())

        return ('%d participants added to  %s poll' % (len(results),
                poll.name), 'success')
开发者ID:JamesMura,项目名称:rapidsms-ureport,代码行数:33,代码来源:forms.py

示例12: test_poll_translation

    def test_poll_translation(self):
        
        t1=Translation.objects.create(field="How did you hear about Ureport?",
                                   language="ach",
                                   value="I winyo pi U-report ki kwene?")
        t2=Translation.objects.create(field="Ureport gives you a chance to speak out on issues in your community & share opinions with youth around Uganda Best responses & results shared through the media",
                                   language="ach",
                                   value="Ureport mini kare me lok ikum jami matime i kama in ibedo iyee. Lagam mabejo kibiketo ne I karatac me ngec.")
       
        self.contact1.language = "en"
        self.contact1.save()

        self.contact2.language = "ach"
        self.contact2.save()

        t_poll = Poll.create_with_bulk(
            'test translation',
            Poll.TYPE_TEXT,
            "How did you hear about Ureport?"
            ,
            "Ureport gives you a chance to speak out on issues in your community & share opinions with youth around Uganda Best responses & results shared through the media",
            Contact.objects.all(),
            self.user)
        t_poll.add_yesno_categories()
        t_poll.save()
        t_poll.start()

        self.assertEquals(Message.objects.count(), 2)
        self.assertInteraction(self.connection1, 'yes', 'Ureport gives you a chance to speak out on issues in your community & share opinions with youth around Uganda Best responses & results shared through the media')
        self.assertInteraction(self.connection2, 'no', 'Ureport mini kare me lok ikum jami matime i kama in ibedo iyee. Lagam mabejo kibiketo ne I karatac me ngec.')
开发者ID:catalpainternational,项目名称:HarukaSMS,代码行数:30,代码来源:tests.py

示例13: setUp

    def setUp(self):
        self.user, created = User.objects.get_or_create(username='admin')

        self.backend = Backend.objects.create(name='test')
        self.user2 = User.objects.create_user('foo', '[email protected]', 'barbar')
        # self.location = Location.objects.create(name='Kampala')
        self.contact1 = Contact.objects.create(name='John Jonny')
        self.connection1 = Connection.objects.create(backend=self.backend, identity='8675309', contact=self.contact1)
        self.u_contact = UreportContact.objects.create(name='John Jonny', autoreg_join_date=self.connection1.created_on,
                                                       quit_date=datetime.datetime.now(), age=23, responses=2, questions=2,
                                                       incoming=1, is_caregiver=True, connection_pk=self.connection1.pk,
                                                       reporting_location_id=-1, user_id=self.user.pk)

        self.contact2 = Contact.objects.create(name='gowl')
        self.connection2 = Connection.objects.create(backend=self.backend, identity='5555555', contact=self.contact2)
        self.test_msg = Message.objects.create(text="hello", direction="I", connection=self.connection1)
        self.poll = Poll.create_with_bulk(
            'test poll1',
            Poll.TYPE_TEXT,
            'test?',
            'test!',
            Contact.objects.filter(pk__in=[self.contact1.pk]),
            self.user)
        self.poll.start_date = datetime.datetime.now()
        self.cat1 = self.poll.categories.create(name="cat1")
        self.cat2 = self.poll.categories.create(name="cat2")
        self.cat3 = self.poll.categories.create(name="cat3")
        self.resp = Response.objects.create(poll=self.poll, message=self.test_msg, contact=self.contact1,
                                            date=self.test_msg.date)
        self.flag = Flag.objects.create(name="jedi", words="luke,sky,walker,jedi", rule=2)
开发者ID:innovationslabkosovo,项目名称:rapidsms-ureport,代码行数:30,代码来源:view_tests.py

示例14: test_null_responses

    def test_null_responses(self):

        no_response_poll = Poll.create_with_bulk(
            'test response type handling', Poll.TYPE_TEXT,
            'Can we defeat Sauron?', None, Contact.objects.all(), self.user)
        no_response_poll.start()

        self.fake_incoming(self.connection1, 'my precious :)')
        self.assertEqual(
            Message.objects.filter(connection=self.connection1,
                                   direction="O").count(), 1)
开发者ID:krelamparo,项目名称:edtrac,代码行数:11,代码来源:tests.py

示例15: test_response_type_handling

    def test_response_type_handling(self):
        # test allow all
        poll1 = Poll.create_with_bulk(
            "test response type handling",
            Poll.TYPE_TEXT,
            "ureport is bored.what would u like it 2 do?",
            "yikes :(",
            Contact.objects.all(),
            self.user,
        )
        poll1.start()
        self.fake_incoming(self.connection1, "get me a kindle :)")
        self.fake_incoming(self.connection1, "get me a kindle :)")
        self.fake_incoming(self.connection1, "get me a kindle :)")
        self.fake_incoming(self.connection1, "get me a kindle :)")
        self.fake_incoming(self.connection1, "get me a kindle :)")
        self.fake_incoming(self.connection1, "get me a kindle :)")
        self.fake_incoming(self.connection1, "get me a kindle :)")

        self.assertEqual(Response.objects.filter(contact=self.contact1).count(), 7)
        self.assertEqual(Message.objects.filter(connection=self.connection1, direction="O").count(), 2)
        poll1.end()

        # allow one

        poll3 = Poll.create_with_bulk(
            "test response type handling", Poll.TYPE_TEXT, "Are u cool?", "yikes :(", Contact.objects.all(), self.user
        )
        poll3.response_type = Poll.RESPONSE_TYPE_ONE
        poll3.add_yesno_categories()
        poll3.save()
        poll3.start()

        self.assertInteraction(self.connection2, "yes", "yikes :(")

        self.assertEqual(Response.objects.filter(contact=self.contact2, poll=poll3).count(), 1)
        self.fake_incoming(self.connection2, "get me a kindle :)")
        self.fake_incoming(self.connection2, "get me an ipad :)")
        self.fake_incoming(self.connection2, "Arrest Bush :)")
        self.assertEqual(Response.objects.filter(contact=self.contact2, poll=poll3).count(), 1)
        self.assertEqual(Response.objects.filter(contact=self.contact2, poll=poll3)[0].message.text, "yes")
开发者ID:unicefburundi,项目名称:rapidsms-polls,代码行数:41,代码来源:tests.py


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