def setUp(self): self.new_poll = Public_Poll.create("New Poll", "Choice1", "Choice2", "Choice3") #An expired poll self.expiration_length = Public_Poll.time_delta_to_expire + datetime.timedelta(days=1) self.expired_poll = Public_Poll.create("Expired Poll", "Choice1", "Choice2", "Choice3", date_created=datetime.datetime.now() - self.expiration_length)
def setUp(self): self.new_poll = Public_Poll.create("New Poll", "Choice1", "Choice2", "Choice3") #An expired poll self.expiration_length = Public_Poll.time_delta_to_expire + datetime.timedelta( days=1) self.expired_poll = Public_Poll.create( "Expired Poll", "Choice1", "Choice2", "Choice3", date_created=datetime.datetime.now() - self.expiration_length)
def test_create(self): question = "A Generic Name" choice1 = "A Choice" choice2 = "A Second Choice" poll = Public_Poll.create(question, choice1, choice2) self.assertEqual(question, poll.question) #Next two methods should throw an exception if the choice doesn't exist. poll.choice_set.get(choice=choice1) poll.choice_set.get(choice=choice2) self.assertEqual(2, poll.choice_set.count())
def handle(self, *args, **options): try: number_to_generate = int(args[0]) except: print("Pass in the the number of polls to generate") return print("Generating %d polls..." % number_to_generate) question_pool = [x.strip() for x in file(QUESTION_POOL_FILE).readlines()] choices_pool = [x.strip() for x in file(CHOICES_POOL_FILE).readlines()] for _ in range(number_to_generate): question = random.choice(question_pool) choices = random.sample(choices_pool, random.randint(2,5)) poll = Public_Poll.create(question, *choices) print(poll) print("Generated %d polls." % number_to_generate)
def create(request): #Test whether we actually got a question if 'question' not in request.POST or not request.POST['question'].strip(): return render_to_response(\ 'index.html', combine_dicts( front_page_polls(), {'error_message':"You did not supply a question"}), context_instance = RequestContext(request)) question = request.POST['question'].strip() choices = [] index = 1 while True: try: choice = request.POST['choice' + str(index)].strip() except KeyError: break if choice[:6] == 'Choice': index += 1 continue if choice: choices.append(choice) index += 1 if not choices or len(choices) < 2: return render_to_response( 'index.html', combine_dicts( front_page_polls(), {'error_message': "You did not supply enough choices"}), context_instance=RequestContext(request)) else: if request.POST['pub_priv'] == 'Private': p = Private_Poll.create(question, *choices) return HttpResponseRedirect( reverse('private_view', args=(p.private_hash, ))) else: p = Public_Poll.create(question, *choices) return HttpResponseRedirect(reverse('poll_view', args=(p.id, )))
def handle(self, *args, **options): try: number_to_generate = int(args[0]) except: print("Pass in the the number of polls to generate") return print("Generating %d polls..." % number_to_generate) question_pool = [ x.strip() for x in file(QUESTION_POOL_FILE).readlines() ] choices_pool = [x.strip() for x in file(CHOICES_POOL_FILE).readlines()] for _ in range(number_to_generate): question = random.choice(question_pool) choices = random.sample(choices_pool, random.randint(2, 5)) poll = Public_Poll.create(question, *choices) print(poll) print("Generated %d polls." % number_to_generate)
def create(request): #Test whether we actually got a question if 'question' not in request.POST or not request.POST['question'].strip(): return render_to_response(\ 'index.html', combine_dicts( front_page_polls(), {'error_message':"You did not supply a question"}), context_instance = RequestContext(request)) question = request.POST['question'].strip() choices = [] index = 1 while True: try: choice = request.POST['choice'+str(index)].strip() except KeyError: break if choice[:6] == 'Choice': index += 1 continue if choice: choices.append(choice) index += 1 if not choices or len(choices) < 2: return render_to_response( 'index.html', combine_dicts( front_page_polls(), {'error_message':"You did not supply enough choices"}), context_instance = RequestContext(request)) else: if request.POST['pub_priv'] == 'Private': p = Private_Poll.create(question, *choices) return HttpResponseRedirect(reverse('private_view',args=(p.private_hash,))) else: p = Public_Poll.create(question, *choices) return HttpResponseRedirect(reverse('poll_view',args=(p.id,)))