示例#1
0
def seed(request):
    """Seeds the database with sample polls."""
    samples_path = path.join(path.dirname(__file__), 'samples.json')
    with open(samples_path, 'r') as samples_file:
        samples_polls = json.load(samples_file)

    for sample_poll in samples_polls:
        poll = Poll()
        poll.text = sample_poll['text']
        poll.pub_date = timezone.now()
        poll.save()

        for sample_choice in sample_poll['choices']:
            choice = Choice()
            choice.poll = poll
            choice.text = sample_choice
            choice.votes = 0
            choice.save()

    return HttpResponseRedirect(reverse('app:home'))
示例#2
0
def seed(request):
    """Seeds the database with sample polls."""
    samples_path = path.join(path.dirname(__file__), 'samples.json')
    with open(samples_path, 'r') as samples_file:
        samples_polls = json.load(samples_file)

    for sample_poll in samples_polls:
        poll = Poll()
        poll.text = sample_poll['text']
        poll.pub_date = timezone.now()
        poll.save()

        for sample_choice in sample_poll['choices']:
            choice = Choice()
            choice.poll = poll
            choice.text = sample_choice
            choice.votes = 0
            choice.save()

    return HttpResponseRedirect(reverse('app:home'))
示例#3
0
def newpoll(request):
    """new poll page."""
    if request.method == 'POST':
        form = CreatePollForm(request.POST)
        if form.is_valid():
            Poll = form.save()
            choice = Choice()
            choice.poll = Poll
            choice.text = 'I agree with argument 1'
            choice.votes = 0
            choice.save()
            choice = Choice()
            choice.poll = Poll
            choice.text = 'I agree with argument 2'
            choice.votes = 0
            choice.save()
            choice = Choice()
            choice.poll = Poll
            choice.text = 'Neither argument is compelling'
            choice.votes = 0
            choice.save()

            return HttpResponseRedirect(reverse('app:home'))
    else:
        form = CreatePollForm
        assert isinstance(request, HttpRequest)
        return render(
            request, 'app/newpoll.html', {
                'title': 'Submit new case',
                'message': 'Your application description page.',
                'year': datetime.now().year,
                'form': form
            })
示例#4
0
def seed(request):
    """Seeds the database with sample polls."""
    samples_path = path.join(path.dirname(__file__), 'samples.json')
    with open(samples_path, 'r') as samples_file:
        samples_polls = json.load(samples_file)

    for sample_poll in samples_polls:
        poll = Poll()
        poll.Geplanter_Status()
        poll.Status()
        poll.Kurzbeschreibung = sample_poll['Kurzbeschreibung']
        poll.text = sample_poll['text']
        poll.pub_date = true
        poll.save()

        for sample_choice in sample_poll['choices']:
            choice = Choice()
            choice.poll = poll
            choice.text = sample_choice
            choice.Status = 0
            choice.save()

    return HttpResponseRedirect(reverse('app:home'))