Esempio n. 1
0
def chooser(request):
    Document = get_document_model()

    if permission_policy.user_has_permission(request.user, "add"):
        DocumentForm = get_document_form(Document)
        uploadform = DocumentForm()
    else:
        uploadform = None

    documents = []

    q = None
    is_searching = False
    if "q" in request.GET or "p" in request.GET or "collection_id" in request.GET:
        documents = Document.objects.all()

        collection_id = request.GET.get("collection_id")
        if collection_id:
            documents = documents.filter(collection=collection_id)

        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            q = searchform.cleaned_data["q"]

            documents = documents.search(q)
            is_searching = True
        else:
            documents = documents.order_by("-created_at")
            is_searching = False

        # Pagination
        paginator, documents = paginate(request, documents, per_page=10)

        return render(
            request,
            "wagtaildocs/chooser/results.html",
            {"documents": documents, "query_string": q, "is_searching": is_searching},
        )
    else:
        searchform = SearchForm()

        collections = Collection.objects.all()
        if len(collections) < 2:
            collections = None

        documents = Document.objects.order_by("-created_at")
        paginator, documents = paginate(request, documents, per_page=10)

    return render_modal_workflow(
        request,
        "wagtaildocs/chooser/chooser.html",
        "wagtaildocs/chooser/chooser.js",
        {
            "documents": documents,
            "uploadform": uploadform,
            "searchform": searchform,
            "collections": collections,
            "is_searching": False,
        },
    )
Esempio n. 2
0
def chooser(request):
    Image = get_image_model()

    if permission_policy.user_has_permission(request.user, 'add'):
        ImageForm = get_image_form(Image)
        uploadform = ImageForm(user=request.user)
    else:
        uploadform = None

    images = Image.objects.order_by('-created_at')

    # allow hooks to modify the queryset
    for hook in hooks.get_hooks('construct_image_chooser_queryset'):
        images = hook(images, request)

    if (
        'q' in request.GET or 'p' in request.GET or 'tag' in request.GET or
        'collection_id' in request.GET
    ):
        # this request is triggered from search, pagination or 'popular tags';
        # we will just render the results.html fragment
        collection_id = request.GET.get('collection_id')
        if collection_id:
            images = images.filter(collection=collection_id)

        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            q = searchform.cleaned_data['q']

            images = images.search(q)
            is_searching = True
        else:
            is_searching = False
            q = None

            tag_name = request.GET.get('tag')
            if tag_name:
                images = images.filter(tags__name=tag_name)

        # Pagination
        paginator, images = paginate(request, images, per_page=12)

        return render(request, "wagtailimages/chooser/results.html", {
            'images': images,
            'is_searching': is_searching,
            'query_string': q,
            'will_select_format': request.GET.get('select_format')
        })
    else:
        paginator, images = paginate(request, images, per_page=12)

        context = get_chooser_context(request)
        context.update({
            'images': images,
            'uploadform': uploadform,
        })
        return render_modal_workflow(
            request, 'wagtailimages/chooser/chooser.html', None, context,
            json_data=get_chooser_js_data()
        )
Esempio n. 3
0
def chooser(request):
    Document = get_document_model()

    if permission_policy.user_has_permission(request.user, 'add'):
        DocumentForm = get_document_form(Document)
        uploadform = DocumentForm(user=request.user)
    else:
        uploadform = None

    documents = Document.objects.all()

    # allow hooks to modify the queryset
    for hook in hooks.get_hooks('construct_document_chooser_queryset'):
        documents = hook(documents, request)

    q = None
    if 'q' in request.GET or 'p' in request.GET or 'collection_id' in request.GET:

        collection_id = request.GET.get('collection_id')
        if collection_id:
            documents = documents.filter(collection=collection_id)

        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            q = searchform.cleaned_data['q']

            documents = documents.search(q)
            is_searching = True
        else:
            documents = documents.order_by('-created_at')
            is_searching = False

        # Pagination
        paginator, documents = paginate(request, documents, per_page=10)

        return render(request, "wagtaildocs/chooser/results.html", {
            'documents': documents,
            'query_string': q,
            'is_searching': is_searching,
        })
    else:
        searchform = SearchForm()

        collections = Collection.objects.all()
        if len(collections) < 2:
            collections = None

        documents = documents.order_by('-created_at')
        paginator, documents = paginate(request, documents, per_page=10)

        return render_modal_workflow(request, 'wagtaildocs/chooser/chooser.html', 'wagtaildocs/chooser/chooser.js', {
            'documents': documents,
            'uploadform': uploadform,
            'searchform': searchform,
            'collections': collections,
            'is_searching': False,
            'uploadid': uuid.uuid4(),
        })
Esempio n. 4
0
def chooser(request):
    VideoForm = get_video_form(Video)
    uploadform = VideoForm()

    videos = Video.objects.order_by('-created_at')

    q = None
    if (
        'q' in request.GET or 'p' in request.GET or 'tag' in request.GET or
        'collection_id' in request.GET
    ):
        # this request is triggered from search, pagination or 'popular tags';
        # we will just render the results.html fragment
        collection_id = request.GET.get('collection_id')
        if collection_id:
            videos = videos.filter(collection=collection_id)

        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            q = searchform.cleaned_data['q']

            videos = videos.search(q)
            is_searching = True
        else:
            is_searching = False

            tag_name = request.GET.get('tag')
            if tag_name:
                videos = videos.filter(tags__name=tag_name)

        # Pagination
        paginator, videos = paginate(request, videos, per_page=12)

        return render(request, "wagtailvideos/chooser/results.html", {
            'videos': videos,
            'is_searching': is_searching,
            'query_string': q,
        })
    else:
        searchform = SearchForm()

        collections = Collection.objects.all()
        if len(collections) < 2:
            collections = None

        paginator, videos = paginate(request, videos, per_page=12)

    return render_modal_workflow(request, 'wagtailvideos/chooser/chooser.html', 'wagtailvideos/chooser/chooser.js', {
        'videos': videos,
        'uploadform': uploadform,
        'searchform': searchform,
        'is_searching': False,
        'query_string': q,
        'popular_tags': popular_tags_for_model(Video),
        'collections': collections,
    })
Esempio n. 5
0
def chooser(request):
    Image = get_image_model()

    if request.user.has_perm('wagtailimages.add_image'):
        ImageForm = get_image_form(Image)
        uploadform = ImageForm()
    else:
        uploadform = None

    images = Image.objects.order_by('-created_at')

    q = None
    if 'q' in request.GET or 'p' in request.GET or 'tag' in request.GET:
        # this request is triggered from search, pagination or 'popular tags';
        # we will just render the results.html fragment

        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            q = searchform.cleaned_data['q']

            images = images.search(q)
            is_searching = True
        else:
            is_searching = False

            tag_name = request.GET.get('tag')
            if tag_name:
                images = images.filter(tags__name=tag_name)

        # Pagination
        paginator, images = paginate(request, images, per_page=12)

        return render(
            request, "wagtailimages/chooser/results.html", {
                'images': images,
                'is_searching': is_searching,
                'query_string': q,
                'will_select_format': request.GET.get('select_format')
            })
    else:
        searchform = SearchForm()

        paginator, images = paginate(request, images, per_page=12)

    return render_modal_workflow(
        request, 'wagtailimages/chooser/chooser.html',
        'wagtailimages/chooser/chooser.js', {
            'images': images,
            'uploadform': uploadform,
            'searchform': searchform,
            'is_searching': False,
            'query_string': q,
            'will_select_format': request.GET.get('select_format'),
            'popular_tags': Image.popular_tags(),
        })
