def test_creating_some_choices_for_a_poll(self):
        # start by creating a new Poll object
        poll = Poll()
        poll.question = "What's up?"
        poll.pub_date = timezone.now()
        poll.save()

        # now create a Choice object
        choice = Choice()

        # link it with our Poll
        choice.poll = poll

        # give it some text
        choice.choice = "doin' fine..."

        # and let's say it's had some votes
        choice.votes = 3

        # save it
        choice.save()

        # try retrieving it from the database, using the poll object's reverse
        # lookup
        poll_choices = poll.choice_set.all()
        self.assertEquals(poll_choices.count(), 1)

        # finally, check its attributes have been saved
        choice_from_db = poll_choices[0]
        self.assertEquals(choice_from_db, choice)
        self.assertEquals(choice_from_db.choice, "doin' fine...")
        self.assertEquals(choice_from_db.votes, 3)
Esempio n. 2
0
    def test_create_some_choices_for_a_poll(self):
        # Create new poll object
        poll = Poll()
        poll.question = "What's up?"
        poll.pub_date = timezone.now()
        poll.save()

        # Create Choice object
        choice = Choice()
        choice.poll = poll
        choice.choice = "doin' fine..."

        # Give it faux votes
        choice.votes = 3
        choice.save()

        # Try to retrieve from DB using poll's reverse lookup.
        poll_choices = poll.choice_set.all()
        self.assertEquals(poll_choices.count(), 1)

        # Finally, check attrbs have been saved
        choice_from_db = poll_choices[0]
        self.assertEqual(choice_from_db, choice)
        self.assertEqual(choice_from_db.choice, "doin' fine...")
        self.assertEqual(choice_from_db.votes, 3)
Esempio n. 3
0
    def test_creating_some_choices_for_a_poll(self):
        # start by creating a new Poll object
        poll = Poll()
        poll.question = "What's up?"
        poll.pub_date = timezone.now()
        poll.save()

        # now create a Choice object
        choice = Choice()

        # link it with our Poll
        choice.poll = poll

        # give it some text
        choice.choice = "doin' fine..."

        # and let's say it's had some votes
        choice.votes = 3

        # save it
        choice.save()

        # try retrieving it from the database, using the poll object's reverse
        # lookup
        poll_choices = poll.choice_set.all()
        self.assertEquals(poll_choices.count(), 1)

        # finally, check its attributes have been saved
        choice_from_db = poll_choices[0]
        self.assertEquals(choice_from_db, choice)
        self.assertEquals(choice_from_db.choice, "doin' fine...")
        self.assertEquals(choice_from_db.votes, 3)
Esempio n. 4
0
    def test_creating_some_choices_for_a_poll(self):
        # Start by creating a new Poll object
        poll = Poll()
        poll.question = "What's up?"
        poll.pub_date = timezone.now()
        poll.save()

        # Now we create a Choice object
        choice = Choice()

        # Link it to our poll
        choice.poll = poll
        choice.choice = 'Doing fine...'
        choice.votes = 3
        choice.save()

        # Try retrieving from the database using the poll object's reverse lookup
        poll_choices = poll.choice_set.all()
        self.assertEquals(poll_choices.count(), 1)

        # Finally, check that its attributes have been saved
        choice_from_db = poll_choices[0]
        self.assertEquals(choice_from_db, choice)
        self.assertEquals(choice_from_db.choice, 'Doing fine...')
        self.assertEquals(choice_from_db.votes, 3)
Esempio n. 5
0
def create(request):

    if request.POST:
        form = PollForm(request.POST)
        poll = form.save(commit=False)
        poll.muaccount = request.muaccount
        poll.pub_date = datetime.datetime.now()
        poll.save()
        if request.POST["choice1"]:
            c1 = Choice()
            c1.poll = poll
            c1.choice = request.POST["choice1"]
            c1.votes = 0
            c1.save()
        if request.POST["choice2"]:
            c2 = Choice()
            c2.poll = poll
            c2.choice = request.POST["choice2"]
            c2.votes = 0
            c2.save()
        if request.POST["choice3"]:
            c3 = Choice()
            c3.poll = poll
            c3.choice = request.POST["choice3"]
            c3.votes = 0
            c3.save()
        if request.POST["choice4"]:
            c4 = Choice()
            c4.poll = poll
            c4.choice = request.POST["choice4"]
            c4.votes = 0
            c4.save()

        return HttpResponseRedirect(reverse("polls.views.index"))
    else:
        form = PollForm()
        return render_to_response("polls/create.html", {"form": form}, RequestContext(request, locals()))
Esempio n. 6
0
	def test_creating_some_choices_for_a_poll(self):
		poll = Poll()
		poll.question = "what's up?"
		poll.pub_date = timezone.now()
		poll.save()

		choice = Choice()
		choice.poll = poll
		choice.choice = 'alright then ...'
		choice.votes = 3
		choice.save()

		# check the database
		poll_choices = poll.choice_set.all()
		self.assertEquals(poll_choices.count(), 1)
		self.assertEquals(poll_choices[0].choice, choice.choice)
