def create_team(request): form = TeamCreationForm() if request.method == 'POST': form = TeamCreationForm(request.POST) if form.is_valid(): with transaction.atomic(): form.instance.save() form.instance.memberships.create(user=request.user, is_admin=True) return redirect(reverse('users:team', args=(form.instance.id, ))) return render(request, 'users/create_team.html', { 'form': form, })
def index(request): team_creation_form = TeamCreationForm() # needed to show the list of the users imagesets userteams = Team.objects.filter(members=request.user) imagesets = ImageSet.objects.filter(team__in=userteams).annotate( image_count_agg=Count('images') ).select_related('team').prefetch_related('set_tags') \ .order_by('-priority', '-time') imageset_creation_form = ImageSetCreationFormWT( ) # the user provides the team manually imageset_creation_form.fields['team'].queryset = userteams annotation_types = Annotation.objects.values('annotation_type').annotate( annotation_count=Count('pk'), public_annotation_count=Count('pk', filter=Q(image__image_set__public=True)), name=F('annotation_type__name')) image_stats = Image.objects.aggregate( total_count=Count('pk'), public_count=Count('pk', filter=Q(image_set__public=True))) imageset_stats = ImageSet.objects.aggregate(total_count=Count('pk'), public_count=Count( 'pk', filter=Q(public=True))) user_stats = User.objects.aggregate(total_count=Count('pk'), active_count=Count( 'pk', filter=Q(points__gte=50))) team_stats = Team.objects.aggregate( total_count=Count('pk'), active_count=Count( 'pk', filter=Q(pk__in=Team.objects.filter( memberships__user__in=User.objects.filter(points__gte=50))))) stats = { 'all_images': image_stats.get('total_count', 0) or 0, 'public_images': image_stats.get('public_count', 0) or 0, 'all_imagesets': imageset_stats.get('total_count', 0) or 0, 'public_imagesets': imageset_stats.get('public_count', 0) or 0, 'all_users': user_stats.get('total_count', 0) or 0, 'active_users': user_stats.get('active_count', 0) or 0, 'all_teams': team_stats.get('total_count', 0) or 0, 'active_teams': team_stats.get('active_count', 0) or 0, 'annotation_types': annotation_types[:3], } return TemplateResponse( request, 'images/index.html', { 'team_creation_form': team_creation_form, 'imageset_creation_form': imageset_creation_form, 'image_sets': imagesets, 'userteams': userteams, 'stats': stats, })
def index(request): team_creation_form = TeamCreationForm() # needed to show the list of the users imagesets userteams = Team.objects.filter(members=request.user) imagesets = ImageSet.objects.select_related()\ .filter(team__in=userteams).order_by('id') return TemplateResponse( request, 'images/index.html', { 'team_creation_form': team_creation_form, 'image_sets': imagesets, 'userteams': userteams, })
def index(request): team_creation_form = TeamCreationForm() # needed to show the list of the users imagesets userteams = Team.objects.filter(members=request.user) imagesets = ImageSet.objects.annotate( image_count_agg=Count('images')).select_related('team').filter( team__in=userteams).order_by('-priority', '-time') imageset_creation_form = ImageSetCreationFormWT( ) # the user provides the team manually imageset_creation_form.fields['team'].queryset = userteams all_images = Image.objects.all().select_related('image_set') public_images = all_images.filter(image_set__public=True) annotation_types = AnnotationType.objects.annotate( annotation_count=Count('annotation'), public_annotation_count=Count( Coalesce( Subquery( Annotation.objects.filter( image__image_set__public=True, annotation_type_id=OuterRef('pk')).values( 'annotation_type_id').annotate( count=Count('pk')).values('count')), 0))).order_by('annotation_count') all_imagesets = ImageSet.objects.all() all_users = User.objects.all() active_users = all_users.filter(points__gte=50) all_teams = Team.objects.all() active_teams = Team.objects.annotate( mc=Count('members', filter=Q(memberships__user__in=User.objects.filter( points__gte=50)))).filter(mc__gte=2) stats = { 'all_images': all_images.count(), 'public_images': public_images.count(), 'all_imagesets': all_imagesets.count(), 'public_imagesets': all_imagesets.filter(public=True).count(), 'all_users': all_users.count(), 'active_users': active_users.count(), 'all_teams': all_teams.count(), 'active_teams': active_teams.count(), 'annotation_types': annotation_types[:3], } return TemplateResponse( request, 'images/index.html', { 'team_creation_form': team_creation_form, 'imageset_creation_form': imageset_creation_form, 'image_sets': imagesets, 'userteams': userteams, 'stats': stats, })
def index(request): team_creation_form = TeamCreationForm() # needed to show the list of the users imagesets userteams = Team.objects.filter(members=request.user) # get all teams where the user is an admin user_admin_teams = Team.objects.filter(memberships__user=request.user, memberships__is_admin=True) imagesets = ImageSet.objects.filter(team__in=userteams).annotate( image_count_agg=Count('images') ).select_related('team').prefetch_related('set_tags') \ .order_by('-priority', '-time') imageset_creation_form = ImageSetCreationFormWT( ) # the user provides the team manually imageset_creation_form.fields['team'].queryset = userteams annotation_types = Annotation.objects.values('annotation_type').annotate( annotation_count=Count('pk'), public_annotation_count=Count('pk', filter=Q(image__image_set__public=True)), name=F('annotation_type__name')).order_by('-public_annotation_count') image_stats = Image.objects.aggregate( total_count=Count('pk'), public_count=Count('pk', filter=Q(image_set__public=True))) imageset_stats = ImageSet.objects.aggregate(total_count=Count('pk'), public_count=Count( 'pk', filter=Q(public=True))) user_stats = User.objects.aggregate(total_count=Count('pk'), active_count=Count( 'pk', filter=Q(points__gte=50))) team_stats = Team.objects.aggregate( total_count=Count('pk'), active_count=Count( 'pk', filter=Q(pk__in=Team.objects.filter( memberships__user__in=User.objects.filter(points__gte=50))))) stats = { 'all_images': image_stats.get('total_count', 0) or 0, 'public_images': image_stats.get('public_count', 0) or 0, 'all_imagesets': imageset_stats.get('total_count', 0) or 0, 'public_imagesets': imageset_stats.get('public_count', 0) or 0, 'all_users': user_stats.get('total_count', 0) or 0, 'active_users': user_stats.get('active_count', 0) or 0, 'all_teams': team_stats.get('total_count', 0) or 0, 'active_teams': team_stats.get('active_count', 0) or 0, 'annotation_types': annotation_types[:3], } global_annoucements = Message.in_range( GlobalMessage.get(request.user).filter(~Q(read_by=request.user))) # Inits message creation form team_message_creation_form = TeamMessageCreationForm( initial={ 'start_time': str(date.today()), 'expire_time': str(date.today() + timedelta(days=settings.DEFAULT_EXPIRE_TIME)), }) team_message_creation_form.fields['team'].queryset = user_admin_teams # Gets all unread messages usermessages = Message.in_range( TeamMessage.get_messages_for_user( request.user)).filter(~Q(read_by=request.user)) too_many_massages = False front_page_messages = 5 if usermessages.count() > front_page_messages: usermessages = usermessages[:front_page_messages] too_many_massages = True many_annoucements = False if global_annoucements.count() > 5: many_annoucements = True return TemplateResponse( request, 'images/index.html', { 'user': request.user, 'team_creation_form': team_creation_form, 'imageset_creation_form': imageset_creation_form, 'team_message_creation_form': team_message_creation_form, 'image_sets': imagesets, 'user_has_admin_teams': user_admin_teams.exists(), 'userteams': userteams, 'stats': stats, 'usermessages': usermessages, 'too_many_messages': too_many_massages, 'many_annoucements': many_annoucements, 'global_annoucements': global_annoucements, })