-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add admin-link to block for BlockAdapter
- Loading branch information
Showing
15 changed files
with
189 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from django.core.management.base import BaseCommand, CommandError | ||
from django.core.management.color import color_style, supports_color | ||
from wagtail_fedit.adapters import adapter_registry | ||
from wagtail_fedit.utils import TEMPLATE_TAG_NAME | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Print an example of how to use all registered adapters." | ||
|
||
def handle(self, *args, **options): | ||
s = [ | ||
"Registered Adapters:", | ||
] | ||
|
||
for identifier, adapter_class in adapter_registry.adapters.items(): | ||
s.append( | ||
f"\t{{% {TEMPLATE_TAG_NAME} {identifier} instance.modelfield {adapter_class.usage_string()} %}}", | ||
) | ||
|
||
if supports_color(): | ||
style = color_style() | ||
s = style.SUCCESS("\n".join(s)) | ||
else: | ||
s = "\n".join(s) | ||
self.stdout.write(s) | ||
self.stdout.write("\n") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.conf import settings | ||
|
||
|
||
|
||
SIGN_SHARED_CONTEXT = getattr(settings, "WAGTAIL_FEDIT_SIGN_SHARED_CONTEXT", True) | ||
""" | ||
Sign the shared context with a secret key. | ||
This is useful to prevent tampering with the shared context. | ||
It will also be compressed with zlib if available. | ||
It might not be in your site's security model to need this. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
wagtail_fedit/templates/wagtail_fedit/content/buttons/admin_link.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{% load i18n %} | ||
<a href="{{ admin_url }}" target="_blank" class="wagtail-fedit-adapter-admin-link wagtail-fedit-toolbar-button wagtail-fedit-link-button"> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-box-arrow-up-right" viewBox="0 0 16 16" aria-label="{% translate "View in Wagtail admin" %}"> | ||
<!-- The MIT License (MIT) --> | ||
<!-- Copyright (c) 2011-2024 The Bootstrap Authors --> | ||
<path fill-rule="evenodd" d="M8.636 3.5a.5.5 0 0 0-.5-.5H1.5A1.5 1.5 0 0 0 0 4.5v10A1.5 1.5 0 0 0 1.5 16h10a1.5 1.5 0 0 0 1.5-1.5V7.864a.5.5 0 0 0-1 0V14.5a.5.5 0 0 1-.5.5h-10a.5.5 0 0 1-.5-.5v-10a.5.5 0 0 1 .5-.5h6.636a.5.5 0 0 0 .5-.5"/> | ||
<path fill-rule="evenodd" d="M16 .5a.5.5 0 0 0-.5-.5h-5a.5.5 0 0 0 0 1h3.793L6.146 9.146a.5.5 0 1 0 .708.708L15 1.707V5.5a.5.5 0 0 0 1 0z"/> | ||
</svg> | ||
</a> |
4 changes: 2 additions & 2 deletions
4
wagtail_fedit/templates/wagtail_fedit/content/buttons/edit_adapter.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
wagtail_fedit/templates/wagtail_fedit/content/buttons/edit_block.html
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
wagtail_fedit/templates/wagtail_fedit/content/buttons/edit_field.html
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,68 @@ | ||
from django.template.loader import render_to_string | ||
from django.utils.safestring import mark_safe | ||
from typing import TYPE_CHECKING | ||
|
||
if TYPE_CHECKING: | ||
from .adapters import BaseAdapter | ||
|
||
class FeditToolbarComponent: | ||
template_name = None | ||
permissions: list[str] = [] | ||
|
||
def __init__(self): | ||
pass | ||
def __init__(self, request): | ||
self.request = request | ||
|
||
def get_context_data(self, request): | ||
def get_context_data(self): | ||
return { | ||
"self": self, | ||
"request": request, | ||
"request": self.request, | ||
} | ||
|
||
def is_shown(self, request): | ||
if not all([request, request.user.is_authenticated]): | ||
def is_shown(self): | ||
if not all([self.request, self.request.user.is_authenticated]): | ||
return False | ||
|
||
if not self.permissions: | ||
return True | ||
|
||
return request.user.has_perms(self.permissions) | ||
return self.request.user.has_perms(self.permissions) | ||
|
||
def render(self, request): | ||
if not self.is_shown(request): | ||
def render(self): | ||
if not self.is_shown(): | ||
return "" | ||
|
||
return mark_safe(render_to_string( | ||
self.template_name, | ||
self.get_context_data(request), | ||
self.get_context_data(), | ||
)) | ||
|
||
|
||
class FeditBlockEditButton(FeditToolbarComponent): | ||
class FeditAdapterComponent(FeditToolbarComponent): | ||
def __init__(self, request, adapter: "BaseAdapter"): | ||
super().__init__(request) | ||
self.adapter = adapter | ||
|
||
class FeditAdapterEditButton(FeditAdapterComponent): | ||
""" | ||
Required button class for the edit modal to function. | ||
This button is handled by the script in `wagtail_fedit/js/frontend.js` | ||
""" | ||
template_name = "wagtail_fedit/content/buttons/edit_block.html" | ||
template_name = "wagtail_fedit/content/buttons/edit_adapter.html" | ||
permissions = [ | ||
"wagtailadmin.access_admin", | ||
] | ||
|
||
|
||
class FeditFieldEditButton(FeditToolbarComponent): | ||
class FeditAdapterAdminLinkButton(FeditAdapterComponent): | ||
""" | ||
Required button class for the edit modal to function. | ||
This button is handled by the script in `wagtail_fedit/js/frontend.js` | ||
""" | ||
template_name = "wagtail_fedit/content/buttons/edit_field.html" | ||
template_name = "wagtail_fedit/content/buttons/admin_link.html" | ||
permissions = [ | ||
"wagtailadmin.access_admin", | ||
] | ||
|
||
class FeditAdapterEditButton(FeditToolbarComponent): | ||
""" | ||
Required button class for the edit modal to function. | ||
This button is handled by the script in `wagtail_fedit/js/frontend.js` | ||
""" | ||
template_name = "wagtail_fedit/content/buttons/edit_adapter.html" | ||
permissions = [ | ||
"wagtailadmin.access_admin", | ||
] | ||
def get_context_data(self): | ||
return super().get_context_data() | { | ||
"admin_url": self.adapter.get_admin_url(), | ||
} |
Oops, something went wrong.