Esempio n. 1
0
def view_imageset(request, image_set_id):
    imageset = get_object_or_404(ImageSet, id=image_set_id)
    # images the imageset contains
    images = Image.objects.filter(image_set=imageset).order_by('name')
    # the saved exports of the imageset
    exports = Export.objects.filter(image_set=image_set_id).order_by('-id')[:5]
    filtered = False
    form_filter = request.POST.get('filter')
    if request.method == "POST" and form_filter is not None:
        filtered = True
        # filter images for missing annotationtype
        images = images.exclude(
            annotations__annotation_type_id=request.POST.get("selected_annotation_type"))
    # a list of annotation types used in the imageset
    annotation_types = set()
    annotations = Annotation.objects.select_related().filter(
        image__in=images).order_by("id")
    annotation_types = annotation_types.union(
        [annotation.annotation_type for annotation in annotations])
    first_annotation = annotations.first()
    return render(request, 'images/imageset.html', {
        'images': images,
        'annotationcount': len(annotations),
        'imageset': imageset,
        'annotationtypes': annotation_types,
        'annotation_types': annotation_types,
        'first_annotation': first_annotation,
        'exports': exports,
        'filtered': filtered,
        'edit_form': ImageSetEditForm(instance=imageset),
        'imageset_perms': imageset.get_perms(request.user),
        'export_formats': ExportFormat.objects.filter(Q(public=True)|Q(team=imageset.team)),
        'upload_notice': settings.UPLOAD_NOTICE
    })
Esempio n. 2
0
def view_imageset(request, image_set_id):
    imageset = get_object_or_404(ImageSet, id=image_set_id)
    if not imageset.has_perm('read', request.user):
        messages.warning(request, 'you do not have the permission to access this imageset')
        return redirect(reverse('images:index'))
    # images the imageset contains
    images = Image.objects.filter(image_set=imageset).order_by('name')
    # the saved exports of the imageset
    exports = Export.objects.filter(image_set=image_set_id).order_by('-id')[:5]
    filtered = False
    form_filter = request.POST.get('filter')
    if request.method == "POST" and form_filter is not None:
        filtered = True
        # filter images for missing annotationtype
        images = images.exclude(
            annotations__annotation_type_id=request.POST.get("selected_annotation_type"))
    # a list of annotation types used in the imageset
    all_annotation_types = AnnotationType.objects.filter(active=True)
    annotation_types = set()
    annotations = Annotation.objects.select_related().filter(
        image__in=images,
        annotation_type__active=True).order_by("id")
    annotation_types = annotation_types.union(
        [annotation.annotation_type for annotation in annotations])
    annotation_type_count = sorted(list(
        map(
            lambda at: count_annotations_of_type(annotations, at),
            annotation_types)),
        key=lambda at_tuple: at_tuple[1],
        reverse=True)
    first_annotation = annotations.first()
    user_teams = Team.objects.filter(members=request.user)
    imageset_edit_form = ImageSetEditForm(instance=imageset)
    imageset_edit_form.fields['main_annotation_type'].queryset = AnnotationType.objects.filter(active=True)
    return render(request, 'images/imageset.html', {
        'images': images,
        'annotationcount': len(annotations),
        'imageset': imageset,
        'annotationtypes': annotation_types,
        'annotation_types': annotation_types,
        'all_annotation_types': all_annotation_types,
        'annotation_type_count': annotation_type_count,
        'first_annotation': first_annotation,
        'exports': exports,
        'filtered': filtered,
        'edit_form': imageset_edit_form,
        'imageset_perms': imageset.get_perms(request.user),
        'export_formats': ExportFormat.objects.filter(Q(public=True) | Q(team__in=user_teams)),
        'label_upload_form': LabelUploadForm(),
        'upload_notice': settings.UPLOAD_NOTICE,
        'enable_zip_download': settings.ENABLE_ZIP_DOWNLOAD,
    })
Esempio n. 3
0
def edit_imageset(request, imageset_id):
    imageset = get_object_or_404(ImageSet, id=imageset_id)
    if not imageset.has_perm('edit_set', request.user):
        messages.warning(
            request, _('You do not have permission to edit this imageset.'))
        return redirect(reverse('images:view_imageset', args=(imageset.id, )))

    form = ImageSetEditForm(instance=imageset)

    if request.method == 'POST':
        form = ImageSetEditForm(request.POST, instance=imageset)
        if form.is_valid():
            form.save()
            # TODO: check if name and path are unique in the team
            return redirect(
                reverse('images:view_imageset', args=(imageset.id, )))

    return render(request, 'images/edit_imageset.html', {
        'form': form,
    })