Example #1
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)
Example #2
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)
Example #3
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)
Example #4
0
def createquestion(request):    
    p=Poll()
    p.question=request.GET['question']
    #p.pub_date=request.getparameter('pub_date')
    p.pub_date=timezone.now()
    p.save()
    return index(request)
    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)
Example #6
0
	def test_creating_a_new_poll_and_saving_it_to_database(self):
		poll = Poll()
		poll.question = self.question
		poll.pub_date = self.pub_date
		poll.save()

		all_polls_in_database = Poll.objects.all()
		self.assertEquals(len(all_polls_in_database), 1)
		only_poll_in_db = all_polls_in_database[0]
		self.assertEquals(only_poll_in_db, poll)

		self.assertEquals(only_poll_in_db.question, self.question)
		self.assertEquals(only_poll_in_db.pub_date, self.pub_date)
    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()

        poll.save()

        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)

        self.assertEquals(only_poll_in_database.question, "What's up?")
        self.assertEquals(only_poll_in_database.pub_date, poll.pub_date)
 def test_create_a_poll_and_save_it_to_the_database(self):
     poll = Poll()
     poll.question = self.options.get('question')
     poll.created_at = self.options.get('created_at')
     
     poll.save()
     
     polls_list = Poll.objects.all()
     self.assertEquals(len(polls_list), 1)
     
     current_poll = polls_list[0]
     self.assertEquals(current_poll, poll)
     
     self.assertEquals(current_poll.question, self.options.get('question'))
Example #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 = '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)
Example #10
0
	def test_creating_a_new_poll_and_saving_it_to_the_database(self):
		# start by creating a new Poll object with its "question" set
		poll = Poll()
		poll.question = "What's up?"
		poll.pub_date = timezone.now()
		# check we can save it to the database
		poll.save()
		# 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)
Example #11
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)
Example #12
0
	def test_creating_a_new_poll_and_saving_it_to_the_database(self):
		# start by creating a new Poll object with its "Question" set
		poll = Poll()
		poll.question = "What's up?"
		poll.pub_date = timezone.now()

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

		# now check we can find it in the database again
		all_polls = Poll.objects.all()
		self.assertEquals(len(all_polls),1)
		only_poll = all_polls[0]
		self.assertEquals(only_poll, poll)

		# check the attributes are set correctly
		self.assertEquals(only_poll.question, "What's up?")
		self.assertEquals(only_poll.pub_date, poll.pub_date)
Example #13
0
    def test_creating_a_new_poll_and_saving_it_to_the_database(self):
        # start by creating a new Poll object with its "question" set
        poll = Poll()
        poll.question = "What's up?"
        poll.pub_date = timezone.now()

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

        # 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)
Example #14
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
Example #15
0
def save_poll(request):
    result = {}
    question = request.POST["question"]

    try:
        poll = Poll()
        poll.question = question
        poll.save()

        result["status"] = "SUCCESS"
        result["msg_status"] = "Su encuesta se ha creado satisfactoriamente"

    except Exception as error:
        result["status"] = "FAILURE"
        result["msg_status"] = "Error en la creacion"

    return render_to_response('home.html',
                              result,
                              context_instance=RequestContext(request))
Example #16
0
    def test_creating_a_new_poll_and_saving_it_to_the_database(self):
        # Create a new poll object wiht its question set

        poll = Poll()
        poll.question = "What's up?"
        poll.pub_date = timezone.now()

        # Check if we can save it to the db
        poll.save()

        # Now check if we can find it in the db again
        all_polls_in_db = Poll.objects.all()
        self.assertEqual(len(all_polls_in_db), 1)
        only_poll_in_db = all_polls_in_db[0]
        self.assertEqual(only_poll_in_db, poll)

        # And check that it has saved its two attrbs, question and pub_date
        self.assertEqual(only_poll_in_db.question, poll.question)
        self.assertEqual(only_poll_in_db.pub_date, poll.pub_date)
Example #17
0
def save_poll(request):
    result = {}
    question = request.POST["question"]

    try:
        poll = Poll()
        poll.question = question
        poll.save()

        result["status"] = "SUCCESS"
        result["msg_status"] = "Su encuesta se ha creado satisfactoriamente"

    except Exception as error:
        result["status"] = "FAILURE"
        result["msg_status"] = "Error en la creacion"



    return render_to_response('home.html',result ,context_instance=RequestContext(request))
Example #18
0
def create_poll(request):
    current_user = get_current_user(request=request)
    if request.method == "POST":
        #Create poll
        new_poll = Poll()
        new_poll.pub_date = datetime.datetime.now()
        new_poll.question = request.POST["question"]
        new_poll.master = current_user
        new_poll.save()
        #Create answers
        answers = [request.POST["answer1"], request.POST["answer2"], request.POST["answer3"], request.POST["answer4"], request.POST["answer5"], request.POST["answer6"]]
        for answer in answers:
            if answer != "":
                new_choice = Choice()
                new_choice.poll = new_poll
                new_choice.choice_text = answer
                new_choice.save()

    return render(request, "add_poll.html", {"current_user": current_user})
Example #19
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)
Example #20
0
 def create( self, request, id=None ): #called for a POST request
   #When making a POST request, data has to be sent with the request, same goes with PUT
   #eg - In jQuery ajax {"a":null} works but {} doesn't
   #print "GOT CREATE (POST) request on /api/poll/"
   if not id: #id should always be None here
     try:
       question = request.POST.get('question')
       pub_date = utils.dateFromString(request.POST.get('pubDate'))
       if question and pub_date:
         poll = Poll()
         poll.question = question
         poll.pub_date = pub_date
         poll.polling_ended = False
         poll.save()
         
         return poll
     except Exception, e:
       resp = rc.BAD_REQUEST
       resp.write("Error creating 'Poll' object")
       return resp