Esempio n. 6
0
def chooser(request):
    EmbedVideo = get_embed_video_model()

    if request.user.has_perm('wagtail_embed_videos.add_embedvideo'):
        can_add = True
    else:
        can_add = False

    q = None
    embed_videos = EmbedVideo.objects.order_by('-created_at')
    if 'q' in request.GET or 'p' in request.GET:
        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            q = searchform.cleaned_data['q']

            embed_videos = embed_videos.search(q)

            is_searching = True

        else:
            is_searching = False
            q = None

        # Pagination
        paginator, embed_videos = paginate(request, embed_videos, per_page=12)

        return render(request, "wagtail_embed_videos/chooser/results.html", {
            'embed_videos': embed_videos,
            'is_searching': is_searching,
            'can_add': can_add,
            'query_string': q,
        })
    else:
        paginator, embed_videos = paginate(request, embed_videos, per_page=12)

        searchform = SearchForm()

    return render_modal_workflow(
        request,
        'wagtail_embed_videos/chooser/chooser.html',
        None,#'wagtail_embed_videos/chooser/chooser.js',
        template_vars={
            'embed_videos': embed_videos,
            'searchform': searchform,
            'is_searching': False,
            'can_add': can_add,
            'query_string': q,
            'popular_tags': popular_tags_for_model(EmbedVideo),
        },
        json_data={
            'step': 'chooser',
        }
    )
Esempio n. 7
0
def chooser(request):
    Image = get_image_model()

    if request.user.has_perm('wagtailimages.add_image'):
        ImageForm = get_image_form(Image)
        uploadform = ImageForm()
    else:
        uploadform = None

    images = Image.objects.order_by('-created_at')

    q = None
    if 'q' in request.GET or 'p' in request.GET or 'tag' in request.GET:
        # this request is triggered from search, pagination or 'popular tags';
        # we will just render the results.html fragment

        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            q = searchform.cleaned_data['q']

            images = images.search(q)
            is_searching = True
        else:
            is_searching = False

            tag_name = request.GET.get('tag')
            if tag_name:
                images = images.filter(tags__name=tag_name)

        # Pagination
        paginator, images = paginate(request, images, per_page=12)

        return render(request, "wagtailimages/chooser/results.html", {
            'images': images,
            'is_searching': is_searching,
            'query_string': q,
            'will_select_format': request.GET.get('select_format')
        })
    else:
        searchform = SearchForm()

        paginator, images = paginate(request, images, per_page=12)

    return render_modal_workflow(request, 'wagtailimages/chooser/chooser.html', 'wagtailimages/chooser/chooser.js', {
        'images': images,
        'uploadform': uploadform,
        'searchform': searchform,
        'is_searching': False,
        'query_string': q,
        'will_select_format': request.GET.get('select_format'),
        'popular_tags': Image.popular_tags(),
    })
Esempio n. 8
0
def chooser(request):
    Media = get_media_model()

    media_files = []

    q = None
    is_searching = False
    if 'q' in request.GET or 'p' in request.GET or 'collection_id' in request.GET:
        media_files = Media.objects.all()

        collection_id = request.GET.get('collection_id')
        if collection_id:
            media_files = media_files.filter(collection=collection_id)

        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            q = searchform.cleaned_data['q']

            media_files = media_files.search(q)
            is_searching = True
        else:
            media_files = media_files.order_by('-created_at')
            is_searching = False

        # Pagination
        paginator, media_files = paginate(request, media_files, per_page=10)

        return render(
            request, "wagtailmedia/chooser/results.html", {
                'media_files': media_files,
                'query_string': q,
                'is_searching': is_searching,
            })
    else:
        searchform = SearchForm()

        collections = Collection.objects.all()
        if len(collections) < 2:
            collections = None

        media_files = Media.objects.order_by('-created_at')
        paginator, media_files = paginate(request, media_files, per_page=10)

    return render_modal_workflow(
        request, 'wagtailmedia/chooser/chooser.html',
        'wagtailmedia/chooser/chooser.js', {
            'media_files': media_files,
            'searchform': searchform,
            'collections': collections,
            'is_searching': False,
        })
def chooser(request):
    EmbedVideo = get_embed_video_model()

    if request.user.has_perm('wagtail_embed_videos.add_embedvideo'):
        can_add = True
    else:
        can_add = False

    q = None
    embed_videos = EmbedVideo.objects.order_by('-created_at')
    if 'q' in request.GET or 'p' in request.GET:
        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            q = searchform.cleaned_data['q']

            embed_videos = embed_videos.search(q)

            is_searching = True

        else:
            is_searching = False
            q = None

        # Pagination
        paginator, embed_videos = paginate(request, embed_videos, per_page=12)

        return render(request, "wagtail_embed_videos/chooser/results.html", {
            'embed_videos': embed_videos,
            'is_searching': is_searching,
            'can_add': can_add,
            'query_string': q,
        })
    else:
        paginator, embed_videos = paginate(request, embed_videos, per_page=12)

        searchform = SearchForm()

    return render_modal_workflow(
        request,
        'wagtail_embed_videos/chooser/chooser.html',
        'wagtail_embed_videos/chooser/chooser.js',
        {
            'embed_videos': embed_videos,
            'searchform': searchform,
            'is_searching': False,
            'can_add': can_add,
            'query_string': q,
            'popular_tags': popular_tags_for_model(EmbedVideo),
        }
    )
Esempio n. 10
0
def chooser(request):
    Report = get_report_model()

    if permission_policy.user_has_permission(request.user, 'add'):
        ReportForm = get_report_form(Report)
        uploadform = ReportForm(user=request.user)
    else:
        uploadform = None

    reports = Report.objects.all()

    # allow hooks to modify the queryset
    for hook in hooks.get_hooks('construct_report_chooser_queryset'):
        reports = hook(reports, request)

    q = None
    if 'q' in request.GET or 'p' in request.GET:

        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            q = searchform.cleaned_data['q']

            reports = reports.search(q)
            is_searching = True
        else:
            reports = reports.order_by('-created_at')
            is_searching = False

        # Pagination
        paginator, reports = paginate(request, reports, per_page=10)

        return render(request, "wagtailreports/chooser/results.html", {
            'reports': reports,
            'query_string': q,
            'is_searching': is_searching,
        })
    else:
        searchform = SearchForm()

        reports = reports.order_by('-created_at')
        paginator, reports = paginate(request, reports, per_page=10)

        return render_modal_workflow(
            request, 'wagtailreports/chooser/chooser.html',
            'wagtailreports/chooser/chooser.js', {
                'reports': reports,
                'uploadform': uploadform,
                'searchform': searchform,
                'is_searching': False,
            })
