コード例 #1
0
    def test_construct_queryset_hook(self):
        page = SimplePage(title="Test shown", content="hello")
        Page.get_first_root_node().add_child(instance=page)

        page_not_shown = SimplePage(title="Test not shown", content="hello")
        Page.get_first_root_node().add_child(instance=page_not_shown)

        def filter_pages(pages, request):
            return pages.filter(id=page.id)

        with self.register_hook('construct_page_chooser_queryset', filter_pages):
            response = self.get()
        self.assertEqual(len(response.context['pages']), 1)
        self.assertEqual(response.context['pages'][0].specific, page)
コード例 #2
0
ファイル: models.py プロジェクト: schaermu/schaermu-ch
 def create_test(title, lead, parent=None):
     if (parent is None):
         parent = Page.get_first_root_node()
     home = HomePage(heading=title, title=title, lead=lead,
                     slug=text.slugify(title))
     parent.add_child(instance=home)
     return home
コード例 #3
0
ファイル: chooser.py プロジェクト: wizardlie/wagtail
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')
        })
    )
コード例 #4
0
ファイル: pages.py プロジェクト: robpal/wagtail
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
    if ordering != 'ord':
        ordering_no_minus = ordering
        if ordering_no_minus.startswith('-'):
            ordering_no_minus = ordering[1:]
        pages = pages.order_by(ordering).annotate(null_position=Count(ordering_no_minus)).order_by('-null_position', ordering)

        p = request.GET.get('p', 1)
        paginator = Paginator(pages, 50)
        try:
            pages = paginator.page(p)
        except PageNotAnInteger:
            pages = paginator.page(1)
        except EmptyPage:
            pages = paginator.page(paginator.num_pages)

    return render(request, 'wagtailadmin/pages/index.html', {
        'parent_page': parent_page,
        'ordering': ordering,
        'pages': pages,
    })
コード例 #5
0
ファイル: pages.py プロジェクト: jwheeler79/wagtail
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
    if 'ordering' in request.GET:
        ordering = request.GET['ordering']

        if ordering in [
                'title', '-title', 'content_type', '-content_type', 'live',
                '-live'
        ]:
            pages = pages.order_by(ordering)
    else:
        ordering = 'title'

    return render(request, 'wagtailadmin/pages/index.html', {
        'parent_page': parent_page,
        'ordering': ordering,
        'pages': pages,
    })
コード例 #6
0
ファイル: models.py プロジェクト: schaermu/schaermu-ch
 def create_test(title, intro, parent=None):
     if (parent is None):
         parent = Page.get_first_root_node()
     contact = ContactFormPage(title=title, intro=intro, thank_you_head='f',
                               thank_you_text='f', slug=text.slugify(title))
     parent.add_child(instance=contact)
     return contact
コード例 #7
0
ファイル: pages.py プロジェクト: romali/wagtail
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", "title")
    if ordering not in ["title", "-title", "content_type", "-content_type", "live", "-live", "ord"]:
        ordering = "title"

    # Pagination
    if ordering != "ord":
        pages = pages.order_by(ordering)

        p = request.GET.get("p", 1)
        paginator = Paginator(pages, 50)
        try:
            pages = paginator.page(p)
        except PageNotAnInteger:
            pages = paginator.page(1)
        except EmptyPage:
            pages = paginator.page(paginator.num_pages)

    return render(
        request, "wagtailadmin/pages/index.html", {"parent_page": parent_page, "ordering": ordering, "pages": pages}
    )
コード例 #8
0
ファイル: pages.py プロジェクト: willcodefortea/wagtail
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', 'title')
    if ordering not in ['title', '-title', 'content_type', '-content_type', 'live', '-live', 'ord']:
        ordering = 'title'

    # Pagination
    if ordering != 'ord':
        pages = pages.order_by(ordering)

        p = request.GET.get('p', 1)
        paginator = Paginator(pages, 50)
        try:
            pages = paginator.page(p)
        except PageNotAnInteger:
            pages = paginator.page(1)
        except EmptyPage:
            pages = paginator.page(paginator.num_pages)

    return render(request, 'wagtailadmin/pages/index.html', {
        'parent_page': parent_page,
        'ordering': ordering,
        'pages': pages,
    })
