Пример #1
0
def edit_exportformat(request, format_id):
    export_format = get_object_or_404(ExportFormat, id=format_id)

    if request.method == 'POST' and \
            'manage_export_formats' in export_format.team.get_perms(request.user):

        form = ExportFormatEditForm(request.POST, instance=export_format)
        if form.is_valid():
            if not export_format.name == form.cleaned_data.get('name') and \
                    ExportFormat.objects.filter(
                        name=form.cleaned_data.get('name')).exists():
                form.add_error(
                    'name',
                    _('The name is already in use by an export format.'))
                messages.error(
                    request,
                    _('The name is already in use by an export format.'))
            else:
                with transaction.atomic():

                    edited_export_format = form.save(commit=False)
                    edited_export_format.annotations_types.clear()
                    for annotation_type in form.cleaned_data[
                            'annotations_types']:
                        edited_export_format.annotations_types.add(
                            annotation_type)
                    edited_export_format.save()

                messages.success(
                    request, _('The export format was edited successfully.'))
        else:
            messages.error(request,
                           _('There was an error editing the export format'))

    return redirect(reverse('users:team', args=(export_format.team.id, )))
Пример #2
0
def view_team(request, team_id):
    team = get_object_or_404(Team, id=team_id)
    members = team.members.all().order_by('id')

    is_member = request.user in members
    admins = team.admins

    imagesets = ImageSet.objects.filter(team=team).annotate(
        image_count_agg=Count('images')).prefetch_related('set_tags').\
        order_by('-public', 'name')
    export_formats = ExportFormat.objects.filter(
        team=team).prefetch_related('annotations_types').order_by('name')

    if not is_member:
        export_formats = export_formats.filter(public=True)
        imagesets = imagesets.filter(public=True)

    export_format_forms = []
    for format_instance in export_formats:
        form = ExportFormatEditForm(instance=format_instance)
        form.fields['annotations_types'].queryset = AnnotationType.objects.filter(product__in=Product.objects.
                                                                                  filter(team__in=Team.objects.
                                                                                         filter(members=request.user)))
        export_format_forms.append(form)

    test_imagesets = imagesets.filter(set_tags__name='test').order_by('-public', 'name')

    products = Product.objects.filter(team=team).order_by('team_id')

    return render(request, 'users/view_team.html', {
        'team': team,
        'members': members,
        'admins': admins,
        'imagesets': imagesets,
        'date_imagesets': sorted(imagesets, key=lambda i: i.time, reverse=True),
        'size_imagesets': sorted(imagesets, key=lambda i: i.image_count, reverse=True),
        'test_imagesets': test_imagesets,
        'imageset_creation_form': ImageSetCreationForm(),
        'product_creation_form': ProductCreationForm(),
        'products': products,
        'team_perms': team.get_perms(request.user),
        'export_formats_forms': export_format_forms,
    })
Пример #3
0
def view_team(request, team_id):
    team = get_object_or_404(Team, id=team_id)
    members = team.members.all().order_by('-points')
    members_30 = User.objects.raw(
        '''
    SELECT
      u.id, u.password, u.last_login, u.is_superuser, u.username, u.first_name,
      u.last_name, u.email, u.is_staff, u.is_active, u.date_joined, u.points,
      COUNT(v.id) points_30
    FROM
      users_user u,
      users_teammembership utm,
      annotations_annotation AS a,
      annotations_verification AS v
    WHERE
      utm.team_id = %s AND
      u.id = utm.user_id AND
      a.id = v.annotation_id AND
      a.user_id = u.id AND
      v.time >= NOW() - '30 days'::interval
    GROUP BY
      u.id, u.password, u.last_login, u.is_superuser, u.username, u.first_name,
      u.last_name, u.email, u.is_staff, u.is_active, u.date_joined, u.points
    ORDER BY
      points_30
    DESC
    ''', (team.pk, ))

    is_member = request.user in members
    admins = team.admins

    imagesets = ImageSet.objects.filter(team=team).annotate(
        image_count_agg=Count('images')).prefetch_related('set_tags').\
        order_by('-public', 'name')
    export_formats = ExportFormat.objects.filter(
        team=team).prefetch_related('annotations_types').order_by('name')

    if not is_member:
        export_formats = export_formats.filter(public=True)
        imagesets = imagesets.filter(public=True)

    export_format_forms = []
    for format_instance in export_formats:
        form = ExportFormatEditForm(instance=format_instance)
        form.fields[
            'annotations_types'].queryset = AnnotationType.objects.filter(
                product__in=Product.objects.filter(
                    team__in=Team.objects.filter(members=request.user)))
        export_format_forms.append(form)

    test_imagesets = imagesets.filter(set_tags__name='test').order_by(
        '-public', 'name')

    products = Product.objects.filter(team=team).order_by('team_id')

    return render(
        request, 'users/view_team.html', {
            'team':
            team,
            'members':
            members,
            'members_30':
            members_30,
            'admins':
            admins,
            'imagesets':
            imagesets,
            'date_imagesets':
            sorted(imagesets, key=lambda i: i.time, reverse=True),
            'size_imagesets':
            sorted(imagesets, key=lambda i: i.image_count, reverse=True),
            'test_imagesets':
            test_imagesets,
            'imageset_creation_form':
            ImageSetCreationForm(),
            'product_creation_form':
            ProductCreationForm(),
            'products':
            products,
            'team_perms':
            team.get_perms(request.user),
            'export_formats_forms':
            export_format_forms,
        })