Esempio n. 11
0
def chooser(request):
    """
    Video chooser view with ability to search
    """
    videos = video_permission_policy.instances_user_has_any_permission_for(
        request.user, ['change', 'delete'])

    q = None
    if 'q' in request.GET or 'p' in request.GET or 'collection_id' in request.GET:
        collection_id = request.GET.get('collection_id')
        if collection_id:
            videos = videos.filter(collection=collection_id)

        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            q = searchform.cleaned_data['q']

            videos = videos.search(q)
            is_searching = True
        else:
            videos = videos.order_by('-created_at')
            is_searching = False

        # Pagination
        paginator, videos = paginate(request, videos, per_page=10)  # pylint: disable=unused-variable

        return render(request, "videos/chooser/results.html", {
            'videos': videos,
            'query_string': q,
            'is_searching': is_searching,
        })
    else:
        searchform = SearchForm()

        collections = Collection.objects.all()
        if len(collections) < 2:
            collections = None

        videos = videos.order_by('-created_at')
        paginator, videos = paginate(request, videos, per_page=10)

        return render_modal_workflow(
            request, 'videos/chooser/chooser.html',
            'videos/chooser/chooser.js', {
                'videos': videos,
                'uploadform': None,
                'searchform': searchform,
                'collections': collections,
                'is_searching': False,
            })
Esempio n. 12
0
def choose(request, app_label, model_name):
    model = get_model_or_404(app_label, model_name)
    objects = model.objects.all()

    q = None
    if ('q' in request.GET or 'p' in request.GET):
        # this request is triggered from search or pagination
        # we will just render the results.html fragment

        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            q = searchform.cleaned_data['q']

            objects = objects.search(q)
            is_searching = True
        else:
            is_searching = False

        # Pagination
        paginator, objects = paginate(request, objects, per_page=12)

        return render(request, "modeladminutils/chooser/results.html", {
            'objects': objects,
            'is_searching': is_searching,
            'query_string': q,
            'will_select_format': request.GET.get('select_format'),
            'app_label': app_label,
            'model_name': model_name,
            'model_verbose_name_plural': model._meta.verbose_name_plural,
        })
    else:
        searchform = SearchForm()

        paginator, objects = paginate(request, objects, per_page=12)

    return render_modal_workflow(
        request,
        'modeladminutils/chooser/chooser.html',
        'modeladminutils/chooser/chooser.js',
        {
            'objects': objects,
            'searchform': searchform,
            'is_searching': False,
            'query_string': q,
            'app_label': app_label,
            'model_name': model_name,
            'model_verbose_name': model._meta.verbose_name,
        }
    )
Esempio n. 13
0
def choose(request, app_label, model_name):
    model = get_model_or_404(app_label, model_name)
    objects = model.objects.all()

    q = None
    if ('q' in request.GET or 'p' in request.GET):
        # this request is triggered from search or pagination
        # we will just render the results.html fragment

        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            q = searchform.cleaned_data['q']

            objects = objects.search(q)
            is_searching = True
        else:
            is_searching = False

        # Pagination
        paginator, objects = paginate(request, objects, per_page=12)

        return render(request, "modeladminutils/chooser/results.html", {
            'objects': objects,
            'is_searching': is_searching,
            'query_string': q,
            'will_select_format': request.GET.get('select_format'),
            'app_label': app_label,
            'model_name': model_name,
            'model_verbose_name_plural': model._meta.verbose_name_plural,
        })
    else:
        searchform = SearchForm()

        paginator, objects = paginate(request, objects, per_page=12)

    return render_modal_workflow(
        request,
        'modeladminutils/chooser/chooser.html',
        'modeladminutils/chooser/chooser.js',
        {
            'objects': objects,
            'searchform': searchform,
            'is_searching': False,
            'query_string': q,
            'app_label': app_label,
            'model_name': model_name,
            'model_verbose_name': model._meta.verbose_name,
        }
    )
Esempio n. 14
0
def chooser(request):
    Media = get_media_model()

    media_files = []

    q = None
    is_searching = False
    if 'q' in request.GET or 'p' in request.GET or 'collection_id' in request.GET:
        media_files = Media.objects.all()

        collection_id = request.GET.get('collection_id')
        if collection_id:
            media_files = media_files.filter(collection=collection_id)

        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            q = searchform.cleaned_data['q']

            media_files = media_files.search(q)
            is_searching = True
        else:
            media_files = media_files.order_by('-created_at')
            is_searching = False

        # Pagination
        paginator, media_files = paginate(request, media_files, per_page=10)

        return render(request, "wagtailmedia/chooser/results.html", {
            'media_files': media_files,
            'query_string': q,
            'is_searching': is_searching,
        })
    else:
        searchform = SearchForm()

        collections = Collection.objects.all()
        if len(collections) < 2:
            collections = None

        media_files = Media.objects.order_by('-created_at')
        paginator, media_files = paginate(request, media_files, per_page=10)

    return render_modal_workflow(request, 'wagtailmedia/chooser/chooser.html', 'wagtailmedia/chooser/chooser.js', {
        'media_files': media_files,
        'searchform': searchform,
        'collections': collections,
        'is_searching': False,
    })
Esempio n. 15
0
def chooser(request,
            app_label=None,
            model_name=None,
            filter_name=None,
            signed_data=None):
    try:
        if signed_data is not None:
            # Load the data generated by the panel
            # This contains the id of the panel used to retrieve it
            data = signing.loads(signed_data)
            panel = registry.choosers[data['chooser_id']]
            panel = panel.bind_to_model(
                apps.get_model(data['app_label'], data['model_name']))
            instance = panel.get_instance(request, data)
            Form = panel.get_form_class()
            chooser = panel.bind_to_instance(instance=instance,
                                             form=Form(instance=instance),
                                             request=request)
            model = chooser.target_model
        else:
            model = apps.get_model(app_label, model_name)
            chooser = registry.choosers[model]
    except (LookupError, ValueError, KeyError, signing.BadSignature) as e:
        raise Http404

    qs = chooser.get_queryset(request)

    is_searchable = issubclass(model, Indexed)
    is_searching = is_searchable and request.GET.get('q')

    if is_searching:
        qs = qs.search(request.GET['q'])

    if filter_name is not None:
        try:
            filter_func = registry.filters[model, filter_name]
        except KeyError:
            raise Http404
        qs = filter_func(qs)

    paginator, page = paginate(request, qs, per_page=10)
    ajax = 'ajax' in request.GET

    context = {
        'chooser': chooser,
        'chooser_url': request.path,
        'opts': model._meta,
        'paginator': paginator,
        'page': page,
        'object_list': page.object_list,
        'is_searchable': is_searchable,
        'is_searching': is_searching,
    }

    if ajax:
        return render(request, chooser.results_template, context)

    js_data = {'step': 'initModal'}
    return render_modal_workflow(request, chooser.modal_template, None,
                                 context, js_data)
