Skip to content

Commit

Permalink
Merge pull request #1 from maykinmedia/feature/anne-frank-32-cms-4
Browse files Browse the repository at this point in the history
Feature/anne frank 32 cms 4
  • Loading branch information
alextreme authored Dec 9, 2024
2 parents cd4eca6 + 77f464d commit 779459a
Show file tree
Hide file tree
Showing 17 changed files with 313 additions and 244 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
matrix:
python-version: ["3.11", "3.10", "3.9"]
django: [42, 41, 32]
cms: [311, 39]
cms: [4]
continue-on-error: [true]
exclude:
- django: 41
Expand Down
1 change: 1 addition & 0 deletions changes/32.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix for permission name change
3 changes: 2 additions & 1 deletion cms_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ def gettext(s):
NOSE_ARGS=[
"-s",
],
CMS_CONFIRM_VERSION4=True,
ROOT_URLCONF="tests.test_utils.urls",
INSTALLED_APPS=[
"easy_thumbnails",
"filer",
"taggit",
"taggit_autosuggest",
"meta",
"djangocms_page_tags",
# "djangocms_page_tags",
"tests.test_utils",
],
LANGUAGE_CODE="en",
Expand Down
9 changes: 7 additions & 2 deletions djangocms_page_meta/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from cms.admin.pageadmin import PageAdmin
from cms.extensions import PageExtensionAdmin, TitleExtensionAdmin

try:
from cms.extensions import PageContentExtensionAdmin, PageExtensionAdmin
except ImportError:
from cms.extensions import PageExtensionAdmin, TitleExtensionAdmin as PageContentExtensionAdmin

from cms.utils import get_language_from_request
from django.conf import settings
from django.contrib import admin
Expand Down Expand Up @@ -68,7 +73,7 @@ def get_model_perms(self, request):


@admin.register(TitleMeta)
class TitleMetaAdmin(TitleExtensionAdmin):
class TitleMetaAdmin(PageContentExtensionAdmin):
form = TitleMetaAdminForm
inlines = (GenericAttributeTitleInline,)

Expand Down
8 changes: 4 additions & 4 deletions djangocms_page_meta/cms_toolbars.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from cms.api import get_page_draft
from cms.cms_toolbars import PAGE_MENU_SECOND_BREAK
from cms.toolbar.items import Break
from cms.toolbar_base import CMSToolbar
Expand All @@ -25,7 +24,8 @@
class PageToolbarMeta(CMSToolbar):
def populate(self):
# always use draft if we have a page
self.page = get_page_draft(self.request.current_page)
# self.page = get_page_draft(self.request.current_page)
self.page = self.request.current_page
if not self.page:
# Nothing to do
return
Expand All @@ -36,7 +36,7 @@ def populate(self):
# check global permissions if CMS_PERMISSIONS is active
if get_cms_setting("PERMISSION"):
has_global_current_page_change_permission = has_page_permission(
self.request.user, self.request.current_page, "change"
self.request.user, self.request.current_page, "change_page"
)
else:
has_global_current_page_change_permission = False
Expand Down Expand Up @@ -79,7 +79,7 @@ def populate(self):
meta_menu.add_modal_item(PAGE_META_ITEM_TITLE, url=url, disabled=not_edit_mode, position=position)
# Title tags
site_id = self.page.node.site_id
titles = self.page.title_set.filter(language__in=get_language_list(site_id))
titles = self.page.pagecontent_set.filter(language__in=get_language_list(site_id))

