Exemplo n.º 1
0
def _set_prop_on_comments(request, instance, prop_name, prop_value):
    comment_ids = get_ids_from_request(request)
    comments = EnhancedThreadedComment.objects.filter(
        pk__in=comment_ids, instance=instance)

    for comment in comments:
        setattr(comment, prop_name, prop_value)
        comment.save()
    return comment_moderation(request, instance)
Exemplo n.º 2
0
def _set_prop_on_comments(request, instance, prop_name, prop_value):
    comment_ids = get_ids_from_request(request)
    comments = EnhancedThreadedComment.objects.filter(pk__in=comment_ids,
                                                      instance=instance)

    for comment in comments:
        setattr(comment, prop_name, prop_value)
        comment.save()
    return comment_moderation(request, instance)
Exemplo n.º 3
0
def comment_moderation(request, instance):
    (is_archived, is_removed, sort) = _comments_params(request.GET)
    page_number = int(request.GET.get('page', '1'))
    page_size = int(request.GET.get('size', '5'))

    comments = get_comments(request.GET, instance)
    paginator = Paginator(comments, page_size)

    try:
        paged_comments = paginator.page(page_number)
    except EmptyPage:
        # If the page number is out of bounds, return the last page
        paged_comments = paginator.page(paginator.num_pages)

    urlizer = UrlParams('comment_moderation',
                        instance.url_name,
                        archived=is_archived,
                        sort=sort,
                        removed=is_removed,
                        page=paged_comments.number)

    comments_url_for_pagination = urlizer.url('archived', 'removed', 'sort')
    comments_url_for_sort = urlizer.url('archived', 'removed')
    comments_url_for_filter = urlizer.url('sort')

    full_params = urlizer.params('archived', 'removed', 'sort', 'page')

    comments_filter = ('Active', _('active'))
    if is_archived is None and is_removed:
        comments_filter = ('Hidden', _('hidden'))
    elif is_archived and is_removed is None:
        comments_filter = ('Archived', _('archived'))

    checked_comments = get_ids_from_request(request)
    if len(checked_comments) == 1:
        # Don't check the box for non-batch requests
        checked_comments = []

    return {
        'comments': paged_comments,
        'comments_filter': comments_filter[0],
        'comments_filter_trans': comments_filter[1],
        'comments_url_for_pagination': comments_url_for_pagination,
        'comments_url_for_sort': comments_url_for_sort,
        'comments_url_for_filter': comments_url_for_filter,
        'comments_params': full_params,
        'comments_sort': sort,
        'comment_ids': checked_comments
    }
Exemplo n.º 4
0
def comment_moderation(request, instance):
    (is_archived, is_removed, sort) = _comments_params(request.GET)
    page_number = int(request.GET.get('page', '1'))
    page_size = int(request.GET.get('size', '5'))

    comments = get_comments(request.GET, instance)
    paginator = Paginator(comments, page_size)

    try:
        paged_comments = paginator.page(page_number)
    except EmptyPage:
        # If the page number is out of bounds, return the last page
        paged_comments = paginator.page(paginator.num_pages)

    urlizer = UrlParams('comment_moderation',
                        instance.url_name,
                        archived=is_archived,
                        sort=sort,
                        removed=is_removed,
                        page=paged_comments.number)

    comments_url_for_pagination = urlizer.url('archived', 'removed', 'sort')
    comments_url_for_sort = urlizer.url('archived', 'removed')

    full_params = urlizer.params('archived', 'removed', 'sort', 'page')

    checked_comments = get_ids_from_request(request)
    if len(checked_comments) == 1:
        # Don't check the box for non-batch requests
        checked_comments = []

    filter_value = dict(archived=is_archived, removed=is_removed)

    filter_context = make_filter_context(urlizer, filter_value, [
        (_('Active'), _('active'), dict(archived=False, removed=None)),
        (_('Hidden'), _('hidden'), dict(archived=None, removed=True)),
        (_('Archived'), _('archived'), dict(archived=True, removed=None)),
    ])
    filter_context['container_attr'] = 'data-comments-filter'

    return {
        'comments': paged_comments,
        'comments_filter': filter_context,
        'comments_url_for_pagination': comments_url_for_pagination,
        'comments_url_for_sort': comments_url_for_sort,
        'comments_params': full_params,
        'comments_sort': sort,
        'comment_ids': checked_comments
    }
Exemplo n.º 5
0
def approve_or_reject_photos(request, instance, action):
    approved = action == 'approve'

    photo_ids = get_ids_from_request(request)

    for photo_id in photo_ids:
        try:
            photo = (MapFeaturePhoto.objects
                     .select_related('treephoto')
                     .get(pk=photo_id))
            try:
                photo = photo.treephoto
            except MapFeaturePhoto.DoesNotExist:
                pass  # There is no tree photo, so use the superclass
        except MapFeaturePhoto.DoesNotExist:
            # This may be a pending tree. Let's see if there
            # are pending audits
            pending_audits = Audit.objects\
                .filter(instance=instance)\
                .filter(model__in=['TreePhoto', 'MapFeaturePhoto'])\
                .filter(model_id=photo_id)\
                .filter(requires_auth=True)

            if len(pending_audits) > 0:
                # Process as pending and quit
                approve_or_reject_audits_and_apply(
                    pending_audits, request.user, approved)

                return photo_review(request, instance)
            else:
                # Error - no pending or regular
                raise Http404('Photo Not Found')

        # Handle the id audit first
        all_audits = []
        for audit in photo.audits():
            if audit.field == 'id':
                all_audits = [audit] + all_audits
            else:
                all_audits.append(audit)

        for audit in all_audits:
            approve_or_reject_existing_edit(
                audit, request.user, approved)

    return photo_review(request, instance)
