Skip to main content

Grok-like configuration for Zope annotations

Project description

This package provides a support to simplify the use of annotations in Zope.

Setting up grokcore.annotation

This package is essentially set up like the grokcore.component package, please refer to its documentation for details. The only additional ZCML line you will need is:

<include package="grokcore.annotation" />

Put this somewhere near the top of your root ZCML file but below the line where you include grokcore.component’s configuration.

Example

Here a simple example of use of an annotation:

import grokcore.annotation
from zope import interface

# Create a model and an interface you want to adapt it to
# and an annotation class to implement the persistent adapter.
class Mammoth(grokcore.annotation.Model):
    pass

class ISerialBrand(interface.Interface):
    unique = interface.Attribute("Brands")

class Branding(grokcore.annotation.Annotation):
    grokcore.annotation.implements(ISerialBrand)
    unique = 0

# Grok the above code, then create some mammoths
manfred = Mammoth()
mumbles = Mammoth()

# creating Annotations work just like Adapters
livestock1 = ISerialBrand(manfred)
livestock2 = ISerialBrand(mumbles)

# except you can store data in them, this data will transparently persist
# in the database for as long as the object exists
livestock1.unique = 101
livestock2.unique = 102

# attributes not listed in the interface will also be persisted
# on the annotation
livestock2.foo = "something"

API Overview

Base classes

Annotation

Base class for an Annotation. Inherits from the persistent.Persistent class.

Model

Base class for a Model on which you want to use an annotation.

queryAnnotation(model, interface)

Query the annotation on the given model for the given interface. Return the annotation if found, None otherwise. This will not make any write operation.

deleteAnnotation(model, interface)

Look for the given annotation and delete it from the model.

LazyAnnotation

Base class for an annotation. It only writes a database object when explicitly setting values on the lazy properties.

LazyAnnotationProperty

Property implementation that works with LazyAnnotation.

In addition, the grokcore.annotation package exposes the grokcore.component API.

Changes

3.2 (2021-08-31)

  • grokcore.annotation.testing.warn was removed as it was not used internally. If you still need it, a copy is in grokcore.view.testing.

  • Add _p_changed property to the LazyAnnotation object, proxying it to the actual Storage object. That way the “API” for explicitely marking objects as changed is the same regaredless of a “normal” annotation object or an lazy annotation object.

  • Add support for Python 3.7, 3.8 and 3.9.

  • Drop support for Python 3.4.

3.1 (2020-10-27)

  • Add support for FieldUpdatedEvent in LazyPropertyAnnotation to mirror the behavior of zope.schema.

3.0.1 (2018-01-17)

  • Replace the use of grok.implements() with the @grok.implementer() directive throughout.

3.0.0 (2018-01-12)

  • Rearrange tests such that Travis CI can pick up all functional tests too.

1.6 (2017-05-30)

  • Add LazyAnnotation and LazyAnnotationProperty.

  • Drop support of Python 2.6 and claim support for Python 3.4, 3.5, 3.6 and PyPy.

1.5.1 (2016-01-29)

  • Update tests.

1.5 (2014-10-20)

  • Updating MANIFEST.in, fixing a brown paper bag release.

1.4 (2014-10-17)

  • Add queryAnnotation() to return an annotation. Return None if it doesn’t exists. This helper will never do any write operation in the database.

  • Add deleteAnnotation() to delete an annotation (if it exists).

1.3 (2012-05-01)

  • Use provideAdapter() from grokcore.component.util.

  • Made package comply to zope.org repository policy.

1.2 (2009-12-13)

  • Use zope.container instead of zope.app.container.

1.1 (2009-09-18)

  • The annotation object become really a contained object to be aware of its context, and name.

  • Use 1.0b1 versions.cfg in Grok’s release info instead of a local copy; a local copy for all grokcore packages is just too hard to maintain.

1.0.1 (2009-06-30)

  • Reupload to pypi with a correct version of Python which doesn’t have a distutils bug.

1.0 (2009-06-29)

  • Created grokcore.Annotation by factoring annotation components, grokkers and directives out of Grok.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

grokcore.annotation-3.2.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

grokcore.annotation-3.2-py2.py3-none-any.whl (18.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file grokcore.annotation-3.2.tar.gz.

File metadata

  • Download URL: grokcore.annotation-3.2.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.10

File hashes

Hashes for grokcore.annotation-3.2.tar.gz
Algorithm Hash digest
SHA256 d7c395dbb802a3f7a52c34b1fadd23e9631e26c2acfeca972d75c8c858204a95
MD5 be1b6541000d6c666f7b7b01bedc16f5
BLAKE2b-256 c5e0fe5208a412b421cd679745ea517cfcc793359b29d7cd2affcb34167b593c

See more details on using hashes here.

File details

Details for the file grokcore.annotation-3.2-py2.py3-none-any.whl.

File metadata

  • Download URL: grokcore.annotation-3.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.2 CPython/3.8.10

File hashes

Hashes for grokcore.annotation-3.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2a5df777bc1478a737e06960eff5b4c6fbaa993307f787cd5f7542cc61a20fcd
MD5 e26a613f99b4074e5b01652fa4fa4183
BLAKE2b-256 ea77562804c25000853bf15f12288a015ecf8d08e0f6c816ebd53f283848fbdb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page