Example #1
0
    def test_date_form_uniqueness(self):
        """
        Tests that when creating/posting a duplicate date using
        the date form, it returns the form error Date already exists
        """
        form_data = {'date': self.dt2}
        form = DateForm(data=form_data)

        self.assertEqual(form.is_valid(), False)
        self.assertEqual(form.errors,
                         {'date': [u'Date with this Date already exists.']})
Example #2
0
def add_date(request):
    if request.method == 'POST':
        date_form = DateForm(request.POST)

        # check if form is valid
        if date_form.is_valid():
            date_form.save()

            return redirect('add_workout')
        else:
            return render(request, 'gym_app/add_date.html',
                          {'date_form': date_form})
    # request.method == 'GET'
    else:
        date_form = DateForm()

    return render(request, 'gym_app/add_date.html',
                  {'date_form': date_form})