コード例 #9
0
ファイル: models.py プロジェクト: schaermu/schaermu-ch
 def create_test(title, intro, parent=None):
     if (parent is None):
         parent = Page.get_first_root_node()
     project_idx = ProjectIndexPage(title=title, intro=intro,
                                    slug=text.slugify(title))
     parent.add_child(instance=project_idx)
     return project_idx
コード例 #10
0
ファイル: pages.py プロジェクト: ghostRider1124/wagtail
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)

    return render(
        request, 'wagtailadmin/pages/move_choose_destination.html', {
            'page_to_move': page_to_move,
            'viewed_page': viewed_page,
            'child_pages': child_pages,
        })
コード例 #11
0
ファイル: pages.py プロジェクト: pjdelport/wagtail
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
    if ordering != 'ord':
        ordering_no_minus = ordering
        if ordering_no_minus.startswith('-'):
            ordering_no_minus = ordering[1:]
        pages = pages.order_by(ordering).annotate(null_position=Count(ordering_no_minus)).order_by('-null_position', ordering)

        p = request.GET.get('p', 1)
        paginator = Paginator(pages, 50)
        try:
            pages = paginator.page(p)
        except PageNotAnInteger:
            pages = paginator.page(1)
        except EmptyPage:
            pages = paginator.page(paginator.num_pages)

    return render(request, 'wagtailadmin/pages/index.html', {
        'parent_page': parent_page,
        'ordering': ordering,
        'pagination_query_params': "ordering=%s" % ordering,
        'pages': pages,
    })
コード例 #12
0
ファイル: pages.py プロジェクト: dRockolla/wagtail
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,
    })
コード例 #13
0
ファイル: pages.py プロジェクト: pjdelport/wagtail
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)

    return render(request, 'wagtailadmin/pages/move_choose_destination.html', {
        'page_to_move': page_to_move,
        'viewed_page': viewed_page,
        'child_pages': child_pages,
    })
コード例 #14
0
ファイル: chooser.py プロジェクト: 0b3r/wagtail
def browse(request, parent_page_id=None):
    page_type = request.GET.get('page_type') or 'wagtailcore.page'
    content_type_app_name, content_type_model_name = page_type.split('.')

    is_searching = False

    try:
        content_type = ContentType.objects.get_by_natural_key(content_type_app_name, content_type_model_name)
    except ContentType.DoesNotExist:
        raise Http404
    desired_class = content_type.model_class()

    if 'q' in request.GET:
        search_form = SearchForm(request.GET)
        if search_form.is_valid() and search_form.cleaned_data['q']:
            pages = desired_class.objects.exclude(
                depth=1  # never include root
            ).filter(title__icontains=search_form.cleaned_data['q'])[:10]
            is_searching = True

    if not is_searching:
        if parent_page_id:
            parent_page = get_object_or_404(Page, id=parent_page_id)
        else:
            parent_page = Page.get_first_root_node()

        parent_page.can_choose = issubclass(parent_page.specific_class, desired_class)
        search_form = SearchForm()
        pages = parent_page.get_children()

    # 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)

    shown_pages = []
    for page in pages:
        page.can_choose = issubclass(page.specific_class, desired_class)
        page.can_descend = page.get_children_count()

        if page.can_choose or page.can_descend:
            shown_pages.append(page)

    if is_searching:
        return render(request, 'wagtailadmin/chooser/_search_results.html', {
            'querystring': get_querystring(request),
            'searchform': search_form,
            'pages': pages,
            'is_searching': is_searching
        })

    return render_modal_workflow(request, 'wagtailadmin/chooser/browse.html', 'wagtailadmin/chooser/browse.js', {
        'allow_external_link': request.GET.get('allow_external_link'),
        'allow_email_link': request.GET.get('allow_email_link'),
        'querystring': get_querystring(request),
        'parent_page': parent_page,
        'pages': shown_pages,
        'search_form': search_form,
        'is_searching': False
    })
コード例 #15
0
 def create_test(title, intro, parent=None):
     if (parent is None):
         parent = Page.get_first_root_node()
     project_idx = ProjectIndexPage(title=title,
                                    intro=intro,
                                    slug=text.slugify(title))
     parent.add_child(instance=project_idx)
     return project_idx
