コード例 #1
0
ファイル: audit_logging.py プロジェクト: jams2/wagtail
    def decorate_paginated_queryset(self, queryset):
        # build lists of ids from queryset, grouped by log model index
        pks_by_log_model_index = defaultdict(list)
        for row in queryset:
            pks_by_log_model_index[row["log_model_index"]].append(row["pk"])

        url_finder = AdminURLFinder(self.request.user)

        # for each log model found in the queryset, look up the set of log entries by id
        # and build a lookup table
        object_lookup = {}
        for log_model_index, pks in pks_by_log_model_index.items():
            log_entries = (
                self.log_models[log_model_index]
                .objects.prefetch_related("user__wagtail_userprofile", "content_type")
                .filter(pk__in=pks)
                .with_instances()
            )
            for log_entry, instance in log_entries:
                # annotate log entry with an 'edit_url' property
                log_entry.edit_url = url_finder.get_edit_url(instance)
                object_lookup[(log_model_index, log_entry.pk)] = log_entry

        # return items from our lookup table in the order of the original queryset
        return [object_lookup[(row["log_model_index"], row["pk"])] for row in queryset]
コード例 #2
0
    def test_simple(self):
        response = self.get()
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, "wagtailredirects/edit.html")

        url_finder = AdminURLFinder(self.user)
        expected_url = "/admin/redirects/%d/" % self.redirect.id
        self.assertEqual(url_finder.get_edit_url(self.redirect), expected_url)
コード例 #3
0
ファイル: tests.py プロジェクト: tomusher/wagtail
    def test_simple(self):
        response = self.get()
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'wagtailsites/edit.html')

        url_finder = AdminURLFinder(self.user)
        expected_url = '/admin/sites/%d/' % self.localhost.id
        self.assertEqual(url_finder.get_edit_url(self.localhost), expected_url)
コード例 #4
0
    def test_simple(self):
        response = self.client.get(
            reverse("wagtailsearchpromotions:edit", args=(self.query.id, )))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, "wagtailsearchpromotions/edit.html")

        url_finder = AdminURLFinder(self.user)
        expected_url = "/admin/searchpicks/%d/" % self.query.id
        self.assertEqual(url_finder.get_edit_url(self.search_pick),
                         expected_url)
コード例 #5
0
    def test_edit(self):
        response = self.post(post_data={
            "title": "Edited setting title",
            "email": "*****@*****.**",
        })
        self.assertEqual(response.status_code, 302)

        setting = TestGenericSetting.objects.first()
        self.assertEqual(setting.title, "Edited setting title")

        url_finder = AdminURLFinder(self.user)
        expected_url = "/admin/settings/tests/testgenericsetting/%d/" % setting.pk
        self.assertEqual(url_finder.get_edit_url(setting), expected_url)
コード例 #6
0
    def test_edit(self):
        response = self.post(
            post_data={"title": "Edited site title", "email": "*****@*****.**"}
        )
        self.assertEqual(response.status_code, 302)

        default_site = Site.objects.get(is_default_site=True)
        setting = TestSiteSetting.objects.get(site=default_site)
        self.assertEqual(setting.title, "Edited site title")
        self.assertEqual(setting.email, "*****@*****.**")

        url_finder = AdminURLFinder(self.user)
        expected_url = "/admin/settings/tests/testsitesetting/%d/" % default_site.pk
        self.assertEqual(url_finder.get_edit_url(setting), expected_url)
コード例 #7
0
ファイル: test_admin.py プロジェクト: tbrlpld/wagtail
    def test_edit(self):
        response = self.post(post_data={
            'title': 'Edited site title',
            'email': '*****@*****.**'
        })
        self.assertEqual(response.status_code, 302)

        default_site = Site.objects.get(is_default_site=True)
        setting = TestSetting.objects.get(site=default_site)
        self.assertEqual(setting.title, 'Edited site title')
        self.assertEqual(setting.email, '*****@*****.**')

        url_finder = AdminURLFinder(self.user)
        expected_url = '/admin/settings/tests/testsetting/%d/' % default_site.pk
        self.assertEqual(url_finder.get_edit_url(setting), expected_url)
コード例 #8
0
    def test_simple(self):
        response = self.get()
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'wagtaillocales/edit.html')

        self.assertEqual(
            response.context['form'].fields['language_code'].choices,
            [
                ('en', 'English'
                 ),  # Note: Current value is displayed even though it's in use
                ('fr', 'French')
            ])

        url_finder = AdminURLFinder(self.user)
        expected_url = '/admin/locales/%d/' % self.english.id
        self.assertEqual(url_finder.get_edit_url(self.english), expected_url)
コード例 #9
0
    def test_simple(self):
        response = self.get(1)

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "The Lord of the Rings")

        # "Last updated" timestamp should be present
        self.assertContains(
            response, 'data-wagtail-tooltip="Sept. 30, 2021, 10:01 a.m."'
        )
        # History link should be present
        self.assertContains(response, 'href="/admin/modeladmintest/book/history/1/"')

        url_finder = AdminURLFinder(self.user)
        expected_url = "/admin/modeladmintest/book/edit/1/"
        self.assertEqual(url_finder.get_edit_url(Book.objects.get(id=1)), expected_url)
コード例 #10
0
ファイル: tests.py プロジェクト: tnir/wagtail
    def test_simple(self):
        response = self.get()
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, "wagtaillocales/edit.html")

        self.assertEqual(
            response.context["form"].fields["language_code"].choices,
            [
                (
                    "en",
                    "English",
                ),  # Note: Current value is displayed even though it's in use
                ("fr", "French"),
            ],
        )

        url_finder = AdminURLFinder(self.user)
        expected_url = "/admin/locales/%d/" % self.english.id
        self.assertEqual(url_finder.get_edit_url(self.english), expected_url)
コード例 #11
0
    def test_edit_permitted(self):
        response = self.client.get("/admin/modeladmintest/book/edit/2/")
        self.assertRedirects(response, "/admin/")

        url_finder = AdminURLFinder(self.user)
        self.assertIsNone(url_finder.get_edit_url(Book.objects.get(id=2)))
コード例 #12
0
 def test_admin_url_finder(self):
     expected_url = "/admin/collections/%d/" % self.l2.pk
     url_finder = AdminURLFinder(self.user)
     self.assertEqual(url_finder.get_edit_url(self.l2), expected_url)
コード例 #13
0
    def test_edit_permitted(self):
        response = self.client.get('/admin/modeladmintest/book/edit/2/')
        self.assertRedirects(response, '/admin/')

        url_finder = AdminURLFinder(self.user)
        self.assertEqual(url_finder.get_edit_url(Book.objects.get(id=2)), None)