Exemplo n.º 6
0
def comment_moderation(request, instance):
    (is_archived, is_removed, sort) = _comments_params(request.GET)
    page_number = int(request.GET.get('page', '1'))
    page_size = int(request.GET.get('size', '5'))

    comments = get_comments(request.GET, instance)
    paginator = Paginator(comments, page_size)

    try:
        paged_comments = paginator.page(page_number)
    except EmptyPage:
        # If the page number is out of bounds, return the last page
        paged_comments = paginator.page(paginator.num_pages)

    urlizer = UrlParams('comment_moderation', instance.url_name,
                        archived=is_archived, sort=sort, removed=is_removed,
                        page=paged_comments.number)

    comments_url_for_pagination = urlizer.url('archived', 'removed', 'sort')
    comments_url_for_sort = urlizer.url('archived', 'removed')
    comments_url_for_filter = urlizer.url('sort')

    full_params = urlizer.params('archived', 'removed', 'sort', 'page')

    comments_filter = ('Active', _('active'))
    if is_archived is None and is_removed:
        comments_filter = ('Hidden', _('hidden'))
    elif is_archived and is_removed is None:
        comments_filter = ('Archived', _('archived'))

    checked_comments = get_ids_from_request(request)
    if len(checked_comments) == 1:
        # Don't check the box for non-batch requests
        checked_comments = []

    return {
        'comments': paged_comments,
        'comments_filter': comments_filter[0],
        'comments_filter_trans': comments_filter[1],
        'comments_url_for_pagination': comments_url_for_pagination,
        'comments_url_for_sort': comments_url_for_sort,
        'comments_url_for_filter': comments_url_for_filter,
        'comments_params': full_params,
        'comments_sort': sort,
        'comment_ids': checked_comments
    }
Exemplo n.º 7
0
def comment_moderation(request, instance):
    (is_archived, is_removed, sort) = _comments_params(request.GET)
    page_number = int(request.GET.get('page', '1'))
    page_size = int(request.GET.get('size', '5'))

    comments = get_comments(request.GET, instance)
    paginator = Paginator(comments, page_size)

    try:
        paged_comments = paginator.page(page_number)
    except EmptyPage:
        # If the page number is out of bounds, return the last page
        paged_comments = paginator.page(paginator.num_pages)

    urlizer = UrlParams('comment_moderation', instance.url_name,
                        archived=is_archived, sort=sort, removed=is_removed,
                        page=paged_comments.number)

    comments_url_for_pagination = urlizer.url('archived', 'removed', 'sort')
    comments_url_for_sort = urlizer.url('archived', 'removed')

    full_params = urlizer.params('archived', 'removed', 'sort', 'page')

    checked_comments = get_ids_from_request(request)
    if len(checked_comments) == 1:
        # Don't check the box for non-batch requests
        checked_comments = []

    filter_value = dict(archived=is_archived, removed=is_removed)

    filter_context = make_filter_context(urlizer, filter_value, [
        (_('Active'), _('active'), dict(archived=False, removed=None)),
        (_('Hidden'), _('hidden'), dict(archived=None, removed=True)),
        (_('Archived'), _('archived'), dict(archived=True, removed=None)),
    ])
    filter_context['container_attr'] = 'data-comments-filter'

    return {
        'comments': paged_comments,
        'comments_filter': filter_context,
        'comments_url_for_pagination': comments_url_for_pagination,
        'comments_url_for_sort': comments_url_for_sort,
        'comments_params': full_params,
        'comments_sort': sort,
        'comment_ids': checked_comments
    }
Exemplo n.º 8
0
def approve_or_reject_photos(request, instance, action):
    approved = action == 'approve'

    photo_ids = get_ids_from_request(request)

    for photo_id in photo_ids:
        try:
            photo = (MapFeaturePhoto.objects.select_related('treephoto').get(
                pk=photo_id))
            try:
                photo = photo.treephoto
            except MapFeaturePhoto.DoesNotExist:
                pass  # There is no tree photo, so use the superclass
        except MapFeaturePhoto.DoesNotExist:
            # This may be a pending tree. Let's see if there
            # are pending audits
            pending_audits = Audit.objects\
                .filter(instance=instance)\
                .filter(model__in=['TreePhoto', 'MapFeaturePhoto'])\
                .filter(model_id=photo_id)\
                .filter(requires_auth=True)

            if len(pending_audits) > 0:
                # Process as pending and quit
                approve_or_reject_audits_and_apply(pending_audits,
                                                   request.user, approved)

                return photo_review(request, instance)
            else:
                # Error - no pending or regular
                raise Http404('Photo Not Found')

        # Handle the id audit first
        all_audits = []
        for audit in photo.audits():
            if audit.field == 'id':
                all_audits = [audit] + all_audits
            else:
                all_audits.append(audit)

        for audit in all_audits:
            approve_or_reject_existing_edit(audit, request.user, approved)

    return photo_review(request, instance)
Exemplo n.º 9
0
def hide_flags(request, instance):
    comment_ids = get_ids_from_request(request)
    EnhancedThreadedCommentFlag.objects.filter(comment__id__in=comment_ids,
                                               comment__instance=instance)\
        .update(hidden=True)
    return comment_moderation(request, instance)
Exemplo n.º 10
0
def hide_flags(request, instance):
    comment_ids = get_ids_from_request(request)
    EnhancedThreadedCommentFlag.objects.filter(comment__id__in=comment_ids,
                                               comment__instance=instance)\
        .update(hidden=True)
    return comment_moderation(request, instance)