コード例 #16
0
ファイル: pages.py プロジェクト: tvenkat/wagtail
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'

    if ordering == 'ord':
        # preserve the native ordering from get_children()
        pass
    elif ordering == 'latest_revision_created_at':
        # order by oldest revision first.
        # Special case NULL entries - these should go at the top of the list.
        # Do this by annotating with Count('latest_revision_created_at'),
        # which returns 0 for these
        pages = pages.annotate(
            null_position=Count('latest_revision_created_at')).order_by(
                'null_position', 'latest_revision_created_at')
    elif ordering == '-latest_revision_created_at':
        # order by oldest revision first.
        # Special case NULL entries - these should go at the end of the list.
        pages = pages.annotate(
            null_position=Count('latest_revision_created_at')).order_by(
                '-null_position', '-latest_revision_created_at')
    else:
        pages = pages.order_by(ordering)

    # Don't paginate if sorting by page order - all pages must be shown to
    # allow drag-and-drop reordering
    do_paginate = ordering != 'ord'

    # allow hooks to modify the queryset
    for hook in hooks.get_hooks('construct_explorer_page_queryset'):
        pages = hook(parent_page, pages, request)

    # Pagination
    if do_paginate:
        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,
        })
コード例 #17
0
ファイル: models.py プロジェクト: schaermu/schaermu-ch
 def create_test(title, lead, parent=None):
     if (parent is None):
         parent = Page.get_first_root_node()
     home = HomePage(heading=title,
                     title=title,
                     lead=lead,
                     slug=text.slugify(title))
     parent.add_child(instance=home)
     return home
コード例 #18
0
    def handle(self, *args, **options):

        if options['content_path']:
            content_path = options['content_path']
        elif settings.BOOTSTRAP_CONTENT_DIR:
            content_path = settings.BOOTSTRAP_CONTENT_DIR
        else:
            raise CommandError("Pass --content <content dir>, where <content dir>/pages contain .yml files")

        if options['owner']:
            owner_user = User.objects.get(username=options['owner'])
        else:
            owner_user = None
            #raise CommandError("Pass --owner <username>, where <username> will be the content owner")

        dry_run = options['dry']

        contents = load_content(os.path.join(content_path, 'pages'))

        for site in Site.objects.all():
            site.delete()

        for page in Page.objects.filter(id__gt=1):
            page.delete()

        root = Page.get_first_root_node()
        content_root = RootNode('/', page_properties={}, parent_page=root)
        for page_attrs in contents:
            new_node = SiteNode(full_path=page_attrs['path'], page_properties=page_attrs)
            content_root.add_node(new_node)

        page_property_defaults = get_page_defaults(content_path)
        relation_mappings = get_relation_mappings(content_path)

        content_root.instantiate_page(owner_user=owner_user,
                                      page_property_defaults=page_property_defaults,
                                      relation_mappings=relation_mappings,
                                      dry_run=dry_run)

        sites = []
        for site in get_sites(content_path):
            sites.append(Site.objects.create(hostname=site['hostname'],
                                             port=int(site['port']),
                                             root_page=page_for_path(site['root_page'])))

        default_site = sites[0]
        default_site.is_default_site = True
        default_site.save()

        if dry_run:
            self.stdout.write("Dry run, exiting without making changes")
            return

        content_root.instantiate_deferred_models(owner_user=owner_user,
                                                 page_property_defaults=page_property_defaults,
                                                 relation_mappings=relation_mappings,
                                                 dry_run=dry_run)
コード例 #19
0
ファイル: pages.py プロジェクト: wengole/wagtail
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'

    if ordering == 'ord':
        # preserve the native ordering from get_children()
        pass
    elif ordering == 'latest_revision_created_at':
        # order by oldest revision first.
        # Special case NULL entries - these should go at the top of the list.
        # Do this by annotating with Count('latest_revision_created_at'),
        # which returns 0 for these
        pages = pages.annotate(
            null_position=Count('latest_revision_created_at')
        ).order_by('null_position', 'latest_revision_created_at')
    elif ordering == '-latest_revision_created_at':
        # order by oldest revision first.
        # Special case NULL entries - these should go at the end of the list.
        pages = pages.annotate(
            null_position=Count('latest_revision_created_at')
        ).order_by('-null_position', '-latest_revision_created_at')
    else:
        pages = pages.order_by(ordering)

    # 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:
        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,
    })