Esempio n. 7
0
    def test_creating_a_new_poll_and_saving_it_to_the_database(self):
        poll = Poll()
        poll.question = "what's up?"
        poll.pub_date = timezone.now()

        # check we can save ite to the database
        poll.save()

        # now create a Choice object
        choice = Choice()
        
        # link it with our Poll
        choice.poll = poll
        
        # give it some text
        choice.choice = "doin' fine..."
        
        # and let's say it's had some votes
        choice.votes = 3

        # save it
        choice.save()
        
        # try retrieving it from the database, using the poll
        # object's reverse lookup
        poll_choices = poll.choice_set.all()
        self.assertEquals(poll_choices.count(), 1)
        
        # finally, check its attributes have been saved
        choice_from_db = poll_choices[0]
        self.assertEquals(choice_from_db, choice)
        self.assertEquals(choice_from_db.choice, "doin' fine...")
        self.assertEquals(choice_from_db.votes, 3)
        
        
        # now check we can find it in the database again
        all_polls_in_database = Poll.objects.all()
        self.assertEquals(len(all_polls_in_database), 1)
        only_poll_in_database = all_polls_in_database[0]
        self.assertEquals(only_poll_in_database, poll)
        
        # and check that it's saved its two attributes: question and
        # pub_date
        self.assertEquals(only_poll_in_database.question, "what's up?")
        self.assertEquals(only_poll_in_database.pub_date, poll.pub_date)
Esempio n. 8
0
  def save(self):
    if not self.form.is_valid():
      return False
    
    self.reset_pdf_cache()

    data = self.form.cleaned_data
    slide_set = self.event.presentation.slide_set

    if slide_set == None:
      slide_set = SlideSet()
      slide_set.presentation = self.event.presentation
      slide_set.save()
      self.event.presentation.slide_set = slide_set

    slide = self.form.instance
    if data['slide_type'] == 'poll':
      # delete the old slide if it has been changed to a poll
      if slide.id != None:
        slide.delete()

      slide = Poll()
      slide.question = data['poll_question']

    slide.slide_set = slide_set
    slide.offset = data['offset']
    if data['image']:
      base_path = os.path.dirname(slide_upload_to(slide, data['image'].name))
      slide.image = self.upload_file(data['image'], upload_to = base_path)

    self.event.presentation.video = data['video']
    slide.save()
    self.event.presentation.save()

    # we need to save the poll choices here, after the poll is saved and has an id
    if data['slide_type'] == 'poll':
      for choice_text in data['poll_choices'].split('\n'):
        print '!!!! choice: %s' % choice_text
        choice = Choice()
        choice.choice = choice_text
        choice.poll = slide
        choice.save()

    return True
Esempio n. 9
0
    def test_creating_some_choices_for_a_poll(self):
        poll = Poll()
        poll.question = "What's up?"
        poll.pub_date = timezone.now()
        poll.save()

        choice = Choice()
        choice.poll = poll
        choice.choice = "doin' fine.."
        choice.votes = 3
        choice.save()

        poll_choices = poll.choice_set.all()
        self.assertEquals(poll_choices.count(), 1)

        choice_from_db = poll_choices[0]
        self.assertEquals(choice_from_db, choice)
        self.assertEquals(choice_from_db.choice, "doin' fine..")
        self.assertEquals(choice_from_db.votes, 3)
Esempio n. 10
0
  def create( self, request, id=None, action=None ):
    if not id: #id should always be None here
      try:
        pollId = request.POST.get('pollId')
        choiceText = request.POST.get('choice')
        try:
          poll = Poll.objects.get(id=pollId)
          if poll and choiceText:
            choice = Choice()
            choice.poll = poll
            choice.choice = choiceText
            choice.save()

            return choice
        except Poll.DoesNotExist, e:
          resp = rc.BAD_REQUEST
          resp.write("Error fetching 'Poll' object")
          return resp
      except Exception, e:
        resp = rc.BAD_REQUEST
        resp.write("Error creating 'Choice' object")
        return resp
 def test_create_poll_choices(self):
     poll = Poll()
     
     poll.question = self.options.get('question')
     poll.created_at = self.options.get('created_at')
     
     poll.save()
     
     choice = Choice()
     
     choice.poll = poll
     choice.choice = self.options.get('choice')
     choice.votes = self.options.get('votes')
     
     choice.save()
     
     poll_choices = poll.choice_set.all()
     self.assertEquals(poll_choices.count(), 1)
     
     choice_from_db = poll_choices[0]
     self.assertEquals(choice_from_db, choice)
     self.assertEquals(choice_from_db.choice, self.options.get('choice'))
     self.assertEquals(choice_from_db.votes, self.options.get('votes'))
Esempio n. 12
0
def new(request):
    if request.method == 'GET':
        return HttpResponseRedirect(reverse('polls.views.index'))
    elif request.method == 'POST':
        response_data = {}
        try:
            json_data = json.loads(request.body)
            p = Poll()
            p.title = json_data["title"]
            p.put()
            for choice in json_data["choices"]:
                c = Choice(parent=p.key)
                c.poll = p.key
                c.choice = choice["choice"]
                c.votes = 0
                c.put()
            response_data['result'] = 'success'
            response_data['id'] = p.key.integer_id()
            response_data['title'] = json_data["title"]
            return HttpResponse(json.dumps(response_data), content_type="application/json")
        except:
            response_data['result'] = 'failed'
            response_data['message'] = 'You messed up'
            return HttpResponse(json.dumps(response_data), content_type="application/json")