コード例 #1
0
ファイル: views.py プロジェクト: bertramr/wgapp
def perform_task(request):
    context = {
        'today': date.today().strftime('%Y-%m-%d'),
        'room_list': Room.objects.all(),
        'flatmate_list': Flatmate.objects.all()
    }
    try:
        flatmate_id = request.POST['flatmate']
    except (KeyError, Flatmate.DoesNotExist):
        return render(request, 'wgapp/task_perform.html', context)

    try:
        task_id = request.POST.getlist('task')

    except (KeyError, Task.DoesNotExist):
        return render(request, 'wgapp/task_perform.html', context)

    else:
        date_input = request.POST['date']
        flatmate = Flatmate.objects.get(pk=flatmate_id)

        for t in task_id:
            task = Task.objects.get(pk=t)

            tj = Journal()
            tj.task = task
            tj.done_by = flatmate
            tj.done_on = datetime.strptime(date_input, '%Y-%m-%d')
            tj.save()
        # Always return an HttpResponseRedirect after successfully dealing
        # with POST data. This prevents data from being posted twice if a
        # user hits the Back button.
        return HttpResponseRedirect(reverse('wgapp:journal_list', ))
コード例 #2
0
ファイル: views.py プロジェクト: bertramr/wgapp
def perform_task(request):
    context = {'today': date.today().strftime('%Y-%m-%d'),
               'room_list': Room.objects.all(),
               'flatmate_list': Flatmate.objects.all()}
    try:
        flatmate_id = request.POST['flatmate']
    except(KeyError, Flatmate.DoesNotExist):
        return render(request, 'wgapp/task_perform.html', context)

    try:
        task_id = request.POST.getlist('task')

    except(KeyError, Task.DoesNotExist):
        return render(request, 'wgapp/task_perform.html', context)

    else:
        date_input = request.POST['date']
        flatmate = Flatmate.objects.get(pk=flatmate_id)

        for t in task_id:
            task = Task.objects.get(pk=t)

            tj = Journal()
            tj.task = task
            tj.done_by = flatmate
            tj.done_on = datetime.strptime(date_input, '%Y-%m-%d')
            tj.save()
        # Always return an HttpResponseRedirect after successfully dealing
        # with POST data. This prevents data from being posted twice if a
        # user hits the Back button.
        return HttpResponseRedirect(reverse('wgapp:journal_list',))