Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behaviors #2

Merged
merged 12 commits into from
Mar 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
wip: behavior
remdub committed Feb 28, 2024
commit c89c40473679f44ca5aa806939057bcf0eefa7f1
Empty file.
22 changes: 22 additions & 0 deletions src/collective/plausible/behaviors/configure.zcml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:plone="http://namespaces.plone.org/plone"
xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="plone">

<include package="plone.behavior" file="meta.zcml"/>

<!-- -*- extra stuff goes here -*- -->

<plone:behavior
name="collective.plausible.plausible_fields"
title="PlausibleFields"
description="This behaviors adds Plausible fields on a content type"
provides=".plausible_fields.IPlausibleFields"
factory=".plausible_fields.PlausibleFields"
marker=".plausible_fields.IPlausibleFieldsMarker"
/>


</configure>
107 changes: 107 additions & 0 deletions src/collective/plausible/behaviors/plausible_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# -*- coding: utf-8 -*-

from collective.plausible import _
from plone import schema
from plone.autoform.interfaces import IFormFieldProvider
from plone.supermodel import directives
from plone.supermodel import model
from Products.CMFPlone.utils import safe_hasattr
from zope.component import adapter
from zope.interface import implementer
from zope.interface import Interface
from zope.interface import provider


class IPlausibleFieldsMarker(Interface):
pass


@provider(IFormFieldProvider)
class IPlausibleFields(model.Schema):
""" """

directives.fieldset(
"plausible_fields",
label=_("Plausible fields"),
description=_("Plausible analytics fields"),
fields=["url", "site", "token", "link_user_action"],
)

url = schema.TextLine(
title=_("Plausible URL"),
description=_("Example : plausible.imio.be"),
default="",
required=False,
readonly=False,
)

site = schema.TextLine(
title=_("Plausible Site"),
description=_("Example : imio.be"),
default="",
required=False,
readonly=False,
)

token = schema.TextLine(
title=_("Plausible token"),
description=_("Plausible authentification token"),
default="",
required=False,
readonly=False,
)

link_user_action = schema.Bool(
title=_("Add a link in the user menu"),
description=_("Add a link to the statistics browser view in the user menu"),
default=True,
required=False,
readonly=False,
)


@implementer(IPlausibleFields)
@adapter(IPlausibleFieldsMarker)
class PlausibleFields(object):
def __init__(self, context):
self.context = context

@property
def url(self):
if safe_hasattr(self.context, "url"):
return self.context.url
return None

@url.setter
def url(self, value):
self.context.url = value

@property
def site(self):
if safe_hasattr(self.context, "site"):
return self.context.site
return None

@site.setter
def site(self, value):
self.context.site = value

@property
def token(self):
if safe_hasattr(self.context, "token"):
return self.context.token
return None

@token.setter
def token(self, value):
self.context.token = value

@property
def link_user_action(self):
if safe_hasattr(self.context, "link_user_action"):
return self.context.link_user_action
return None

@link_user_action.setter
def link_user_action(self, value):
self.context.link_user_action = value
3 changes: 3 additions & 0 deletions src/collective/plausible/configure.zcml
Original file line number Diff line number Diff line change
@@ -42,6 +42,9 @@

<!-- -*- extra stuff goes here -*- -->

<include package=".behaviors" />


<include package=".upgrades" />

<include package=".controlpanels" />
28 changes: 28 additions & 0 deletions src/collective/plausible/tests/test_behavior_plausible_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from collective.plausible.behaviors.plausible_fields import IPlausibleFieldsMarker
from collective.plausible.testing import ( # noqa
COLLECTIVE_PLAUSIBLE_INTEGRATION_TESTING,
)
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from plone.behavior.interfaces import IBehavior
from zope.component import getUtility

import unittest


class PlausibleFieldsIntegrationTest(unittest.TestCase):

layer = COLLECTIVE_PLAUSIBLE_INTEGRATION_TESTING

def setUp(self):
"""Custom shared utility setup for tests."""
self.portal = self.layer["portal"]
setRoles(self.portal, TEST_USER_ID, ["Manager"])

def test_behavior_plausible_fields(self):
behavior = getUtility(IBehavior, "collective.plausible.plausible_fields")
self.assertEqual(
behavior.marker,
IPlausibleFieldsMarker,
)
4 changes: 2 additions & 2 deletions src/collective/plausible/tests/test_robot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from collective.plausible.testing import (
from collective.plausible.testing import ( # noqa: E501
COLLECTIVE_PLAUSIBLE_ACCEPTANCE_TESTING,
) # noqa: E501
)
from plone.app.testing import ROBOT_TEST_LEVEL
from plone.testing import layered

4 changes: 2 additions & 2 deletions src/collective/plausible/tests/test_setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
"""Setup tests for this package."""
from collective.plausible.testing import (
from collective.plausible.testing import ( # noqa: E501
COLLECTIVE_PLAUSIBLE_INTEGRATION_TESTING,
) # noqa: E501
)
from plone import api
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
5 changes: 2 additions & 3 deletions src/collective/plausible/tests/test_upgrade_step_1001.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
# from collective.plausible.testing import COLLECTIVE_PLAUSIBLE_FUNCTIONAL_TESTING
from collective.plausible.testing import COLLECTIVE_PLAUSIBLE_INTEGRATION_TESTING
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
from Products.CMFCore.utils import getToolByName

# from collective.plausible.testing import COLLECTIVE_PLAUSIBLE_FUNCTIONAL_TESTING
from collective.plausible.testing import COLLECTIVE_PLAUSIBLE_INTEGRATION_TESTING

import unittest


Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from collective.plausible.views.plausible_utils import PlausibleUtilsView
from collective.plausible.testing import COLLECTIVE_PLAUSIBLE_FUNCTIONAL_TESTING
from collective.plausible.views.plausible_utils import PlausibleUtilsView
from plone import api
from plone.app.testing import setRoles
from plone.app.testing import TEST_USER_ID
5 changes: 2 additions & 3 deletions src/collective/plausible/upgrades/v1001.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-

from . import logger


from .base import reload_gs_profile
from collective.plausible import _
from plone.registry import Record, field
from plone.registry import field
from plone.registry import Record
from plone.registry.interfaces import IRegistry
from zope.component import getUtility

6 changes: 3 additions & 3 deletions src/collective/plausible/views/plausible_utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# -*- coding: utf-8 -*-

import requests

from collective.plausible.utils import get_plausible_vars
from zope.interface import Interface
from plone import api
from Products.Five.browser import BrowserView
from zope.interface import implementer
from zope.interface import Interface

import requests


# from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile