From 76b19f7b47a17512d23f6491288079a6df35f586 Mon Sep 17 00:00:00 2001 From: Andrew Aikman Date: Thu, 1 Apr 2021 14:44:46 +0100 Subject: [PATCH 1/6] Temporary workaround for failing intallation where the migrations hasn't yet occured but the code is trying to run in Docker --- djangocms_blog/cms_wizards.py | 49 +++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/djangocms_blog/cms_wizards.py b/djangocms_blog/cms_wizards.py index 3e4ba5d2..1dd56220 100644 --- a/djangocms_blog/cms_wizards.py +++ b/djangocms_blog/cms_wizards.py @@ -97,25 +97,30 @@ class PostWizard(Wizard): pass -for config in BlogConfig.objects.all().order_by("namespace"): - seed = slugify("{}.{}".format(config.app_title, config.namespace)) - new_wizard = type(str(seed), (PostWizard,), {}) - new_form = type("{}Form".format(seed), (PostWizardForm,), {"default_appconfig": config.pk}) - post_wizard = new_wizard( - title=_("New {0}").format(config.object_name), - weight=200, - form=new_form, - model=Post, - description=_("Create a new {0} in {1}").format(config.object_name, config.app_title), - ) - try: - wizard_pool.register(post_wizard) - except AlreadyRegisteredException: # pragma: no cover - if settings.DEBUG: - raise - else: - warnings.warn( - "Wizard {} cannot be registered. Please make sure that " - "BlogConfig.namespace {} and BlogConfig.app_title {} are" - "unique together".format(seed, config.namespace, config.app_title) - ) +try: + for config in BlogConfig.objects.all().order_by("namespace"): + seed = slugify("{}.{}".format(config.app_title, config.namespace)) + new_wizard = type(str(seed), (PostWizard,), {}) + new_form = type("{}Form".format(seed), (PostWizardForm,), {"default_appconfig": config.pk}) + post_wizard = new_wizard( + title=_("New {0}").format(config.object_name), + weight=200, + form=new_form, + model=Post, + description=_("Create a new {0} in {1}").format(config.object_name, config.app_title), + ) + try: + wizard_pool.register(post_wizard) + except AlreadyRegisteredException: # pragma: no cover + if settings.DEBUG: + raise + else: + warnings.warn( + "Wizard {} cannot be registered. Please make sure that " + "BlogConfig.namespace {} and BlogConfig.app_title {} are" + "unique together".format(seed, config.namespace, config.app_title) + ) +except: # pragma: no cover + warnings.warn( + "Wizards not yet registered" + ) \ No newline at end of file From d1a5d39eb3781e681487338bdbfaf9c76e945bed Mon Sep 17 00:00:00 2001 From: Andrew Aikman Date: Thu, 1 Apr 2021 14:45:16 +0100 Subject: [PATCH 2/6] Temporary workaround for an issue in the migration files looking for draft pages --- djangocms_blog/migrations/0014_auto_20160215_1331.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djangocms_blog/migrations/0014_auto_20160215_1331.py b/djangocms_blog/migrations/0014_auto_20160215_1331.py index 1e4f560c..ac3aa63e 100644 --- a/djangocms_blog/migrations/0014_auto_20160215_1331.py +++ b/djangocms_blog/migrations/0014_auto_20160215_1331.py @@ -12,7 +12,7 @@ def forwards(apps, schema_editor): LatestPostsPlugin = apps.get_model("djangocms_blog", "LatestPostsPlugin") AuthorEntriesPlugin = apps.get_model("djangocms_blog", "AuthorEntriesPlugin") config = None - for page in Page.objects.drafts().filter(application_urls="BlogApp"): + for page in Page.objects.filter(application_urls="BlogApp"): config, created = BlogConfig.objects.get_or_create(namespace=page.application_namespace) if not BlogConfigTranslation.objects.exists(): for lang in get_language_list(): From 16818a1027e0bb84886d645774e902256559f64d Mon Sep 17 00:00:00 2001 From: Andrew Aikman Date: Thu, 1 Apr 2021 15:21:01 +0100 Subject: [PATCH 3/6] Remove draft logic --- djangocms_blog/cms_menus.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/djangocms_blog/cms_menus.py b/djangocms_blog/cms_menus.py index 740c9128..3176b6ae 100644 --- a/djangocms_blog/cms_menus.py +++ b/djangocms_blog/cms_menus.py @@ -55,12 +55,12 @@ def get_nodes(self, request): logger.exception(e) return [] config = self._config[self.instance.application_namespace] - if not getattr(request, "toolbar", False) or not request.toolbar.edit_mode_active: - if self.instance == self.instance.get_draft_object(): - return [] - else: - if self.instance == self.instance.get_public_object(): - return [] + # if not getattr(request, "toolbar", False) or not request.toolbar.edit_mode_active: + # if self.instance == self.instance.get_draft_object(): + # return [] + # else: + # if self.instance == self.instance.get_public_object(): + # return [] if config and config.menu_structure in (MENU_TYPE_COMPLETE, MENU_TYPE_CATEGORIES): categories_menu = True if config and config.menu_structure in (MENU_TYPE_COMPLETE, MENU_TYPE_POSTS): From 739d9e5e8e332f025d872c6abc3f66eb7a779cd3 Mon Sep 17 00:00:00 2001 From: Andrew Aikman Date: Thu, 1 Apr 2021 16:22:32 +0100 Subject: [PATCH 4/6] Initial start to editable view --- djangocms_blog/cms_config.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 djangocms_blog/cms_config.py diff --git a/djangocms_blog/cms_config.py b/djangocms_blog/cms_config.py new file mode 100644 index 00000000..4860ccd6 --- /dev/null +++ b/djangocms_blog/cms_config.py @@ -0,0 +1,12 @@ +from django.apps import apps +from django.conf import settings + +from cms.app_base import CMSAppConfig + +from .models import Post +from .views import PostDetailView + + +class AliasCMSConfig(CMSAppConfig): + cms_enabled = True + cms_toolbar_enabled_models = [(Post, PostDetailView)] From 9ce67a869ea4e18c4d5e4a9776c1f01485d77d72 Mon Sep 17 00:00:00 2001 From: Andrew Aikman Date: Thu, 1 Apr 2021 20:19:47 +0100 Subject: [PATCH 5/6] Remap the placeholders to v4 compatible mechanisms --- djangocms_blog/cms_config.py | 9 ++---- djangocms_blog/models.py | 30 ++++++++++++++++--- djangocms_blog/rendering.py | 7 +++++ .../djangocms_blog/post_structure.html | 4 +++ 4 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 djangocms_blog/rendering.py create mode 100644 djangocms_blog/templates/djangocms_blog/post_structure.html diff --git a/djangocms_blog/cms_config.py b/djangocms_blog/cms_config.py index 4860ccd6..e8d10d11 100644 --- a/djangocms_blog/cms_config.py +++ b/djangocms_blog/cms_config.py @@ -1,12 +1,9 @@ -from django.apps import apps -from django.conf import settings - from cms.app_base import CMSAppConfig from .models import Post -from .views import PostDetailView +from .rendering import render_post_content -class AliasCMSConfig(CMSAppConfig): +class BlogCMSConfig(CMSAppConfig): cms_enabled = True - cms_toolbar_enabled_models = [(Post, PostDetailView)] + cms_toolbar_enabled_models = [(Post, render_post_content)] diff --git a/djangocms_blog/models.py b/djangocms_blog/models.py index 150a4aa6..6810a811 100644 --- a/djangocms_blog/models.py +++ b/djangocms_blog/models.py @@ -2,7 +2,7 @@ from aldryn_apphooks_config.fields import AppHookConfigField from aldryn_apphooks_config.managers.parler import AppHookConfigTranslatableManager -from cms.models import CMSPlugin, PlaceholderField +from cms.models import CMSPlugin, Placeholder, PlaceholderRelationField from django.conf import settings as dj_settings from django.contrib.auth import get_user_model from django.contrib.sites.shortcuts import get_current_site @@ -263,9 +263,7 @@ class Post(KnockerModel, BlogMetaMixin, TranslatableModel): post_text=HTMLField(_("text"), default="", blank=True, configuration="BLOG_POST_TEXT_CKEDITOR"), meta={"unique_together": (("language_code", "slug"),)}, ) - media = PlaceholderField("media", related_name="media") - content = PlaceholderField("post_content", related_name="post_content") - liveblog = PlaceholderField("live_blog", related_name="live_blog") + placeholders = PlaceholderRelationField() enable_liveblog = models.BooleanField(verbose_name=_("enable liveblog on post"), default=False) objects = GenericDateTaggedManager() @@ -316,6 +314,26 @@ def __str__(self): default = gettext("Post (no translation)") return self.safe_translation_getter("title", any_language=True, default=default) + def _get_placeholder_from_slotname(self, slotname): + try: + return self.placeholders.get(slot=slotname) + except Placeholder.DoesNotExist: + from cms.utils.placeholder import rescan_placeholders_for_obj + rescan_placeholders_for_obj(self) + return self.placeholders.get(slot=slotname) + + @cached_property + def media(self): + return self._get_placeholder_from_slotname("media") + + @cached_property + def content(self): + return self._get_placeholder_from_slotname("content") + + @cached_property + def liveblog(self): + return self._get_placeholder_from_slotname("liveblog") + @property def guid(self, language=None): if not language: @@ -442,6 +460,10 @@ def full_image_options(self): else: return get_setting("IMAGE_FULL_SIZE") + def get_template(self): + # Used for the cms structure endpoint + return 'djangocms_blog/post_structure.html' + @property def is_published(self): """ diff --git a/djangocms_blog/rendering.py b/djangocms_blog/rendering.py new file mode 100644 index 00000000..a2c14aff --- /dev/null +++ b/djangocms_blog/rendering.py @@ -0,0 +1,7 @@ +from django.template.response import TemplateResponse + + +def render_post_content(request, content_object): + template = 'djangocms_blog/post_detail.html' + context = {'post': content_object} + return TemplateResponse(request, template, context) diff --git a/djangocms_blog/templates/djangocms_blog/post_structure.html b/djangocms_blog/templates/djangocms_blog/post_structure.html new file mode 100644 index 00000000..4482b950 --- /dev/null +++ b/djangocms_blog/templates/djangocms_blog/post_structure.html @@ -0,0 +1,4 @@ +{% load cms_tags %} +{% placeholder 'media' %} +{% placeholder 'content' %} +{% placeholder 'liveblog' %} From b4d91be3661843f9654b785497b54fcfe701636d Mon Sep 17 00:00:00 2001 From: Aiky30 Date: Tue, 11 May 2021 19:28:28 +0100 Subject: [PATCH 6/6] Changed the View on site button for Posts to use the preview endpoint (#1) --- djangocms_blog/admin.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/djangocms_blog/admin.py b/djangocms_blog/admin.py index 5a4d7ea9..785d4953 100644 --- a/djangocms_blog/admin.py +++ b/djangocms_blog/admin.py @@ -3,6 +3,7 @@ from aldryn_apphooks_config.admin import BaseAppHookConfig, ModelAppHookConfig from cms.admin.placeholderadmin import FrontendEditableAdminMixin, PlaceholderAdminMixin from cms.models import CMSPlugin, ValidationError +from cms.toolbar.utils import get_object_preview_url from django.apps import apps from django.conf import settings from django.contrib import admin, messages @@ -449,6 +450,9 @@ def save_related(self, request, form, formsets, change): form.instance.sites.add(*self.get_restricted_sites(request).all().values_list("pk", flat=True)) super().save_related(request, form, formsets, change) + def view_on_site(self, obj): + return get_object_preview_url(obj, obj.language_code) + class Media: css = {"all": ("{}djangocms_blog/css/{}".format(settings.STATIC_URL, "djangocms_blog_admin.css"),)}