Пример #1
0
 def test_was_published_recently_with_recent_poll(self):
     """
     was_published_recently() should return True for polls whose pub_date
     is within the last day
     """
     recent_poll = Poll(pub_date=timezone.now() - datetime.timedelta(hours=1))
     self.assertEqual(recent_poll.was_published_recently(), True)
Пример #2
0
 def test_was_published_recently_with_old_poll(self):
     """
     was_published_recently() should return False for polls whose pub_date
     is older than 1 day
     """
     old_poll = Poll(pub_date=timezone.now() - datetime.timedelta(days=30))
     self.assertEqual(old_poll.was_published_recently(), False)
Пример #3
0
def add_poll(owner, name, question, single_selection, end_time):
    """
    Add poll object. Matching owner+name is considered same.
    :param owner: User object.
    :param name: Name for poll.
    :param question: Poll question.
    :param single_selection: Can users select one or multiple options.
    :param end_time: Poll close time.
    :return: Poll object, Boolean (true if created).
    """
    created = False
    try:
        p = Poll.objects.get(owner=owner, name=name)
        p.question = question
        p.single_selection = single_selection
        # p.end_time = end_time
    except Poll.DoesNotExist:
        created = True
        p = Poll(
            owner=owner,
            name=name,
            question=question,
            single_selection=single_selection
            # end_time=end_time
        )
    p.save()
    return p, created
Пример #4
0
 def test_was_published_recently_with_future_poll(self):
     """
     was_published_recently() should return False for polls whose
     pub_date is in the future
     """
     future_poll = Poll(pub_date=timezone.now() + datetime.timedelta(days=30))
     self.assertEqual(future_poll.was_published_recently(), False)
Пример #5
0
def poll_save(request):
    if request.method == 'POST':
        title = request.POST.get('title', None)
        comments = request.POST.get('comments', None)
        template = request.POST.get('template', None)
        now = timezone.now()
        poll = Poll(title=title, comments=comments, pub_date=now, template=template)
        poll.save()
    
        for key in request.POST:
            print "key:%s value:%s" %(key, request.POST.get(key))
#         print "request.POST.getlist('product')=%s" %request.POST.getlist('product')
    
        for pk in request.POST.getlist('product'):
            product = Product.objects.get(pk=pk)
            poll.products.add(product)
        
        for pk in request.POST.getlist('contact_group'):
            contact_group = ContactGroup.objects.get(pk=pk)
            poll.contact_group_list.add(contact_group)
    
        poll.save()
    
        message = u'您已经成功保存调查:%s' % title
        request.session['poll'] = poll
        
        return my_send_mail(request)

    return render_to_response('pollapp/poll.html', 
        {'poll': poll,
         'poll_list': Poll.objects.all(),
         'contact_list': Contact.objects.all(),
         'form': ContactForm(),
         'message': message,
        }, 
        context_instance=RequestContext(request))