title_extensions = {
t.extended_object_id: t
Expand Down
3 changes: 3 additions & 0 deletions djangocms_page_meta/migrations/0011_auto_20190218_1010.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class Migration(migrations.Migration):
dependencies = [
("djangocms_page_meta", "0010_auto_20180108_2316"),
]
run_before = [
("cms", "0032_remove_title_to_pagecontent"), # before title is renamed
]

operations = [
migrations.AlterField(
Expand Down
1 change: 0 additions & 1 deletion djangocms_page_meta/migrations/0016_auto_20230830_1007.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class Migration(migrations.Migration):
dependencies = [
("djangocms_page_meta", "0015_defaultmetaimage"),
]

operations = [
migrations.RunPython(generate_default_meta_image_singleton, backwards),
]
16 changes: 12 additions & 4 deletions djangocms_page_meta/models.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import ast

from cms.extensions import PageExtension, TitleExtension
try:
from cms.extensions import PageContentExtension, PageExtension
from cms.models import Page, PageContent
except ImportError:
from cms.extensions import PageExtension, TitleExtension as PageContentExtension
from cms.models import Page, Title as PageContent

from cms.extensions.extension_pool import extension_pool
from cms.models import Page, Title
from django.conf import settings
from django.core.cache import cache
from django.db import models
Expand Down Expand Up @@ -98,7 +103,8 @@ def robots_list(self):
extension_pool.register(PageMeta)


class TitleMeta(TitleExtension):
# TODO: renamed too PageContentExtension
class TitleMeta(PageContentExtension):
image = FilerFileField(
null=True,
blank=True,
Expand Down Expand Up @@ -206,7 +212,7 @@ def cleanup_page(sender, instance, **kwargs):
cache.delete(key)


@receiver(pre_delete, sender=Title)
@receiver(pre_delete, sender=PageContent)
def cleanup_title(sender, instance, **kwargs):
key = get_cache_key(instance.page, instance.language)
cache.delete(key)
Expand All @@ -218,13 +224,15 @@ def cleanup_pagemeta(sender, instance, **kwargs):
for language in instance.extended_object.get_languages():
key = get_cache_key(instance.extended_object, language)
cache.delete(key)
instance.extended_object.clear_cache()


@receiver(post_save, sender=TitleMeta)
@receiver(pre_delete, sender=TitleMeta)
def cleanup_titlemeta(sender, instance, **kwargs):
key = get_cache_key(instance.extended_object.page, instance.extended_object.language)
cache.delete(key)
instance.extended_object.page.clear_cache()


if registry:
Expand Down
12 changes: 6 additions & 6 deletions djangocms_page_meta/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_page_meta(page, language):
meta = cache.get(meta_key)
if not meta:
meta = Meta()
title = page.get_title_obj(language)
title = page.get_content_obj(language)
default_meta_image = DefaultMetaImage.objects.first().image
meta.extra_custom_props = []

Expand Down Expand Up @@ -93,7 +93,7 @@ def get_page_meta(page, language):
"twitter_site": meta_settings.get_setting("TWITTER_SITE"),
"twitter_author": meta_settings.get_setting("TWITTER_AUTHOR"),
"schemaorg_type": meta_settings.get_setting("SCHEMAORG_TYPE"),
"schemaorg_datePublished": page.publication_date.isoformat() if page.publication_date else None,
# "schemaorg_datePublished": page.publication_date.isoformat() if page.publication_date else None,
"schemaorg_dateModified": page.changed_date.isoformat() if page.changed_date else None,
}
try:
Expand All @@ -108,12 +108,12 @@ def get_page_meta(page, language):
meta.twitter_author = pagemeta.twitter_author
meta.schemaorg_type = pagemeta.schemaorg_type
meta.robots = pagemeta.robots_list
if page.publication_date:
meta.published_time = page.publication_date.isoformat()
# if page.publication_date:
# meta.published_time = page.publication_date.isoformat()
if page.changed_date:
meta.modified_time = page.changed_date.isoformat()
if page.publication_end_date:
meta.expiration_time = page.publication_end_date.isoformat()
# if page.publication_end_date:
# meta.expiration_time = page.publication_end_date.isoformat()
if meta.og_type == "article":
meta.og_publisher = pagemeta.og_publisher
meta.og_author_url = pagemeta.og_author_url
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ classifiers =
[options]
include_package_data = True
install_requires =
django-cms>=3.7,<4.0
django-cms~=4.1
django-meta>=2.4.0
django-filer>=3.0
setup_requires =
Expand Down
63 changes: 0 additions & 63 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,63 +0,0 @@
from app_helper.base_test import BaseTestCase
from django.core.cache import cache


class DummyTokens(list):
def __init__(self, *tokens):
super().__init__(["dummy_tag"] + list(tokens))

def split_contents(self):
return self


class BaseTest(BaseTestCase):
"""
Base class with utility function
"""

page_data = {}
_pages_data = (
{
"en": {"title": "page one", "template": "page_meta.html", "publish": True},
"fr-fr": {"title": "page un", "publish": True},
"it": {"title": "pagina uno", "publish": True},
},
{
"en": {"title": "page two", "template": "page_meta.html", "publish": True},
"fr-fr": {"title": "page deux", "publish": True},
"it": {"title": "pagina due", "publish": True},
},
)
title_data = {
"keywords": "keyword1, keyword2, keyword3",
"description": "base lorem ipsum - english",
"og_description": "opengraph - lorem ipsum - english",
"twitter_description": "twitter - lorem ipsum - english",
"schemaorg_description": "gplus - lorem ipsum - english",
}
title_data_it = {
"keywords": "parola1, parola2, parola3",
"description": "base lorem ipsum - italian",
"og_description": "opengraph - lorem ipsum - italian",
"twitter_description": "twitter - lorem ipsum - italian",
"schemaorg_description": "gplus - lorem ipsum - italian",
}
og_data = {
"og_type": "article",
"og_author_url": "https://facebook.com/FakeUser",
"og_author_fbid": "123456789",
"og_publisher": "https://facebook.com/FakeUser",
"og_app_id": "123456789",
"fb_pages": "PAGES123456789",
}
twitter_data = {
"twitter_author": "fake_user",
"twitter_site": "fake_site",
"twitter_type": "summary",
}
robots_data_single = {"robots": "['noindex']"}
robots_data_multiple = {"robots": "['none', 'noimageindex', 'noarchive']"}

def setUp(self):
super().setUp()
cache.clear()
120 changes: 120 additions & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
from collections import OrderedDict
from copy import deepcopy

from app_helper.base_test import CreateTestDataMixin
from cms.api import create_page, create_page_content
from cms.test_utils.testcases import CMSTestCase
from django.contrib.auth.models import Permission
from django.core.cache import cache


class DummyTokens(list):
def __init__(self, *tokens):
super().__init__(["dummy_tag"] + list(tokens))

def split_contents(self):
return self


class BaseTest(CMSTestCase):
"""
Base class with utility function
"""

language = "en"
languages = ["en", "fr-fr", "it"]

pages_data = (
{
"en": {"title": "page one", "template": "page_meta.html"},
"fr-fr": {"title": "page un"},
"it": {"title": "pagina uno"},
},
{
"en": {"title": "page two", "template": "page_meta.html"},
"fr-fr": {"title": "page deux"},
"it": {"title": "pagina due"},
},
)

title_data = {
"keywords": "keyword1, keyword2, keyword3",
"description": "base lorem ipsum - english",
"og_description": "opengraph - lorem ipsum - english",
"twitter_description": "twitter - lorem ipsum - english",
"schemaorg_description": "gplus - lorem ipsum - english",
}
title_data_it = {
"keywords": "parola1, parola2, parola3",
"description": "base lorem ipsum - italian",
"og_description": "opengraph - lorem ipsum - italian",
"twitter_description": "twitter - lorem ipsum - italian",
"schemaorg_description": "gplus - lorem ipsum - italian",
}
og_data = {
"og_type": "article",
"og_author_url": "https://facebook.com/FakeUser",
"og_author_fbid": "123456789",
"og_publisher": "https://facebook.com/FakeUser",
"og_app_id": "123456789",
"fb_pages": "PAGES123456789",
}
twitter_data = {
"twitter_author": "fake_user",
"twitter_site": "fake_site",
"twitter_type": "summary",
}
robots_data_single = {"robots": "['noindex']"}
robots_data_multiple = {"robots": "['none', 'noimageindex', 'noarchive']"}

image_name = "test_image.jpg"

def setUp(self):
super().setUp()
assert self.language == self.languages[0]

self.superuser = self.get_superuser()
self.staff_user = self.get_staff_user_with_std_permissions()

cache.clear()

def create_pages(self):
"""
Removes all draft and publishing from parent function
"""
home_set = False
pages = OrderedDict()

for page_data in self.pages_data:

main_data = deepcopy(page_data[self.language])
main_data["language"] = self.language
page = create_page(**main_data)

for lang in self.languages[1:]:
context_data = deepcopy(page_data[lang])
context_data["language"] = lang
context_data["page"] = page
create_page_content(**context_data)

if not home_set:
page.set_as_homepage()
home_set = True
pages[page.get_slug(self.language)] = page

return list(pages.values())

def _add_default_permissions(self, user):
# Page permissions
user.user_permissions.add(Permission.objects.get(codename="publish_page"))
user.user_permissions.add(Permission.objects.get(codename="add_page"))
user.user_permissions.add(Permission.objects.get(codename="change_page"))
user.user_permissions.add(Permission.objects.get(codename="delete_page"))

create_filer_image = CreateTestDataMixin.create_filer_image
create_django_image = CreateTestDataMixin.create_django_image

def create_filer_image_object(self):
self.filer_image = self.create_filer_image(self.staff_user, self.image_name)
return self.filer_image
Loading

0 comments on commit 779459a

Please sign in to comment.