コード例 #20
0
 def create_test(title, intro, parent=None):
     if (parent is None):
         parent = Page.get_first_root_node()
     contact = ContactFormPage(title=title,
                               intro=intro,
                               thank_you_head='f',
                               thank_you_text='f',
                               slug=text.slugify(title))
     parent.add_child(instance=contact)
     return contact
コード例 #21
0
    def setUp(self):
        self.site_2_page = SimplePage(
            title="Site 2 page",
            slug="site_2_page",
            content="Hello",
        )
        Page.get_first_root_node().add_child(instance=self.site_2_page)
        self.site_2_subpage = SimplePage(
            title="Site 2 subpage",
            slug="site_2_subpage",
            content="Hello again",
        )
        self.site_2_page.add_child(instance=self.site_2_subpage)

        self.site_2 = Site.objects.create(
            hostname='example.com',
            port=8080,
            root_page=Page.objects.get(pk=self.site_2_page.pk),
            is_default_site=False)
        self.about_us_page = SimplePage.objects.get(url_path='/home/about-us/')
コード例 #22
0
    def setUp(self):
        self.site_2_page = SimplePage(
            title="Site 2 page",
            slug="site_2_page",
            content="Hello",
        )
        Page.get_first_root_node().add_child(instance=self.site_2_page)
        self.site_2_subpage = SimplePage(
            title="Site 2 subpage",
            slug="site_2_subpage",
            content="Hello again",
        )
        self.site_2_page.add_child(instance=self.site_2_subpage)

        self.site_2 = Site.objects.create(
            hostname='example.com',
            port=8080,
            root_page=Page.objects.get(pk=self.site_2_page.pk),
            is_default_site=False
        )
        self.about_us_page = SimplePage.objects.get(url_path='/home/about-us/')
コード例 #23
0
ファイル: pages.py プロジェクト: CreativeOutbreak/wagtail
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
    if "ordering" in request.GET:
        ordering = request.GET["ordering"]

        if ordering in ["title", "-title", "content_type", "-content_type", "live", "-live"]:
            pages = pages.order_by(ordering)
    else:
        ordering = "title"

    return render(
        request, "wagtailadmin/pages/index.html", {"parent_page": parent_page, "ordering": ordering, "pages": pages}
    )
コード例 #24
0
ファイル: pages.py プロジェクト: uchicago-library/wagtail
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,
    })
コード例 #25
0
ファイル: pages.py プロジェクト: ErnieMac/wagtail
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
    if 'ordering' in request.GET:
        ordering = request.GET['ordering']

        if ordering in ['title', '-title', 'content_type', '-content_type', 'live', '-live']:
            pages = pages.order_by(ordering)
    else:
        ordering = 'title'

    return render(request, 'wagtailadmin/pages/index.html', {
        'parent_page': parent_page,
        'ordering': ordering,
        'pages': pages,
    })
コード例 #26
0
ファイル: test_page_queryset.py プロジェクト: chrxr/wagtail
 def test_all_pages_include_self_strict(self):
     self.assertEqual(
         Page.get_first_root_node(),
         Page.objects.first_common_ancestor(include_self=True, strict=True))