Esempio n. 16
0
def chooser_upload(request):
    VideoForm = get_video_form(Video)

    searchform = SearchForm()

    if request.POST:
        video = Video(uploaded_by_user=request.user)
        form = VideoForm(request.POST, request.FILES, instance=video)

        if form.is_valid():
            video.uploaded_by_user = request.user
            video.save()

            # Reindex the video to make sure all tags are indexed
            search_index.insert_or_update_object(video)

            return render_modal_workflow(
                request, None, 'wagtailvideos/chooser/video_chosen.js',
                {'video_json': get_video_json(video)}
            )
    else:
        form = VideoForm()

    videos = Video.objects.order_by('title')
    paginator, videos = paginate(request, videos, per_page=12)

    return render_modal_workflow(
        request, 'wagtailvideos/chooser/chooser.html', 'wagtailvideos/chooser/chooser.js',
        {'videos': videos, 'uploadform': form, 'searchform': searchform}
    )
Esempio n. 17
0
def chooser(request, get_results=False):
    # Get most popular queries
    queries = models.Query.get_most_popular()

    # If searching, filter results by query string
    query_string = None
    if 'q' in request.GET:
        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            query_string = searchform.cleaned_data['q']
            queries = queries.filter(query_string__icontains=normalise_query_string(query_string))
    else:
        searchform = SearchForm()

    paginator, queries = paginate(request, queries, per_page=10)

    # Render
    if get_results:
        return render(request, "wagtailsearch/queries/chooser/results.html", {
            'queries': queries,
        })
    else:
        return render_modal_workflow(
            request, 'wagtailsearch/queries/chooser/chooser.html', None, {
                'queries': queries,
                'searchform': searchform,
            }, json_data={'step': 'chooser'}
        )
Esempio n. 18
0
def index(request):
    submissions = Submission.objects.all()

    # Ordering
    if request.GET.get('ordering') in ['title', '-submitted_at']:
        ordering = request.GET['ordering']
    else:
        ordering = '-submitted_at'
    submissions = submissions.order_by(ordering)

    # Search
    query_string = None
    if 'q' in request.GET:
        form = SearchForm(request.GET, placeholder=_("Search submissions"))
        if form.is_valid():
            query_string = form.cleaned_data['q']
            submissions = submissions.search(query_string)
    else:
        form = SearchForm(placeholder=_("Search submissions"))

    # Pagination
    paginator, submissions = paginate(request, submissions)

    return render(request, 'submissions/admin/index.html', {
        'submissions': submissions,
        'ordering': ordering,
        'query_string': query_string,
        'is_searching': bool(query_string),
        'search_form': form,
    })
Esempio n. 19
0
def index(request):
    Report = get_report_model()

    # Get reports (filtered by user permission)
    reports = permission_policy.instances_user_has_any_permission_for(
        request.user, ['change', 'delete'])

    # Ordering
    if 'ordering' in request.GET and request.GET['ordering'] in [
            'title', '-created_at'
    ]:
        ordering = request.GET['ordering']
    else:
        ordering = '-created_at'
    reports = reports.order_by(ordering)

    # Search
    query_string = None
    if 'q' in request.GET:
        form = SearchForm(request.GET, placeholder=_("Search reports"))
        if form.is_valid():
            query_string = form.cleaned_data['q']
            reports = reports.search(query_string)
    else:
        form = SearchForm(placeholder=_("Search reports"))

    # Pagination
    paginator, reports = paginate(request, reports)

    # Create response
    if request.is_ajax():
        return render(
            request, 'wagtailreports/reports/results.html', {
                'ordering':
                ordering,
                'reports':
                reports,
                'query_string':
                query_string,
                'is_searching':
                bool(query_string),
                'user_can_add':
                permission_policy.user_has_permission(request.user, 'add'),
            })
    else:
        return render(
            request, 'wagtailreports/reports/index.html', {
                'ordering':
                ordering,
                'reports':
                reports,
                'query_string':
                query_string,
                'is_searching':
                bool(query_string),
                'search_form':
                form,
                'user_can_add':
                permission_policy.user_has_permission(request.user, 'add'),
            })
Esempio n. 20
0
def usage(request, document_id):
    Document = get_document_model()
    doc = get_object_or_404(Document, id=document_id)

    paginator, used_by = paginate(request, doc.get_usage())

    return render(request, "wagtaildocs/documents/usage.html", {"document": doc, "used_by": used_by})
Esempio n. 21
0
    def get(self, request):
        if len(request.GET) > 1:
            formset = PageBlockQueryFormSet(request.GET)
            if not formset.is_valid():
                return HttpResponseBadRequest("invalid query")

            queryset = formset.get_query()
        else:
            formset = PageBlockQueryFormSet()
            queryset = Page.objects.all()

        queryset = queryset.order_by("title")

        # https://docs.wagtail.io/en/latest/releases/2.5.html#changes-to-admin-pagination-helpers
        if wagtail.VERSION < (2, 5):
            from wagtail.utils.pagination import paginate

            paginator, pages = paginate(request, queryset)
        else:  # pragma: no cover
            from django.core.paginator import Paginator

            paginator = Paginator(queryset, per_page=20)
            pages = paginator.get_page(request.GET.get("p"))

        for page in pages:
            page.can_choose = True

        return render(request, self.template_name, {
            "formset": formset,
            "pages": pages
        })
Esempio n. 22
0
def chooser(request, get_results=False):
    # Get most popular queries
    queries = models.Query.get_most_popular()

    # If searching, filter results by query string
    query_string = None
    if "q" in request.GET:
        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            query_string = searchform.cleaned_data["q"]
            queries = queries.filter(query_string__icontains=normalise_query_string(query_string))
    else:
        searchform = SearchForm()

    paginator, queries = paginate(request, queries, per_page=10)

    # Render
    if get_results:
        return render(request, "wagtailsearch/queries/chooser/results.html", {"queries": queries})
    else:
        return render_modal_workflow(
            request,
            "wagtailsearch/queries/chooser/chooser.html",
            "wagtailsearch/queries/chooser/chooser.js",
            {"queries": queries, "searchform": searchform},
        )
Esempio n. 23
0
def search(request):
    pages = []
    q = None

    if "q" in request.GET:
        form = SearchForm(request.GET)
        if form.is_valid():
            q = form.cleaned_data["q"]

            pages = Page.objects.all().prefetch_related("content_type").search(q)
            paginator, pages = paginate(request, pages)
    else:
        form = SearchForm()

    if request.is_ajax():
        return render(
            request,
            "wagtailadmin/pages/search_results.html",
            {"pages": pages, "query_string": q, "pagination_query_params": ("q=%s" % q) if q else ""},
        )
    else:
        return render(
            request,
            "wagtailadmin/pages/search.html",
            {
                "search_form": form,
                "pages": pages,
                "query_string": q,
                "pagination_query_params": ("q=%s" % q) if q else "",
            },
        )
