def test_form_save_note_type(self): list_ = List.objects.create() form = EntryForm(for_list=list_, data={ 'text': 'A new note', 'note': [''] }) new_task = form.save() self.assertEqual(new_task.type, Entry.NOTE)
def test_form_save_event_type(self): list_ = List.objects.create() form = EntryForm(for_list=list_, data={ 'text': 'A new event', 'event': [''] }) new_task = form.save() self.assertEqual(new_task.type, Entry.EVENT)
def view_month(request, year, month): if request.user.is_authenticated(): month = MonthLog.get_month(year, month, request.user) else: month = MonthLog.get_month(year, month) form = EntryForm(for_list=month.list) if request.method == "POST": form = EntryForm(for_list=month.list, data=request.POST) if form.is_valid(): form.save() return redirect(month) return render(request, 'month.html', {'month': month, 'form': form})
def view_day(request, year, month, day): if request.user.is_authenticated(): month = MonthLog.get_month(year, month, request.user) else: month = MonthLog.get_month(year, month) day = month.get_day(day) form = EntryForm(for_list=day.list) if request.method == "POST": form = EntryForm(for_list=day.list, data=request.POST) if form.is_valid(): form.save() return redirect(day) return render(request, 'day.html', {'day': day, 'form': form})
def entry_form(request, activity_pk, entry_pk=None): """Function that allows the user to add/edit entries""" curr_student = Student.objects.get(user=request.user) activity = Activity.objects.get(pk=activity_pk) e = None if entry_pk: e = Entry.objects.get(pk=entry_pk) entry_verification(curr_student, e) if request.method == 'POST': form = EntryForm(request.POST, request.FILES, instance=e) if form.is_valid(): f = form.save(commit=False) if type(e) == Entry: # Editing f.save() form.save() action.send(curr_student, verb='edited an entry of', target=activity, seen=False) else: # New f.stu_pk = curr_student.pk f.activity_pk = activity.pk f.save() form.save() activity.entries.add(f) action.send(curr_student, verb='added an entry in', target=activity, seen=False) return HttpResponseRedirect('/entries/' + activity_pk) else: form = EntryForm(instance=e) return render(request, 'journal/entry_form.html', {'form': form, 'activity': activity, 'entry_pk': entry_pk, 'entry': e})
def entry_form(request, activity_pk, entry_pk=None): """Function that allows the user to add/edit entries""" curr_student = Student.objects.get(user=request.user) activity = Activity.objects.get(pk=activity_pk) e = None if entry_pk: e = Entry.objects.get(pk=entry_pk) entry_verification(curr_student, e) if request.method == 'POST': form = EntryForm(request.POST, request.FILES, instance=e) if form.is_valid(): f = form.save(commit=False) if type(e) == Entry: # Editing f.save() form.save() action.send(curr_student, verb='edited an entry of', target=activity, seen=False) else: # New f.stu_pk = curr_student.pk f.activity_pk = activity.pk f.save() form.save() activity.entries.add(f) action.send(curr_student, verb='added an entry in', target=activity, seen=False) return HttpResponseRedirect('/entries/' + activity_pk) else: form = EntryForm(instance=e) return render(request, 'journal/entry_form.html', { 'form': form, 'activity': activity, 'entry_pk': entry_pk, 'entry': e })
def test_form_renders_task_text_input(self): list_ = List.objects.create() form = EntryForm(for_list=list_) self.assertIn('placeholder="Add an Entry!"', form.as_p()) self.assertIn('class="form-control input"', form.as_p())
def test_form_save_default_type(self): list_ = List.objects.create() form = EntryForm(for_list=list_, data={'text': 'A task!'}) new_task = form.save() self.assertEqual(new_task, Entry.objects.first())
def test_form_validation_for_blank_items(self): list_ = List.objects.create() form = EntryForm(for_list=list_, data={'text': ''}) self.assertFalse(form.is_valid()) self.assertEqual(form.errors['text'], [EMPTY_ENTRY_ERROR])