示例#1
0
def overview_unread(request):
    usermessages = Message.in_range(
        TeamMessage.get_messages_for_user(
            request.user)).filter(~Q(read_by=request.user))

    page = request.GET.get('page')
    paginator = Paginator(usermessages, settings.MESSAGES_PER_PAGE)
    usermessages = paginator.get_page(page)

    user_admin_teams = Team.objects.filter(memberships__user=request.user,
                                           memberships__is_admin=True)

    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

    return TemplateResponse(
        request, 'tagger_messages/overview.html', {
            'mode': 'unread',
            'usermessages': usermessages,
            'team_message_creation_form': team_message_creation_form,
            'user_has_admin_teams': user_admin_teams.exists(),
        })
def base_data(request):
    if request.user.is_authenticated:
        my_teams = Team.objects.filter(members=request.user)
        unread_message_count = TeamMessage.in_range(
            TeamMessage.get_messages_for_user(
                request.user).filter(~Q(read_by=request.user))).count()
    else:
        my_teams = None
        unread_message_count = 0

    return {
        'IMPRINT_URL': settings.IMPRINT_URL,
        'USE_IMPRINT': settings.USE_IMPRINT,
        'IMPRINT_NAME': settings.IMPRINT_NAME,
        'TOOLS_ENABLED': settings.TOOLS_ENABLED,
        'my_teams': my_teams,
        'unread_message_count': unread_message_count,
    }
示例#3
0
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,
        })
示例#4
0
def read_all_messages(request):
    messages = Message.in_range(TeamMessage.get_messages_for_user(
        request.user)).filter(~Q(read_by=request.user))
    current_user = User.objects.get(username=request.user.username)
    current_user.read_messages.add(*messages)
    return HttpResponseRedirect(request.META.get('HTTP_REFERER'))