Esempio n. 24
0
def index(request):
    q = None
    is_searching = False

    model_fields = [f.name for f in User._meta.get_fields()]

    if 'q' in request.GET:
        form = SearchForm(request.GET, placeholder=_("Search users"))
        if form.is_valid():
            q = form.cleaned_data['q']
            is_searching = True
            conditions = Q()

            if 'username' in model_fields:
                conditions |= Q(username__icontains=q)

            if 'first_name' in model_fields:
                conditions |= Q(first_name__icontains=q)

            if 'last_name' in model_fields:
                conditions |= Q(last_name__icontains=q)

            if 'email' in model_fields:
                conditions |= Q(email__icontains=q)

            users = User.objects.filter(conditions)
    else:
        form = SearchForm(placeholder=_("Search users"))

    if not is_searching:
        users = User.objects.all()

    if 'last_name' in model_fields and 'first_name' in model_fields:
        users = users.order_by('last_name', 'first_name')

    if 'ordering' in request.GET:
        ordering = request.GET['ordering']

        if ordering == 'username':
            users = users.order_by(User.USERNAME_FIELD)
    else:
        ordering = 'name'

    paginator, users = paginate(request, users)

    if request.is_ajax():
        return render(request, "wagtailusers/users/results.html", {
            'users': users,
            'is_searching': is_searching,
            'query_string': q,
            'ordering': ordering,
        })
    else:
        return render(request, "wagtailusers/users/index.html", {
            'search_form': form,
            'users': users,
            'is_searching': is_searching,
            'ordering': ordering,
            'query_string': q,
        })
Esempio n. 25
0
def browse(request, parent_page_id=None):
    # Find parent page
    if parent_page_id:
        parent_page = get_object_or_404(Page, id=parent_page_id)
    else:
        parent_page = Page.get_first_root_node()

    # Get children of parent page
    pages = parent_page.get_children()

    # Filter them by page type
    # A missing or empty page_type parameter indicates 'all page types' (i.e. descendants of wagtailcore.page)
    page_type_string = request.GET.get('page_type') or 'wagtailcore.page'
    if page_type_string != 'wagtailcore.page':
        try:
            desired_classes = page_models_from_string(page_type_string)
        except (ValueError, LookupError):
            raise Http404

        # restrict the page listing to just those pages that:
        # - are of the given content type (taking into account class inheritance)
        # - or can be navigated into (i.e. have children)
        choosable_pages = filter_page_type(pages, desired_classes)
        descendable_pages = pages.filter(numchild__gt=0)
        pages = choosable_pages | descendable_pages
    else:
        desired_classes = (Page, )

    can_choose_root = request.GET.get('can_choose_root', False)

    # Parent page can be chosen if it is a instance of desired_classes
    parent_page.can_choose = issubclass(parent_page.specific_class or Page, desired_classes) and (can_choose_root or not parent_page.is_root())

    # Pagination
    # We apply pagination first so we don't need to walk the entire list
    # in the block below
    paginator, pages = paginate(request, pages, per_page=25)

    # Annotate each page with can_choose/can_decend flags
    for page in pages:
        if desired_classes == (Page, ):
            page.can_choose = True
        else:
            page.can_choose = issubclass(page.specific_class or Page, desired_classes)

        page.can_descend = page.get_children_count()

    # Render
    return render_modal_workflow(
        request,
        'wagtailadmin/chooser/browse.html', 'wagtailadmin/chooser/browse.js',
        shared_context(request, {
            'parent_page': parent_page,
            'pages': pages,
            'search_form': SearchForm(),
            'page_type_string': page_type_string,
            'page_type_names': [desired_class.get_verbose_name() for desired_class in desired_classes],
            'page_types_restricted': (page_type_string != 'wagtailcore.page')
        })
    )
Esempio n. 26
0
def search(request, parent_page_id=None):
    # A missing or empty page_type parameter indicates 'all page types' (i.e. descendants of wagtailcore.page)
    page_type_string = request.GET.get('page_type') or 'wagtailcore.page'

    try:
        desired_classes = page_models_from_string(page_type_string)
    except (ValueError, LookupError):
        raise Http404

    search_form = SearchForm(request.GET)
    if search_form.is_valid() and search_form.cleaned_data['q']:
        pages = Page.objects.exclude(
            depth=1  # never include root
        )
        pages = filter_page_type(pages, desired_classes)
        pages = pages.search(search_form.cleaned_data['q'], fields=['title'])
    else:
        pages = Page.objects.none()

    paginator, pages = paginate(request, pages, per_page=25)

    for page in pages:
        page.can_choose = True

    return render(
        request, 'wagtailadmin/chooser/_search_results.html',
        shared_context(request, {
            'searchform': search_form,
            'pages': pages,
            'page_type_string': page_type_string,
        })
    )
Esempio n. 27
0
def usage(request, app_label, model_name, id):
    model = get_snippet_model_from_url_params(app_label, model_name)
    instance = get_object_or_404(model, id=id)

    paginator, used_by = paginate(request, instance.get_usage())

    return render(request, "wagtailsnippets/snippets/usage.html", {"instance": instance, "used_by": used_by})
Esempio n. 28
0
    def get(self, request, *args, **kwargs):
        """
           Handle GET request
        """

        if request.user.is_superuser:
            journals = Journal.objects.all()
        else:
            journals = Journal.objects.filter(organization__site=request.site)
        # Ordering
        if 'ordering' in request.GET and request.GET['ordering'] in [
                'name', 'organization'
        ]:
            ordering = request.GET['ordering']
        else:
            ordering = 'name'
        journals = journals.order_by(ordering)

        # Pagination
        paginator, journals = paginate(request, journals)  # pylint: disable=unused-variable

        self.append_discovery_data(journals.object_list)

        action_url_name = self.url_helper.get_action_url_name('index')
        create_url_name = self.url_helper.get_action_url_name('create')

        return render(
            request, 'wagtailadmin/journal_index.html', {
                'view': self,
                'ordering': ordering,
                'journals': journals,
                'popular_tags': [],
                'action_url_name': action_url_name,
                'create_url_name': create_url_name
            })
Esempio n. 29
0
def search(request):
    pages = []
    q = None

    if 'q' in request.GET:
        form = SearchForm(request.GET)
        if form.is_valid():
            q = form.cleaned_data['q']

            pages = Page.objects.all().prefetch_related('content_type').search(q)
            paginator, pages = paginate(request, pages)
    else:
        form = SearchForm()

    if request.is_ajax():
        return render(request, "wagtailadmin/pages/search_results.html", {
            'pages': pages,
            'query_string': q,
            'pagination_query_params': ('q=%s' % q) if q else ''
        })
    else:
        return render(request, "wagtailadmin/pages/search.html", {
            'search_form': form,
            'pages': pages,
            'query_string': q,
            'pagination_query_params': ('q=%s' % q) if q else ''
        })
Esempio n. 30
0
def index(request):
    submissions = Submission.objects.all()

    # Ordering
    if request.GET.get('ordering') in ['title', '-submitted_at']:
        ordering = request.GET['ordering']
    else:
        ordering = '-submitted_at'
    submissions = submissions.order_by(ordering)

    # Search
    query_string = None
    if 'q' in request.GET:
        form = SearchForm(request.GET, placeholder=_("Search submissions"))
        if form.is_valid():
            query_string = form.cleaned_data['q']
            submissions = submissions.search(query_string)
    else:
        form = SearchForm(placeholder=_("Search submissions"))

    # Pagination
    paginator, submissions = paginate(request, submissions)

    return render(
        request, 'submissions/admin/index.html', {
            'submissions': submissions,
            'ordering': ordering,
            'query_string': query_string,
            'is_searching': bool(query_string),
            'search_form': form,
        })
Esempio n. 31
0
def search(request, parent_page_id=None):
    # A missing or empty page_type parameter indicates 'all page types' (i.e. descendants of wagtailcore.page)
    page_type_string = request.GET.get('page_type') or 'wagtailcore.page'

    try:
        desired_classes = page_models_from_string(page_type_string)
    except (ValueError, LookupError):
        raise Http404

    search_form = SearchForm(request.GET)
    if search_form.is_valid() and search_form.cleaned_data['q']:
        pages = Page.objects.exclude(
            depth=1  # never include root
        )
        pages = filter_page_type(pages, desired_classes)
        pages = pages.search(search_form.cleaned_data['q'], fields=['title'])
    else:
        pages = Page.objects.none()

    paginator, pages = paginate(request, pages, per_page=25)

    for page in pages:
        page.can_choose = True

    return render(
        request, 'wagtailadmin/chooser/_search_results.html',
        shared_context(request, {
            'searchform': search_form,
            'pages': pages,
            'page_type_string': page_type_string,
        })
    )
Esempio n. 32
0
def index(request, pk):
    newsindex = get_object_or_404(
        Page.objects.specific().type(NewsIndexMixin), pk=pk)
    NewsItem = newsindex.get_newsitem_model()

    if not user_can_edit_newsitem(request.user, NewsItem):
        raise PermissionDenied()

    newsitem_list = NewsItem.objects.filter(newsindex=newsindex)

    query = None
    try:
        query = request.GET['q']
    except KeyError:
        pass
    else:
        backend = get_search_backend()
        newsitem_list = backend.search(query, newsitem_list)

    paginator, page = paginate(request, newsitem_list)

    return render(request, 'wagtailnews/index.html', {
        'newsindex': newsindex,
        'page': page,
        'paginator': paginator,
        'newsitem_list': page.object_list,
        'newsitem_perms': perms_for_template(request, NewsItem),
        'query_string': query,
    })
Esempio n. 33
0
def index(request):
    is_searching = False
    query_string = request.GET.get('q', "")

    queries = Query.objects.filter(editors_picks__isnull=False).distinct()

    # Search
    if query_string:
        queries = queries.filter(query_string__icontains=query_string)
        is_searching = True

    paginator, queries = paginate(request, queries)

    if request.is_ajax():
        return render(request, "wagtailsearchpromotions/results.html", {
            'is_searching': is_searching,
            'queries': queries,
            'query_string': query_string,
        })
    else:
        return render(request, 'wagtailsearchpromotions/index.html', {
            'is_searching': is_searching,
            'queries': queries,
            'query_string': query_string,
            'search_form': SearchForm(
                data=dict(q=query_string) if query_string else None, placeholder=_("Search promoted results")
            ),
        })
Esempio n. 34
0
def index(request):
    query_string = request.GET.get('q', "")
    ordering = request.GET.get('ordering', 'old_path')

    redirects = models.Redirect.objects.prefetch_related('redirect_page', 'site')

    # Search
    if query_string:
        redirects = redirects.filter(old_path__icontains=query_string)

    # Ordering (A bit useless at the moment as only 'old_path' is allowed)
    if ordering not in ['old_path']:
        ordering = 'old_path'

    if ordering != 'old_path':
        redirects = redirects.order_by(ordering)

    # Pagination
    paginator, redirects = paginate(request, redirects)

    # Render template
    if request.is_ajax():
        return render(request, "wagtailredirects/results.html", {
            'ordering': ordering,
            'redirects': redirects,
            'query_string': query_string,
        })
    else:
        return render(request, "wagtailredirects/index.html", {
            'ordering': ordering,
            'redirects': redirects,
            'query_string': query_string,
            'search_form': SearchForm(data=dict(q=query_string) if query_string else None, placeholder=_("Search redirects")),
        })
Esempio n. 35
0
def index(request):
    q = None
    is_searching = False

    model_fields = [f.name for f in User._meta.get_fields()]

    if 'q' in request.GET:
        form = SearchForm(request.GET, placeholder=_("Search users"))
        if form.is_valid():
            q = form.cleaned_data['q']
            is_searching = True
            conditions = Q()

            if 'username' in model_fields:
                conditions |= Q(username__icontains=q)

            if 'first_name' in model_fields:
                conditions |= Q(first_name__icontains=q)

            if 'last_name' in model_fields:
                conditions |= Q(last_name__icontains=q)

            if 'email' in model_fields:
                conditions |= Q(email__icontains=q)

            users = User.objects.filter(conditions)
    else:
        form = SearchForm(placeholder=_("Search users"))

    if not is_searching:
        users = User.objects.all()

    if 'last_name' in model_fields and 'first_name' in model_fields:
        users = users.order_by('last_name', 'first_name')

    if 'ordering' in request.GET:
        ordering = request.GET['ordering']

        if ordering == 'username':
            users = users.order_by(User.USERNAME_FIELD)
    else:
        ordering = 'name'

    paginator, users = paginate(request, users)

    if request.is_ajax():
        return render(request, "wagtailusers/users/results.html", {
            'users': users,
            'is_searching': is_searching,
            'query_string': q,
            'ordering': ordering,
        })
    else:
        return render(request, "wagtailusers/users/index.html", {
            'search_form': form,
            'users': users,
            'is_searching': is_searching,
            'ordering': ordering,
            'query_string': q,
        })
Esempio n. 36
0
def chooser(request, get_results=False):
    # Get most popular queries
    queries = models.Query.get_most_popular()

    # If searching, filter results by query string
    query_string = None
    if 'q' in request.GET:
        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            query_string = searchform.cleaned_data['q']
            queries = queries.filter(query_string__icontains=normalise_query_string(query_string))
    else:
        searchform = SearchForm()

    paginator, queries = paginate(request, queries, per_page=10)

    # Render
    if get_results:
        return render(request, "wagtailsearch/queries/chooser/results.html", {
            'queries': queries,
        })
    else:
        return render_modal_workflow(
            request, 'wagtailsearch/queries/chooser/chooser.html', 'wagtailsearch/queries/chooser/chooser.js', {
                'queries': queries,
                'searchform': searchform,
            }
        )
Esempio n. 37
0
def chooser_upload(request):
    VideoForm = get_video_form(Video)

    searchform = SearchForm()

    if request.POST:
        video = Video(uploaded_by_user=request.user)
        form = VideoForm(request.POST, request.FILES, instance=video)

        if form.is_valid():
            video.uploaded_by_user = request.user
            video.save()

            # Reindex the video to make sure all tags are indexed
            search_index.insert_or_update_object(video)

            return render_modal_workflow(
                request, None, 'wagtailvideos/chooser/video_chosen.js',
                {'video_json': get_video_json(video)}
            )
    else:
        form = VideoForm()

    videos = Video.objects.order_by('title')
    paginator, videos = paginate(request, videos, per_page=12)

    return render_modal_workflow(
        request, 'wagtailvideos/chooser/chooser.html', 'wagtailvideos/chooser/chooser.js',
        {'videos': videos, 'uploadform': form, 'searchform': searchform}
    )
def move_choose_destination(request, page_to_move_id, viewed_page_id=None):
    page_to_move = get_object_or_404(Page, id=page_to_move_id)
    page_perms = page_to_move.permissions_for_user(request.user)
    if not page_perms.can_move():
        raise PermissionDenied

    if viewed_page_id:
        viewed_page = get_object_or_404(Page, id=viewed_page_id)
    else:
        viewed_page = Page.get_first_root_node()

    viewed_page.can_choose = page_perms.can_move_to(viewed_page)

    child_pages = []
    for target in viewed_page.get_children():
        # can't move the page into itself or its descendants
        target.can_choose = page_perms.can_move_to(target)

        target.can_descend = (
            not(target == page_to_move or
                target.is_child_of(page_to_move)) and
            target.get_children_count()
        )

        child_pages.append(target)

    # Pagination
    paginator, child_pages = paginate(request, child_pages, per_page=50)

    return render(request, 'wagtailadmin/pages/move_choose_destination.html', {
        'page_to_move': page_to_move,
        'viewed_page': viewed_page,
        'child_pages': child_pages,
    })
Esempio n. 39
0
def index(request, parent_page_id=None):
    if parent_page_id:
        parent_page = get_object_or_404(Page, id=parent_page_id)
    else:
        parent_page = Page.get_first_root_node()

    pages = parent_page.get_children().prefetch_related('content_type')

    # Get page ordering
    ordering = request.GET.get('ordering', '-latest_revision_created_at')
    if ordering not in ['title', '-title', 'content_type', '-content_type', 'live', '-live', 'latest_revision_created_at', '-latest_revision_created_at', 'ord']:
        ordering = '-latest_revision_created_at'

    # Pagination
    # Don't paginate if sorting by page order - all pages must be shown to
    # allow drag-and-drop reordering
    do_paginate = ordering != 'ord'
    if do_paginate:
        ordering_no_minus = ordering.lstrip('-')
        pages = pages.order_by(ordering).annotate(null_position=Count(ordering_no_minus)).order_by('-null_position', ordering)
        paginator, pages = paginate(request, pages, per_page=50)

    return render(request, 'wagtailadmin/pages/index.html', {
        'parent_page': parent_page,
        'ordering': ordering,
        'pagination_query_params': "ordering=%s" % ordering,
        'pages': pages,
        'do_paginate': do_paginate,
    })
Esempio n. 40
0
def index(request):
    is_searching = False
    query_string = request.GET.get('q', "")

    queries = Query.objects.filter(editors_picks__isnull=False).distinct()

    # Search
    if query_string:
        queries = queries.filter(query_string__icontains=query_string)
        is_searching = True

    paginator, queries = paginate(request, queries)

    if request.is_ajax():
        return render(
            request, "wagtailsearchpromotions/results.html", {
                'is_searching': is_searching,
                'queries': queries,
                'query_string': query_string,
            })
    else:
        return render(
            request, 'wagtailsearchpromotions/index.html', {
                'is_searching':
                is_searching,
                'queries':
                queries,
                'query_string':
                query_string,
                'search_form':
                SearchForm(data=dict(q=query_string) if query_string else None,
                           placeholder=_("Search promoted results")),
            })
Esempio n. 41
0
def search(request):
    pages = []
    q = None

    if 'q' in request.GET:
        form = SearchForm(request.GET)
        if form.is_valid():
            q = form.cleaned_data['q']

            pages = Page.objects.all().prefetch_related(
                'content_type').specific().search(q)
            paginator, pages = paginate(request, pages)
    else:
        form = SearchForm()

    if request.is_ajax():
        return render(
            request, "wagtailadmin/pages/search_results.html", {
                'pages': pages,
                'query_string': q,
                'pagination_query_params': ('q=%s' % q) if q else ''
            })
    else:
        return render(
            request, "wagtailadmin/pages/search.html", {
                'search_form': form,
                'pages': pages,
                'query_string': q,
                'pagination_query_params': ('q=%s' % q) if q else ''
            })
Esempio n. 42
0
def chooser(request):
    Document = get_document_model()

    if permission_policy.user_has_permission(request.user, 'add'):
        DocumentForm = get_document_form(Document)
        uploadform = DocumentForm()
    else:
        uploadform = None

    documents = []

    q = None
    is_searching = False
    if 'q' in request.GET or 'p' in request.GET:
        searchform = SearchForm(request.GET)
        if searchform.is_valid():
            q = searchform.cleaned_data['q']

            documents = Document.objects.search(q)
            is_searching = True
        else:
            documents = Document.objects.order_by('-created_at')
            is_searching = False

        # Pagination
        paginator, documents = paginate(request, documents, per_page=10)

        return render(
            request, "wagtaildocs/chooser/results.html", {
                'documents': documents,
                'query_string': q,
                'is_searching': is_searching,
            })
    else:
        searchform = SearchForm()

        documents = Document.objects.order_by('-created_at')
        paginator, documents = paginate(request, documents, per_page=10)

    return render_modal_workflow(
        request, 'wagtaildocs/chooser/chooser.html',
        'wagtaildocs/chooser/chooser.js', {
            'documents': documents,
            'uploadform': uploadform,
            'searchform': searchform,
            'is_searching': False,
        })
