Skip to content

Commit

Permalink
Add "Instances of ..." menu entry to blog menu
Browse files Browse the repository at this point in the history
  • Loading branch information
fsbraun committed Jan 9, 2024
1 parent 72b968f commit 1252bf6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 8 deletions.
49 changes: 45 additions & 4 deletions djangocms_blog/cms_appconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,54 @@


class BlogConfig(TranslatableModel):
"""
Class representing a blog configuration.
This class inherits from TranslatableModel.
Attributes:
type (models.CharField): Represents the type of the blog config.
namespace (models.CharField): Represents the namespace of the instance.
translations (TranslatedFields): Represents the translated fields of the blog config.
default_image_full (models.ForeignKey): Represents the default size of full images.
default_image_thumbnail (models.ForeignKey): Represents the default size of thumbnail images.
url_patterns (models.CharField): Represents the structure of permalinks.
use_placeholder (models.BooleanField): Represents whether to use placeholder and plugins for article body.
use_abstract (models.BooleanField): Represents whether to use abstract field.
use_related (models.SmallIntegerField): Represents whether to enable related posts.
urlconf (models.CharField): Represents the URL config.
set_author (models.BooleanField): Represents whether to set author by default.
paginate_by (models.SmallIntegerField): Represents the number of articles per page for pagination.
template_prefix (models.CharField): Represents the alternative directory to load the blog templates from.
menu_structure (models.CharField): Represents the menu structure.
menu_empty_categories (models.BooleanField): Represents whether to show empty categories in menu.
sitemap_changefreq (models.CharField): Represents the changefreq attribute for sitemap items.
sitemap_priority (models.DecimalField): Represents the priority attribute for sitemap items.
object_type (models.CharField): Represents the object type.
og_type (models.CharField): Represents the Facebook type.
og_app_id (models.CharField): Represents the Facebook application ID.
og_profile_id (models.CharField): Represents the Facebook profile ID.
og_publisher (models.CharField): Represents the Facebook page URL.
og_author_url (models.CharField): Represents the Facebook author URL.
og_author (models.CharField): Represents the Facebook author.
twitter_type (models.CharField): Represents the Twitter type field.
twitter_site (models.CharField): Represents the Twitter site handle.
twitter_author (models.CharField): Represents the Twitter author handle.
gplus_type (models.CharField): Represents the Schema.org object type.
gplus_author (models.CharField): Represents the Schema.org author name abstract field.
"""
class Meta:
verbose_name = _("blog config")
verbose_name_plural = _("blog configs")

type = models.CharField(
_("Type"),
verbose_name=_("type"),
max_length=100,
)
namespace = models.CharField(
_("Instance namespace"),
verbose_name=_("instance namespace"),
default=None,
max_length=100,
unique=True,
Expand All @@ -67,7 +105,7 @@ class Meta:
blank=True,
null=True,
on_delete=models.SET_NULL,
verbose_name=_("Default size of full images"),
verbose_name=_("default size of full images"),
help_text=_("If left empty the image size will have to be set for every newly created post."),
)
#: Default size of thumbnail images
Expand All @@ -77,7 +115,7 @@ class Meta:
blank=True,
null=True,
on_delete=models.SET_NULL,
verbose_name=_("Default size of thumbnail images"),
verbose_name=_("default size of thumbnail images"),
help_text=_("If left empty the thumbnail image size will have to be set for every newly created post."),
)
#: Structure of permalinks (get_absolute_url); see :ref:`AVAILABLE_PERMALINK_STYLES <AVAILABLE_PERMALINK_STYLES>`
Expand Down Expand Up @@ -262,6 +300,9 @@ def __str__(self):


def get_app_instance(request):
"""
Return current app instance namespace and config
"""
app = None
namespace, config = "", None
if getattr(request, "current_page", None) and request.current_page.application_urls:
Expand Down
18 changes: 14 additions & 4 deletions djangocms_blog/cms_toolbars.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
@toolbar_pool.register
class BlogToolbar(CMSToolbar):
def _get_published_post_version(self):
"""Returns a published page if one exists for the toolbar object"""
"""Returns a published post if one exists for the toolbar object"""
language = self.current_lang
# Exit the current toolbar object is not a Page / PageContent instance
# Exit if the current toolbar object is not a PostContent instance
if not isinstance(self.toolbar.obj, PostContent):
return

Expand All @@ -34,7 +34,6 @@ def add_preview_button(self):
url = get_object_preview_url(page_content, language=self.toolbar.request_language)
item = ButtonList(side=self.toolbar.RIGHT)
if self.toolbar.preview_mode_active:
print(f"==> {self.request.path_info=} {self.toolbar.request_path=}")
item.add_button(
_("View on site"),
url=page_content.get_absolute_url(),
Expand Down Expand Up @@ -104,12 +103,23 @@ def populate(self):
if current_config and current_config.app_title:
menu_name = current_config.app_title.capitalize()
admin_menu = self.toolbar.get_or_create_menu("djangocms_blog", menu_name)
# Properties menu entry
object_name = current_config.object_name if current_config else Post._meta.verbose_name
object_name = object_name.capitalize()
if current_content and self.request.user.has_perm("djangocms_blog.change_post"):
admin_menu.add_modal_item(
_("%(object_name)s properties") % dict(object_name=object_name.capitalize()),
admin_reverse("djangocms_blog_post_change", args=(current_content.post.pk,)),
)
admin_menu.add_break()
# Entry list menu entry
if current_config:
url = admin_reverse("djangocms_blog_post_changelist") + f"?app_config__id__exact={current_config.pk}"
admin_menu.add_sideframe_item(
_("Instances of %(object_name)s") % dict(object_name=object_name),
url=url,
)
# Create menu entry
url = admin_reverse("djangocms_blog_post_add")
if current_config:
url += f"?app_config={current_config.pk}"
Expand All @@ -119,7 +129,7 @@ def populate(self):
)
if current_config:
url = admin_reverse("djangocms_blog_blogconfig_change", args=(current_config.pk,))
admin_menu.add_modal_item(_("Edit configuration"), url=url)
admin_menu.add_modal_item(_("Edit Configuration"), url=url)
self.add_preview_button()
self.add_view_published_button() # Takes the user the published post version

Expand Down

0 comments on commit 1252bf6

Please sign in to comment.