Exemplo n.º 1
0
 def get_columns(self):
     try:
         return self.columns
     except AttributeError:
         return [
             TitleColumn('name',
                         label=gettext_lazy("Name"),
                         accessor=str,
                         get_url=lambda obj: self.get_edit_url(obj)),
         ]
Exemplo n.º 2
0
 def columns(self):
     return [
         TitleColumn(
             "title",
             label=_("Title"),
             accessor=str,
             url_name=self.chosen_url_name,
             link_attrs={"data-chooser-modal-choice": True},
         ),
     ]
Exemplo n.º 3
0
    def test_title_column(self):
        root_page = Page.objects.filter(depth=2).first()
        blog = Site.objects.create(
            hostname="blog.example.com", site_name="My blog", root_page=root_page
        )
        gallery = Site.objects.create(
            hostname="gallery.example.com", site_name="My gallery", root_page=root_page
        )
        data = [blog, gallery]

        table = Table(
            [
                TitleColumn(
                    "hostname",
                    url_name="wagtailsites:edit",
                    link_classname="choose-site",
                ),
                Column("site_name", label="Site name"),
            ],
            data,
        )

        html = self.render_component(table)
        self.assertHTMLEqual(
            html,
            """
            <table class="listing">
                <thead>
                    <tr><th>Hostname</th><th>Site name</th></tr>
                </thead>
                <tbody>
                    <tr>
                        <td class="title">
                            <div class="title-wrapper">
                                <a href="/admin/sites/%d/" class="choose-site">blog.example.com</a>
                            </div>
                        </td>
                        <td>My blog</td>
                    </tr>
                    <tr>
                        <td class="title">
                            <div class="title-wrapper">
                                <a href="/admin/sites/%d/" class="choose-site">gallery.example.com</a>
                            </div>
                        </td>
                        <td>My gallery</td>
                    </tr>
                </tbody>
            </table>
        """
            % (blog.pk, gallery.pk),
        )
Exemplo n.º 4
0
class IndexView(generic.IndexView):
    page_title = _("Sites")
    add_item_label = _("Add a site")
    context_object_name = 'sites'
    default_ordering = 'hostname'
    columns = [
        TitleColumn('hostname',
                    label=_("Site"),
                    sort_key='hostname',
                    url_name='wagtailsites:edit'),
        Column('port', sort_key='port'),
        Column('site_name'),
        Column('root_page'),
        StatusFlagColumn('is_default_site',
                         label=_("Default?"),
                         true_label=_("Default")),
    ]
Exemplo n.º 5
0
class IndexView(generic.IndexView):
    page_title = _("Sites")
    add_item_label = _("Add a site")
    context_object_name = "sites"
    default_ordering = "hostname"
    columns = [
        TitleColumn(
            "hostname",
            label=_("Site"),
            sort_key="hostname",
            url_name="wagtailsites:edit",
        ),
        Column("port", sort_key="port"),
        Column("site_name"),
        Column("root_page"),
        StatusFlagColumn(
            "is_default_site", label=_("Default?"), true_label=_("Default")
        ),
    ]
Exemplo n.º 6
0
class IndexView(mixins.SearchableListMixin, generic.IndexView):
    page_title = _("Groups")
    add_item_label = _("Add a group")
    search_box_placeholder = _("Search groups")
    search_fields = ['name']
    context_object_name = 'groups'
    paginate_by = 20
    ordering = ['name']
    default_ordering = 'name'

    columns = [
        TitleColumn('name',
                    label=_("Name"),
                    sort_key='name',
                    url_name='wagtailusers_groups:edit'),
    ]

    def get_template_names(self):
        if self.request.headers.get('x-requested-with') == 'XMLHttpRequest':
            return ['wagtailusers/groups/results.html']
        else:
            return ['wagtailusers/groups/index.html']
Exemplo n.º 7
0
    def test_title_column(self):
        root_page = Page.objects.filter(depth=2).first()
        blog = Site.objects.create(hostname='blog.example.com', site_name='My blog', root_page=root_page)
        gallery = Site.objects.create(hostname='gallery.example.com', site_name='My gallery', root_page=root_page)
        data = [blog, gallery]

        table = Table([
            TitleColumn('hostname', url_name='wagtailsites:edit'),
            Column('site_name', label="Site name"),
        ], data)

        html = self.render_component(table)
        self.assertHTMLEqual(html, '''
            <table class="listing">
                <thead>
                    <tr><th>Hostname</th><th>Site name</th></tr>
                </thead>
                <tbody>
                    <tr>
                        <td class="title">
                            <div class="title-wrapper">
                                <a href="/admin/sites/%d/">blog.example.com</a>
                            </div>
                        </td>
                        <td>My blog</td>
                    </tr>
                    <tr>
                        <td class="title">
                            <div class="title-wrapper">
                                <a href="/admin/sites/%d/">gallery.example.com</a>
                            </div>
                        </td>
                        <td>My gallery</td>
                    </tr>
                </tbody>
            </table>
        ''' % (blog.pk, gallery.pk))
Exemplo n.º 8
0
class IndexView(mixins.SearchableListMixin, generic.IndexView):
    page_title = _("Groups")
    add_item_label = _("Add a group")
    search_box_placeholder = _("Search groups")
    search_fields = ["name"]
    context_object_name = "groups"
    paginate_by = 20
    ordering = ["name"]
    default_ordering = "name"

    columns = [
        TitleColumn(
            "name",
            label=_("Name"),
            sort_key="name",
            url_name="wagtailusers_groups:edit",
        ),
    ]

    def get_template_names(self):
        if self.request.headers.get("x-requested-with") == "XMLHttpRequest":
            return ["wagtailusers/groups/results.html"]
        else:
            return ["wagtailusers/groups/index.html"]
Exemplo n.º 9
0
    def get(self, request):
        Document = get_document_model()

        if permission_policy.user_has_permission(request.user, "add"):
            DocumentForm = get_document_form(Document)
            self.uploadform = DocumentForm(
                user=request.user, prefix="document-chooser-upload"
            )
        else:
            self.uploadform = None

        documents = permission_policy.instances_user_has_any_permission_for(
            request.user, ["choose"]
        )

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

        self.q = None
        self.is_searching = False

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

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

                documents = documents.search(self.q)
                self.is_searching = True
        else:
            self.searchform = SearchForm()

        if not self.is_searching:
            documents = documents.order_by("-created_at")

        paginator = Paginator(documents, per_page=10)
        self.documents = paginator.get_page(request.GET.get("p"))

        self.collections = permission_policy.collections_user_has_permission_for(
            request.user, "choose"
        )
        if len(self.collections) < 2:
            self.collections = None

        columns = [
            TitleColumn(
                "title",
                label=_("Title"),
                url_name="wagtaildocs:document_chosen",
                link_classname="document-choice",
            ),
            DownloadColumn("filename", label=_("File")),
            DateColumn("created_at", label=_("Created"), width="16%"),
        ]

        if self.collections:
            columns.insert(2, Column("collection", label=_("Collection")))

        self.table = Table(columns, self.documents)

        return self.render_to_response()