Esempio n. 43
0
def list(request, app_label, model_name):
    model = get_snippet_model_from_url_params(app_label, model_name)

    permissions = [
        get_permission_name(action, model)
        for action in ['add', 'change', 'delete']
    ]
    if not any([request.user.has_perm(perm) for perm in permissions]):
        return permission_denied(request)

    items = model.objects.all()

    # Search
    is_searchable = class_is_indexed(model)
    is_searching = False
    search_query = None
    if is_searchable and 'q' in request.GET:
        search_form = SearchForm(
            request.GET,
            placeholder=_("Search %(snippet_type_name)s") %
            {'snippet_type_name': model._meta.verbose_name_plural})

        if search_form.is_valid():
            search_query = search_form.cleaned_data['q']

            search_backend = get_search_backend()
            items = search_backend.search(search_query, items)
            is_searching = True

    else:
        search_form = SearchForm(
            placeholder=_("Search %(snippet_type_name)s") %
            {'snippet_type_name': model._meta.verbose_name_plural})

    paginator, paginated_items = paginate(request, items)

    # Template
    if request.is_ajax():
        template = 'wagtailsnippets/snippets/results.html'
    else:
        template = 'wagtailsnippets/snippets/type_index.html'

    return render(
        request, template, {
            'model_opts':
            model._meta,
            'items':
            paginated_items,
            'can_add_snippet':
            request.user.has_perm(get_permission_name('add', model)),
            'is_searchable':
            is_searchable,
            'search_form':
            search_form,
            'is_searching':
            is_searching,
            'query_string':
            search_query,
        })
Esempio n. 44
0
def index(request):
    survey_pages = get_surveys_for_user(request.user)

    paginator, survey_pages = paginate(request, survey_pages)

    return render(request, 'wagtailsurveys/index.html', {
        'survey_pages': survey_pages,
    })
Esempio n. 45
0
def index(request):
    survey_pages = get_surveys_for_user(request.user)

    paginator, survey_pages = paginate(request, survey_pages)

    return render(request, 'wagtailsurveys/index.html', {
        'survey_pages': survey_pages,
    })
Esempio n. 46
0
 def sessions(self, request):
     context = self.get_context(request)
     paginator, context['sessions'] = paginate(request, self.past_sessions, per_page=20)
     return TemplateResponse(
         request,
         'group/sessions.html',
         context
     )
Esempio n. 47
0
def index(request):
    form_pages = get_forms_for_user(request.user)

    paginator, form_pages = paginate(request, form_pages)

    return render(request, 'wagtailforms/index.html', {
        'form_pages': form_pages,
    })
Esempio n. 48
0
def index(request):
    form_pages = get_forms_for_user(request.user)

    paginator, form_pages = paginate(request, form_pages)

    return render(request, 'wagtailforms/index.html', {
        'form_pages': form_pages,
    })
Esempio n. 49
0
def index(request):
    Image = get_image_model()

    # Get images (filtered by user permission)
    images = permission_policy.instances_user_has_any_permission_for(
        request.user, ['change', 'delete']
    ).order_by('-created_at')

    # Search
    query_string = None
    if 'q' in request.GET:
        form = SearchForm(request.GET, placeholder=_("Search images"))
        if form.is_valid():
            query_string = form.cleaned_data['q']

            images = images.search(query_string)
    else:
        form = SearchForm(placeholder=_("Search images"))

    # Filter by collection
    current_collection = None
    collection_id = request.GET.get('collection_id')
    if collection_id:
        try:
            current_collection = Collection.objects.get(id=collection_id)
            images = images.filter(collection=current_collection)
        except (ValueError, Collection.DoesNotExist):
            pass

    paginator, images = paginate(request, images)

    collections = permission_policy.collections_user_has_any_permission_for(
        request.user, ['add', 'change']
    )
    if len(collections) < 2:
        collections = None
    else:
        collections = Collection.order_for_display(collections)

    # Create response
    if request.is_ajax():
        return render(request, 'wagtailimages/images/results.html', {
            'images': images,
            'query_string': query_string,
            'is_searching': bool(query_string),
        })
    else:
        return render(request, 'wagtailimages/images/index.html', {
            'images': images,
            'query_string': query_string,
            'is_searching': bool(query_string),

            'search_form': form,
            'popular_tags': popular_tags_for_model(Image),
            'collections': collections,
            'current_collection': current_collection,
            'user_can_add': permission_policy.user_has_permission(request.user, 'add'),
        })
Esempio n. 50
0
def usage(request, image_id):
    image = get_object_or_404(Video, id=image_id)

    paginator, used_by = paginate(request, image.get_usage())

    return render(request, "wagtailvideos/videos/usage.html", {
        'image': image,
        'used_by': used_by
    })
Esempio n. 51
0
def index(request):
    Image = get_image_model()

    # Get images (filtered by user permission)
    images = permission_policy.instances_user_has_any_permission_for(request.user, ["change", "delete"]).order_by(
        "-created_at"
    )

    # Search
    query_string = None
    if "q" in request.GET:
        form = SearchForm(request.GET, placeholder=_("Search images"))
        if form.is_valid():
            query_string = form.cleaned_data["q"]

            images = images.search(query_string)
    else:
        form = SearchForm(placeholder=_("Search images"))

    # Filter by collection
    current_collection = None
    collection_id = request.GET.get("collection_id")
    if collection_id:
        try:
            current_collection = Collection.objects.get(id=collection_id)
            images = images.filter(collection=current_collection)
        except (ValueError, Collection.DoesNotExist):
            pass

    paginator, images = paginate(request, images)

    collections = permission_policy.collections_user_has_any_permission_for(request.user, ["add", "change"])
    if len(collections) < 2:
        collections = None

    # Create response
    if request.is_ajax():
        return render(
            request,
            "wagtailimages/images/results.html",
            {"images": images, "query_string": query_string, "is_searching": bool(query_string)},
        )
    else:
        return render(
            request,
            "wagtailimages/images/index.html",
            {
                "images": images,
                "query_string": query_string,
                "is_searching": bool(query_string),
                "search_form": form,
                "popular_tags": Image.popular_tags(),
                "collections": collections,
                "current_collection": current_collection,
                "user_can_add": permission_policy.user_has_permission(request.user, "add"),
            },
        )
Esempio n. 52
0
def usage(request, document_id):
    doc = get_object_or_404(Document, id=document_id)

    paginator, used_by = paginate(request, doc.get_usage())

    return render(request, "wagtaildocs/documents/usage.html", {
        'document': doc,
        'used_by': used_by
    })
Esempio n. 53
0
def usage(request, document_id):
    doc = get_object_or_404(Document, id=document_id)

    paginator, used_by = paginate(request, doc.get_usage())

    return render(request, "wagtaildocs/documents/usage.html", {
        'document': doc,
        'used_by': used_by
    })
Esempio n. 54
0
def usage(request, image_id):
    image = get_object_or_404(get_image_model(), id=image_id)

    paginator, used_by = paginate(request, image.get_usage())

    return render(request, "wagtailimages/images/usage.html", {
        'image': image,
        'used_by': used_by
    })
Esempio n. 55
0
def usage(request, image_id):
    image = get_object_or_404(get_image_model(), id=image_id)

    paginator, used_by = paginate(request, image.get_usage())

    return render(request, "wagtailimages/images/usage.html", {
        'image': image,
        'used_by': used_by
    })
Esempio n. 56
0
def index(request):
    survey_pages = get_surveys_for_user(request.user)
    survey_pages = (survey_pages.descendant_of(
        request.site.root_page).specific())
    paginator, survey_pages = paginate(request, survey_pages)

    return render(request, 'wagtailsurveys/index.html', {
        'survey_pages': survey_pages,
    })