@staff_member_required
def add_image_sequence(request, subject_id):
    try:
        subject = Subject.objects.get(pk=subject_id)
    except Subject.DoesNotExist:
        raise Http404('Subject does not exist')
    if (request.method == 'POST'):
        form = ImageSequenceForm(request.POST)
        if form.is_valid():
            new_image_sequence = form.save(commit=False)
            (start_frame, total_nr_of_frames) = get_start_and_total_frames(new_image_sequence.format)
            print(start_frame, total_nr_of_frames)
            if (start_frame is None):
                messages.error(request, 'No data existed with the provided filename format.')
            else:
                new_image_sequence.nr_of_frames = total_nr_of_frames
                new_image_sequence.start_frame_nr = start_frame
                new_image_sequence.subject = subject
                new_image_sequence.save()
                messages.success(request, 'Sequence successfully added')
                return redirect('dataset_details', subject.dataset.id)
    else:
        form = ImageSequenceForm()
    return render(request, 'annotationweb/add_image_sequence.html', {'form': form, 'subject': subject})
@staff_member_required
def add_image_sequence(request, subject_id):
    try:
        subject = Subject.objects.get(pk=subject_id)
    except Subject.DoesNotExist:
        raise Http404('Subject does not exist')
    if (request.method == 'POST'):
        form = ImageSequenceForm(request.POST)
        if form.is_valid():
            new_image_sequence = form.save(commit=False)
            (start_frame, total_nr_of_frames) = get_start_and_total_frames(new_image_sequence.format)
            print(start_frame, total_nr_of_frames)
            if (start_frame is None):
                messages.error(request, 'No data existed with the provided filename format.')
            else:
                new_image_sequence.nr_of_frames = total_nr_of_frames
                new_image_sequence.start_frame_nr = start_frame
                new_image_sequence.subject = subject
                new_image_sequence.save()
                messages.success(request, 'Sequence successfully added')
                return redirect('dataset_details', subject.dataset.id)
    else:
        form = ImageSequenceForm()
    return render(request, 'annotationweb/add_image_sequence.html', {'form': form, 'subject': subject})