コード例 #27
0
def browse(request, parent_page_id=None):
    page_type = request.GET.get('page_type') or 'wagtailcore.page'
    content_type_app_name, content_type_model_name = page_type.split('.')

    is_searching = False

    try:
        content_type = ContentType.objects.get_by_natural_key(
            content_type_app_name, content_type_model_name)
    except ContentType.DoesNotExist:
        raise Http404
    desired_class = content_type.model_class()

    if 'q' in request.GET:
        search_form = SearchForm(request.GET)
        if search_form.is_valid() and search_form.cleaned_data['q']:
            pages = desired_class.objects.exclude(
                depth=1  # never include root
            ).filter(title__icontains=search_form.cleaned_data['q'])[:10]
            is_searching = True

    if not is_searching:
        if parent_page_id:
            parent_page = get_object_or_404(Page, id=parent_page_id)
        else:
            parent_page = Page.get_first_root_node()

        parent_page.can_choose = issubclass(parent_page.specific_class,
                                            desired_class)
        search_form = SearchForm()
        pages = parent_page.get_children()

    # 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)

    shown_pages = []
    for page in pages:
        page.can_choose = issubclass(page.specific_class, desired_class)
        page.can_descend = page.get_children_count()

        if page.can_choose or page.can_descend:
            shown_pages.append(page)

    if is_searching:
        return render(
            request, 'wagtailadmin/chooser/_search_results.html', {
                'querystring': get_querystring(request),
                'searchform': search_form,
                'pages': pages,
                'is_searching': is_searching
            })

    return render_modal_workflow(
        request, 'wagtailadmin/chooser/browse.html',
        'wagtailadmin/chooser/browse.js', {
            'allow_external_link': request.GET.get('allow_external_link'),
            'allow_email_link': request.GET.get('allow_email_link'),
            'querystring': get_querystring(request),
            'parent_page': parent_page,
            'pages': shown_pages,
            'search_form': search_form,
            'is_searching': False
        })
コード例 #28
0
ファイル: chooser.py プロジェクト: rudyondolan/wagtail
def browse(request, parent_page_id=None):
    ITEMS_PER_PAGE = 25

    page_type = request.GET.get('page_type') or 'wagtailcore.page'
    content_type_app_name, content_type_model_name = page_type.split('.')

    try:
        content_type = ContentType.objects.get_by_natural_key(content_type_app_name, content_type_model_name)
    except ContentType.DoesNotExist:
        raise Http404
    desired_class = content_type.model_class()

    if parent_page_id:
        parent_page = get_object_or_404(Page, id=parent_page_id)
    else:
        parent_page = Page.get_first_root_node()

    parent_page.can_choose = issubclass(parent_page.specific_class, desired_class)
    search_form = SearchForm()
    pages = parent_page.get_children()

    if desired_class == Page:
        # apply pagination first, since we know that the page listing won't
        # have to be filtered, and that saves us walking the entire list
        p = request.GET.get('p', 1)
        paginator = Paginator(pages, ITEMS_PER_PAGE)
        try:
            pages = paginator.page(p)
        except PageNotAnInteger:
            pages = paginator.page(1)
        except EmptyPage:
            pages = paginator.page(paginator.num_pages)

        for page in pages:
            page.can_choose = True
            page.can_descend = page.get_children_count()

    else:
        # 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)

        shown_pages = []
        for page in pages:
            page.can_choose = issubclass(page.specific_class or Page, desired_class)
            page.can_descend = page.get_children_count()

            if page.can_choose or page.can_descend:
                shown_pages.append(page)

        # Apply pagination
        p = request.GET.get('p', 1)
        paginator = Paginator(shown_pages, ITEMS_PER_PAGE)
        try:
            pages = paginator.page(p)
        except PageNotAnInteger:
            pages = paginator.page(1)
        except EmptyPage:
            pages = paginator.page(paginator.num_pages)

    return render_modal_workflow(request, 'wagtailadmin/chooser/browse.html', 'wagtailadmin/chooser/browse.js', {
        'allow_external_link': request.GET.get('allow_external_link'),
        'allow_email_link': request.GET.get('allow_email_link'),
        'querystring': get_querystring(request),
        'parent_page': parent_page,
        'pages': pages,
        'search_form': search_form,
        'page_type_string': page_type,
        'page_type_name': desired_class.get_verbose_name(),
        'page_types_restricted': (page_type != 'wagtailcore.page')
    })
