def view_team(request, team_id): team = get_object_or_404(Team, id=team_id) members = team.members.all() is_member = request.user in members admins = team.admins imagesets = ImageSet.objects.filter(team=team).order_by('-public', 'name') if not is_member: imagesets = imagesets.filter(public=True) return render(request, 'users/view_team.html', { 'team': team, 'members': members, 'admins': admins, 'imagesets': imagesets, 'imageset_creation_form': ImageSetCreationForm(), 'team_perms': team.get_perms(request.user), })
def create_imageset(request): team = get_object_or_404(Team, id=request.POST['team']) if not team.has_perm('create_set', request.user): messages.warning( request, _('You do not have permission to create image sets in the team {}.' ).format(team.name)) return redirect(reverse('users:team', args=(team.id, ))) form = ImageSetCreationForm() if request.method == 'POST': form = ImageSetCreationForm(request.POST) if form.is_valid(): if team.image_sets\ .filter(name=form.cleaned_data.get('name')).exists(): form.add_error( 'name', _('The name is already in use by an imageset of this team.' )) else: with transaction.atomic(): form.instance.team = team form.instance.creator = request.user form.instance.save() form.instance.path = '{}_{}'.format( team.id, form.instance.id) form.instance.save() # create a folder to store the images of the set folder_path = form.instance.root_path() root().makedirs(folder_path, recreate=True) # TODO rfrigg: Check if necessary # shutil.chown(folder_path, group=settings.UPLOAD_FS_GROUP) messages.success(request, _('The image set was created successfully.')) return redirect( reverse('images:view_imageset', args=(form.instance.id, ))) return render(request, 'images/create_imageset.html', { 'team': team, 'form': form, })
def view_team(request, team_id): team = get_object_or_404(Team, id=team_id) members = team.members.all().annotate(points=Subquery( Verification.objects.filter( verified=True, annotation__user_id=OuterRef('pk')) .values('annotation__user_id') .annotate(count=Count('annotation__user_id')) .values('count'), output_field=IntegerField())).all()\ .order_by(F('points').desc(nulls_last=True)).distinct() members_30 = team.members.all().annotate(points=Subquery( Verification.objects.filter( verified=True, annotation__user_id=OuterRef('pk'), annotation__time__gte=timezone.now() - datetime.timedelta(days=30)) .values('annotation__user_id') .annotate(count=Count('annotation__user_id')) .values('count'), output_field=IntegerField())).filter(points__gt=0)\ .order_by(F('points').desc(nulls_last=True)).distinct() is_member = request.user in members admins = team.admins imagesets = ImageSet.objects.filter(team=team).order_by('-public', 'name') if is_member: export_formats = ExportFormat.objects.filter(team=team).order_by('name') else: export_formats = ExportFormat.objects.filter(team=team, public=True).order_by('name') export_format_forms = [ExportFormatEditForm(instance=format_instance) for format_instance in export_formats] if not is_member: imagesets = imagesets.filter(public=True) return render(request, 'users/view_team.html', { 'team': team, 'members': members, 'members_30': members_30, 'admins': admins, 'imagesets': imagesets, 'date_imagesets': imagesets.order_by('-time'), 'size_imagesets': sorted(imagesets, key=lambda i: -i.image_count()), 'test_imagesets': imagesets.filter(name__icontains='test'), 'imageset_creation_form': ImageSetCreationForm(), 'team_perms': team.get_perms(request.user), 'export_formats_forms': export_format_forms, })
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')).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 = (ExportFormatEditForm(instance=format_instance) for format_instance in export_formats) test_imagesets = ImageSet.objects.filter(set_tags__name='test').order_by( '-public', 'name') 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(), 'team_perms': team.get_perms(request.user), 'export_formats_forms': export_format_forms, })