Example #21
0
def save_poll_3(request):
    result = {}
    question = request.POST["question"]
    pub_date = request.POST["pub_date"]
    try:
        poll = Poll()
        poll.question = question
        poll.pub_date = pub_date
        poll.save()

        result["status"] = "SUCCESS"
        result["msg_status"] = "Su encuesta se ha creado satisfactoriamente"
        result['name'] = "Leandro"
        result['lastname'] = "Agudelo"

    except Exception as error:
        result["status"] = "FAILURE"
        result["msg_status"] = "Error en la creacion"



    return render_to_response('home3.html',result ,context_instance=RequestContext(request))
Example #22
0
def save_poll_3(request):
    result = {}
    question = request.POST["question"]
    pub_date = request.POST["pub_date"]
    try:
        poll = Poll()
        poll.question = question
        poll.pub_date = pub_date
        poll.save()

        result["status"] = "SUCCESS"
        result["msg_status"] = "Su encuesta se ha creado satisfactoriamente"
        result['name'] = "Leandro"
        result['lastname'] = "Agudelo"

    except Exception as error:
        result["status"] = "FAILURE"
        result["msg_status"] = "Error en la creacion"

    return render_to_response('home3.html',
                              result,
                              context_instance=RequestContext(request))
Example #23
0
def submit_poll(request):
    question = request.POST['question']
    number = int(request.POST['num_choices'])
    end_date = request.POST['end_date']
    errors = []
    if not question or not number:
        if not question:
            errors.append("You didn't put a question")
        if not number:
            errors.append("You didn't specify a number of options")
        if not end_date:
            errors.append("You didn't specify an end date for the poll")
        return render(request, 'polls/poll_creation.html', {
            'error_message': errors
            })
    else:
        poll = Poll()
        poll.question=question
        poll.pub_date=timezone.now()
        poll.start_date=timezone.now()
        poll.end_date=end_date
        poll.save()
        return HttpResponseRedirect(reverse('polls:option_creation', args=(number, poll.id)))
Example #24
0
def submit_poll(request):
    question = request.POST['question']
    number = int(request.POST['num_choices'])
    end_date = request.POST['end_date']
    errors = []
    if not question or not number:
        if not question:
            errors.append("You didn't put a question")
        if not number:
            errors.append("You didn't specify a number of options")
        if not end_date:
            errors.append("You didn't specify an end date for the poll")
        return render(request, 'polls/poll_creation.html',
                      {'error_message': errors})
    else:
        poll = Poll()
        poll.question = question
        poll.pub_date = timezone.now()
        poll.start_date = timezone.now()
        poll.end_date = end_date
        poll.save()
        return HttpResponseRedirect(
            reverse('polls:option_creation', args=(number, poll.id)))
 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'))
 def test_poll_objects_are_named_after_their_question(self):
     p = Poll()
     p.question = 'How is babby formed?'
     self.assertEquals(unicode(p), 'How is babby formed?')
Example #27
0
 def test_poll_objects_are_named_after_their_question(self):
     p = Poll()
     p.question = 'This question is a test?'
     self.assertEquals(unicode(p), 'This question is a test?')
Example #28
0
 def test_poll_objects_are_named_after_their_question(self):
     p = Poll()
     p.question = 'How is babby formed?'
     self.assertEquals(unicode(p), 'How is babby formed?')
 def test_poll_objects_are_named_according_to_its_name(self):
     poll = Poll()
     poll.question = self.options.get('question')
     
     self.assertEquals(unicode(poll), self.options.get('question'))
Example #30
0
# No polls are in the system yet.
Poll.objects.all()

# Create a new Poll
# Support for time zones is enabled in the default settings file, so
# Django expects a timedate with tzinfo for pub_date. Use timezone.now()
# instead of datetime.datetime.now() and it will do the right thing.
from django.utils import timezone
p = Poll(question="What's new?", pub_date=timezone.now())

# Save the object into the database. You have to call save() explicitly.
p.save()

# Now it has an ID. Note that this might say "1L" instead of "1", depending 
# on which database you're using. That's no biggie; it just means your
# database backend prefers to return integers as Python long integer
# objects.
p.id

# Access database columns via Python attributes
p.question
p.pub_date

# Change values by changing the attributes, then calling save().
p.question = "What's up?"
p.save()

# objects.all() displays all the polls in the database
Poll.objects.all()

Example #31
0

# Save the object into the database. You have to call save() explicitly.
>>> p.save()

# CHECK THE ID WITH P.ID
>>> p.id #returns "1"

# Access database columns via Python attributes.
>>> p.question
"What's new?"
>>> p.pub_date
datetime.datetime(2012, 2, 26, 13, 0, 0, 775217, tzinfo=<UTC>)

# Change values by changing the attributes, then calling save().
>>> p.question = "What's up?"
>>> p.save()

# objects.all() displays all the polls in the database.
>>> Poll.objects.all() #returns: [<Poll: Poll object>]

""" <Poll: Poll object> is, utterly, an unhelpful representation of this object. 
Let’s fix that by editing the polls model (in the polls/models.py file) 
and adding a __unicode__() method to both Poll and Choice. :"""

from django.db import models

class Poll(models.Model):
    # ...
    def __unicode__(self):  #ADD THIS
        return self.question
Example #32
0
	def test_poll_objects_are_named_after_their_question(self):
		# the model shows the unicode value in the admin panel
		p = Poll()
		question_text = 'How are you doing?'
		p.question = question_text
		self.assertEquals(unicode(p), question_text)
Example #33
0
 def test_poll_objects_are_named_after_their_question(self):
     p = Poll()
     p.question = "How does theees work?"
     self.assertEqual(unicode(p), "How does theees work?")