コード例 #29
0
    def handle(self, *args, **options):

        if options['content_path']:
            content_path = options['content_path']
        elif settings.BOOTSTRAP_CONTENT_DIR:
            content_path = settings.BOOTSTRAP_CONTENT_DIR
        else:
            raise CommandError(
                "Pass --content <content dir>, where <content dir>/pages contain .yml files"
            )

        if options['owner']:
            owner_user = User.objects.get(username=options['owner'])
        else:
            owner_user = None
            #raise CommandError("Pass --owner <username>, where <username> will be the content owner")

        dry_run = options['dry']

        contents = load_content(os.path.join(content_path, 'pages'))

        for site in Site.objects.all():
            site.delete()

        for page in Page.objects.filter(id__gt=1):
            page.delete()

        root = Page.get_first_root_node()
        content_root = RootNode('/', page_properties={}, parent_page=root)
        for page_attrs in contents:
            new_node = SiteNode(full_path=page_attrs['path'],
                                page_properties=page_attrs)
            content_root.add_node(new_node)

        page_property_defaults = get_page_defaults(content_path)
        relation_mappings = get_relation_mappings(content_path)

        content_root.instantiate_page(
            owner_user=owner_user,
            page_property_defaults=page_property_defaults,
            relation_mappings=relation_mappings,
            dry_run=dry_run)

        sites = []
        for site in get_sites(content_path):
            sites.append(
                Site.objects.create(hostname=site['hostname'],
                                    port=int(site['port']),
                                    root_page=page_for_path(
                                        site['root_page'])))

        default_site = sites[0]
        default_site.is_default_site = True
        default_site.save()

        if dry_run:
            self.stdout.write("Dry run, exiting without making changes")
            return

        content_root.instantiate_deferred_models(
            owner_user=owner_user,
            page_property_defaults=page_property_defaults,
            relation_mappings=relation_mappings,
            dry_run=dry_run)
コード例 #30
0
 def get_root_page(self, request):
     return Page.get_first_root_node()
コード例 #31
0
def browse(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'
    user_perm = request.GET.get('user_perms', False)

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

    # Find parent page
    if parent_page_id:
        parent_page = get_object_or_404(Page, id=parent_page_id)
    elif desired_classes == (Page,):
        # Just use the root page
        parent_page = Page.get_first_root_node()
    else:
        # Find the highest common ancestor for the specific classes passed in
        # In many cases, such as selecting an EventPage under an EventIndex,
        # this will help the administrator find their page quicker.
        all_desired_pages = filter_page_type(Page.objects.all(), desired_classes)
        parent_page = all_desired_pages.first_common_ancestor()

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

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

    # Filter them by page type
    if desired_classes != (Page,):
        # 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

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

    # Do permission lookups for this user now, instead of for every page.
    permission_proxy = UserPagePermissionsProxy(request.user)

    # Parent page can be chosen if it is a instance of desired_classes
    parent_page.can_choose = can_choose_page(
        parent_page, permission_proxy, desired_classes, can_choose_root, user_perm)

    # 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:
        page.can_choose = can_choose_page(page, permission_proxy, desired_classes, can_choose_root, user_perm)
        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,
            'parent_page_id': parent_page.pk,
            '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')
        })
    )
コード例 #32
0
ファイル: test_page_queryset.py プロジェクト: chrxr/wagtail
 def test_empty_queryset(self):
     self.assertEqual(
         Page.get_first_root_node(),
         Page.objects.none().first_common_ancestor())
