Beispiel #1
0
Datei: views.py Projekt: npch/amy
def event_edit(request, event_ident):
    try:
        event = Event.get_by_ident(event_ident)
        tasks = event.task_set.order_by('role__name')
    except ObjectDoesNotExist:
        raise Http404("No event found matching the query.")

    if request.method == 'GET':
        event_form = EventForm(prefix='event', instance=event)
        task_form = TaskForm(prefix='task', initial={'event': event})

    elif request.method == 'POST':
        event_form = EventForm(request.POST, prefix='event', instance=event)
        task_form = TaskForm(request.POST, prefix='task',
                             initial={'event': event})

        if "submit" in request.POST and event_form.is_valid():
            event_form.save()
            return redirect(event)

        if "add" in request.POST and task_form.is_valid():
            task_form.save()

    context = {'title': 'Edit Event {0}'.format(event.get_ident()),
               'event_form': event_form,
               'object': event,
               'model': Event,
               'tasks': tasks,
               'task_form': task_form,
               'form_helper': bootstrap_helper_without_form}
    return render(request, 'workshops/event_edit_form.html', context)
Beispiel #2
0
 def test_creating_event_with_no_comment(self):
     """Ensure that no comment is added when the form without comment
     content is saved."""
     self.assertEqual(Comment.objects.count(), 0)
     data = {
         'slug': '2018-12-28-test-event',
         'host': self.org_alpha.id,
         'tags': [self.test_tag.id],
         'comment': '',
     }
     form = EventForm(data)
     form.save()
     self.assertEqual(Comment.objects.count(), 0)
Beispiel #3
0
 def test_creating_event_with_comment(self):
     """Ensure that a comment is added when the form with comment
     content is saved."""
     self.assertEqual(Comment.objects.count(), 0)
     data = {
         'slug': '2018-12-28-test-event',
         'host': self.org_alpha.id,
         'tags': [self.test_tag.id],
         'comment': 'This is a test comment.',
     }
     form = EventForm(data)
     obj = form.save()
     self.assertEqual(Comment.objects.count(), 1)
     comment = Comment.objects.first()
     self.assertEqual(comment.comment, 'This is a test comment.')
     self.assertIn(comment, Comment.objects.for_model(obj))