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

Fix default DOI when adding content #142

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
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
4 changes: 4 additions & 0 deletions src/recensio/plone/behaviors/base_review.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from plone.autoform import directives
from plone.autoform.interfaces import IFormFieldProvider
from plone.dexterity.interfaces import IDexterityContent
from plone.dexterity.utils import iterSchemata
from plone.namedfile.field import NamedBlobFile
from plone.namedfile.field import NamedBlobImage
from plone.registry.interfaces import IRegistry
Expand All @@ -26,6 +27,9 @@ def generateDoi(context):
Might not need to be called as a default factory, but just in the
edit form
"""
if IBaseReview not in iterSchemata(context):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nicer, maybe also more performant‌ (which probably isn't a problem here) if you would use a marker interface.

You create a marker interface, register it for the behavior like so:

  <plone:behavior
      name="recensio.base_review"
      title="Base Review Behavior"
      factory=".base_review.BaseReview"
      provides=".base_review.IBaseReview"
      marker=".base_review.IBaseReviewMarker"
      for="plone.dexterity.interfaces.IDexterityContent"
      />

and then:

Suggested change
if IBaseReview not in iterSchemata(context):
if not IBaseReviewMarker.providedBy(context):

# XXX When adding new content we get the container as context
return None
registry = getUtility(IRegistry)
settings = registry.forInterface(
IRecensioSettings, prefix="recensio.plone.settings"
Expand Down
Loading