コード例 #33
0
ファイル: chooser.py プロジェクト: javierhdez3/wagtail
def browse(request, parent_page_id=None):
    ITEMS_PER_PAGE = 25

    page_types = request.GET.get('page_types', 'wagtailcore.page').split(',')

    desired_classes = []
    for page_type in page_types:
        try:
            content_type = resolve_model_string(page_type)
        except LookupError:
            raise Http404

        desired_classes.append(content_type)

    if parent_page_id:
        parent_page = get_object_or_404(Page, id=parent_page_id)
    else:
        parent_page = Page.get_first_root_node()

    parent_page.can_choose = issubclass(parent_page.specific_class, tuple(desired_classes))
    search_form = SearchForm()
    pages = parent_page.get_children()

    if desired_classes == [Page]:
        # apply pagination first, since we know that the page listing won't
        # have to be filtered, and that saves us walking the entire list
        p = request.GET.get('p', 1)
        paginator = Paginator(pages, ITEMS_PER_PAGE)
        try:
            pages = paginator.page(p)
        except PageNotAnInteger:
            pages = paginator.page(1)
        except EmptyPage:
            pages = paginator.page(paginator.num_pages)

        for page in pages:
            page.can_choose = True
            page.can_descend = page.get_children_count()

    else:
        # 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)

        shown_pages = []
        for page in pages:
            page.can_choose = issubclass(page.specific_class or Page, tuple(desired_classes))
            page.can_descend = page.get_children_count()

            if page.can_choose or page.can_descend:
                shown_pages.append(page)

        # Apply pagination
        p = request.GET.get('p', 1)
        paginator = Paginator(shown_pages, ITEMS_PER_PAGE)
        try:
            pages = paginator.page(p)
        except PageNotAnInteger:
            pages = paginator.page(1)
        except EmptyPage:
            pages = paginator.page(paginator.num_pages)

    return render_modal_workflow(
        request,
        'wagtailadmin/chooser/browse.html', 'wagtailadmin/chooser/browse.js',
        shared_context(request, {
            'parent_page': parent_page,
            'pages': pages,
            'search_form': search_form,
            'page_type_string': ','.join(page_types),
            'page_type_names': [desired_class.get_verbose_name() for desired_class in desired_classes],
            'page_types_restricted': (page_type != 'wagtailcore.page')
        })
    )
コード例 #34
0
ファイル: pages.py プロジェクト: barschool/wagtail
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'

    if ordering == 'ord':
        # preserve the native ordering from get_children()
        pass
    elif ordering == 'latest_revision_created_at':
        # order by oldest revision first.
        # Special case NULL entries - these should go at the top of the list.
        # Do this by annotating with Count('latest_revision_created_at'),
        # which returns 0 for these
        pages = pages.annotate(
            null_position=Count('latest_revision_created_at')
        ).order_by('null_position', 'latest_revision_created_at')
    elif ordering == '-latest_revision_created_at':
        # order by oldest revision first.
        # Special case NULL entries - these should go at the end of the list.
        pages = pages.annotate(
            null_position=Count('latest_revision_created_at')
        ).order_by('-null_position', '-latest_revision_created_at')
    else:
        pages = pages.order_by(ordering)

    # 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:
        # Retrieve pages in their most specific form.
        # Only do this for paginated listings, as this could potentially be a
        # very expensive operation when performed on a large queryset.
        pages = pages.specific()

    # allow hooks to modify the queryset
    for hook in hooks.get_hooks('construct_explorer_page_queryset'):
        pages = hook(parent_page, pages, request)

    # Pagination
    if do_paginate:
        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,
    })
コード例 #35
0
 def test_empty_queryset(self):
     self.assertEqual(Page.get_first_root_node(),
                      Page.objects.none().first_common_ancestor())
コード例 #36
0
 def test_all_pages_include_self_strict(self):
     self.assertEqual(
         Page.get_first_root_node(),
         Page.objects.first_common_ancestor(include_self=True, strict=True))
コード例 #37
0
ファイル: test_page_queryset.py プロジェクト: chrxr/wagtail
 def test_all_pages(self):
     self.assertEqual(
         Page.get_first_root_node(),
         Page.objects.first_common_ancestor())
コード例 #38
0
ファイル: chooser.py プロジェクト: thenewguy/wagtail
def browse(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

    # Find parent page
    if parent_page_id:
        parent_page = get_object_or_404(Page, id=parent_page_id)
    elif desired_classes == (Page,):
        # Just use the root page
        parent_page = Page.get_first_root_node()
    else:
        # Find the highest common ancestor for the specific classes passed in
        # In many cases, such as selecting an EventPage under an EventIndex,
        # this will help the administrator find their page quicker.
        all_desired_pages = filter_page_type(Page.objects.all(), desired_classes)
        parent_page = all_desired_pages.first_common_ancestor()

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

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

    # Filter them by page type
    if desired_classes != (Page,):
        # 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

    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,
            'parent_page_id': parent_page.pk,
            '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')
        })
    )
コード例 #39
0
def browse(request, parent_page_id=None):
    ITEMS_PER_PAGE = 25

    page_type = request.GET.get('page_type') or 'wagtailcore.page'
    content_type_app_name, content_type_model_name = page_type.split('.')

    try:
        content_type = ContentType.objects.get_by_natural_key(
            content_type_app_name, content_type_model_name)
    except ContentType.DoesNotExist:
        raise Http404
    desired_class = content_type.model_class()

    if parent_page_id:
        parent_page = get_object_or_404(Page, id=parent_page_id)
    else:
        parent_page = Page.get_first_root_node()

    parent_page.can_choose = issubclass(parent_page.specific_class,
                                        desired_class)
    search_form = SearchForm()
    pages = parent_page.get_children()

    if desired_class == Page:
        # apply pagination first, since we know that the page listing won't
        # have to be filtered, and that saves us walking the entire list
        p = request.GET.get('p', 1)
        paginator = Paginator(pages, ITEMS_PER_PAGE)
        try:
            pages = paginator.page(p)
        except PageNotAnInteger:
            pages = paginator.page(1)
        except EmptyPage:
            pages = paginator.page(paginator.num_pages)

        for page in pages:
            page.can_choose = True
            page.can_descend = page.get_children_count()

    else:
        # 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)

        shown_pages = []
        for page in pages:
            page.can_choose = issubclass(page.specific_class or Page,
                                         desired_class)
            page.can_descend = page.get_children_count()

            if page.can_choose or page.can_descend:
                shown_pages.append(page)

        # Apply pagination
        p = request.GET.get('p', 1)
        paginator = Paginator(shown_pages, ITEMS_PER_PAGE)
        try:
            pages = paginator.page(p)
        except PageNotAnInteger:
            pages = paginator.page(1)
        except EmptyPage:
            pages = paginator.page(paginator.num_pages)

    return render_modal_workflow(
        request, 'wagtailadmin/chooser/browse.html',
        'wagtailadmin/chooser/browse.js',
        shared_context(
            request, {
                'parent_page': parent_page,
                'pages': pages,
                'search_form': search_form,
                'page_type_string': page_type,
                'page_type_name': desired_class.get_verbose_name(),
                'page_types_restricted': (page_type != 'wagtailcore.page')
            }))
コード例 #40
0
ファイル: pages.py プロジェクト: mvantellingen/wagtail
def index(request, parent_page_id=None):
    if parent_page_id:
        parent_page = get_object_or_404(Page, id=parent_page_id).specific
    else:
        parent_page = Page.get_first_root_node().specific

    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"

    if ordering == "ord":
        # preserve the native ordering from get_children()
        pass
    elif ordering == "latest_revision_created_at":
        # order by oldest revision first.
        # Special case NULL entries - these should go at the top of the list.
        # Do this by annotating with Count('latest_revision_created_at'),
        # which returns 0 for these
        pages = pages.annotate(null_position=Count("latest_revision_created_at")).order_by(
            "null_position", "latest_revision_created_at"
        )
    elif ordering == "-latest_revision_created_at":
        # order by oldest revision first.
        # Special case NULL entries - these should go at the end of the list.
        pages = pages.annotate(null_position=Count("latest_revision_created_at")).order_by(
            "-null_position", "-latest_revision_created_at"
        )
    else:
        pages = pages.order_by(ordering)

    # 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:
        # Retrieve pages in their most specific form.
        # Only do this for paginated listings, as this could potentially be a
        # very expensive operation when performed on a large queryset.
        pages = pages.specific()

    # allow hooks to modify the queryset
    for hook in hooks.get_hooks("construct_explorer_page_queryset"):
        pages = hook(parent_page, pages, request)

    # Pagination
    if do_paginate:
        paginator, pages = paginate(request, pages, per_page=50)

    return render(
        request,
        "wagtailadmin/pages/index.html",
        {
            "parent_page": parent_page.specific,
            "ordering": ordering,
            "pagination_query_params": "ordering=%s" % ordering,
            "pages": pages,
            "do_paginate": do_paginate,
        },
    )
コード例 #41
0
ファイル: filters.py プロジェクト: DimiC/wagtail
 def get_root_page(self, request):
     return Page.get_first_root_node()
コード例 #42
0
 def test_all_pages(self):
     self.assertEqual(Page.get_first_root_node(),
                      Page.objects.first_common_ancestor())