Skip to main content

Enhanced Python API for the Plone Content Management System

Project description

logo

kitconcept.api

A facade enhancing the already amazing plone.api.

PyPI PyPI - Python Version PyPI - Wheel PyPI - License PyPI - Status

PyPI - Plone Versions

Code analysis checks Tests Code Style

GitHub contributors GitHub Repo stars

Installation

Add kitconcept.api as a requirement of your package (in setup.py or setup.cfg).

Usage

Replace, in your codebase, occurrences of from plone import api with from kitconcept import api.

Inclusion of api.addon

api.addon.get_addons

Return a list of addons (kitconcept.api._typing.AddonInformation) in the installation.

Example:

from kitconcept import api
from kitconcept.api._typing import AddonInformation


addons = api.addon.get_addons()

# List of AddonInformation
assert isinstance(addons, list)
assert isinstance(addons[0], AddonInformation)

It is possible to filter the addons using the parameter limit:

from kitconcept import api


# Return all valid addons
all_addons = api.addon.get_addons()

# Only installed addons
installed_addons = api.addon.get_addons(limit="installed")

# Only upgradable (already installed) addons
upgradable_addons = api.addon.get_addons(limit="upgradable")

# Available addons -- not installed
available_addons = api.addon.get_addons(limit="available")

# It is also possible to get addons not available in the UI
# Only broken addons (with installation problems)
broken_addons = api.addon.get_addons(limit="broken")

# Only non-installable addons
broken_addons = api.addon.get_addons(limit="non_installable")

api.addon.get_addons_ids

Similar to api.addon.get_addons, but return only the addon ids.

Example:

from kitconcept import api


addons_ids = api.addon.get_addons_ids()

# List of str
assert isinstance(addons_ids, list)
assert isinstance(addons_ids[0], str)

api.addon.get

Get information about one addon.

Example:

from kitconcept import api


# Get information about plone.restapi
addon = api.addon.get("plone.restapi")
assert addon.id, "plone.restapi"
assert addon.valid is True
assert addon.description == "RESTful hypermedia API for Plone."
assert addon.profile_type == "default"
assert addon.version == "8.21.0"

api.addon.install

Install an addon

Example:

from kitconcept import api


status = api.addon.install("plone.restapi")
assert status is True
assert "plone.restapi" in api.addon.get_addons_ids(limit="installed")

api.addon.uninstall

Uninstall an addon

Example:

from kitconcept import api


status = api.addon.uninstall("plone.restapi")
assert status is True
assert "plone.restapi" in api.addon.get_addons_ids(limit="available")

Additions to api.content

api.content.get_constrains

Get constrains -- limits -- of a folderish content.

Example:

from kitconcept import api


constrains = api.content.get_constrains(obj)

# Constrains are not enabled by default
assert constrains.mode == "disabled"

# Document is allowed to be added to obj
assert "Document" in constrains.allowed_types

# Document is a prefered type to be added to obj
assert "Document" in constrains.immediately_addable_types

api.content.set_constrains

Set constrains -- limits -- of a folderish content.

Example:

from kitconcept import api


constrains = api.content.set_constrains(
    obj,
    mode="enabled",
    allowed_types=["Folder", "Image"],
    immediately_addable_types=[
        "Image",
    ],
)

# Constrains now enabled
assert constrains.mode == "enabled"

# Folder and Image are allowed to be added to obj
assert "Folder" in constrains.allowed_types
assert "Image" in constrains.allowed_types

# Image is a prefered type to be added to obj
assert "Image" in constrains.immediately_addable_types

api.content.serialize

Serialize an object, using the serializers defined in plone.restapi.

Example:

from kitconcept import api


portal = api.portal.get()
data = api.content.serialize(portal)

# data is a dictionary
assert isinstance(data, dict)

# We have the serialized info
assert data["@type"] == "Plone Site"
assert data["id"] == "plone"
assert data["title"] == "Site"

Inclusion of api.fti

api.fti.get_types

Return a dictionary with all FTI's registered for the Portal.

Example:

from kitconcept import api
from plone.dexterity.fti import DexterityFTI


ftis = api.fti.get_types()

# Dictionary with FTI
assert isinstance(ftis, dict)
# Document FTI should be present
assert "Document" in ftis
assert isinstance(ftis["Document"], DexterityFTI)

api.fti.get

Return a FTI for a type.

Example:

from kitconcept import api
from plone.dexterity.fti import DexterityFTI


fti = api.fti.get(type="Document")

# FTI for Document content type
assert isinstance(fti, DexterityFTI)
assert fti.id == "Document

api.fti.behaviors_for_type

Return a list of behaviors for a type.

Example:

from kitconcept import api
from plone.dexterity.fti import DexterityFTI


behaviors = api.fti.behaviors_for_type(type="Document")

# List of behaviors for Document
assert isinstance(behaviors, list)
assert "plone.dublincore" in behaviors

api.fti.get_behavior_registration

Return a list of behaviors for a type.

Example:

from kitconcept import api
from plone.behavior.registration import BehaviorRegistration


behavior = api.fti.get_behavior_registration(name="plone.dublincore")

# Behavior registration info
assert isinstance(behavior, BehaviorRegistration)
assert behavior.title == "Dublin Core metadata"

api.fti.add_behavior_for_type

Adds the given behavior to the given portal type.

Example:

from kitconcept import api

api.fti.add_behavior_for_type("Document", "plone.leadimage")
behaviors = api.fti.behaviors_for_type(type="Document")

# List of behaviors for Document
assert isinstance(behaviors, list)
assert "plone.leadimage" in behaviors

api.fti.remove_behavior_for_type

Removes the given behavior from the given portal type.

Example:

from kitconcept import api

api.fti.remove_behavior_for_type("Document", "plone.allowdiscussion")
behaviors = api.fti.behaviors_for_type(type="Document")

# List of behaviors for Document
assert isinstance(behaviors, list)
assert "plone.allowdiscussion" not in behaviors

Inclusion of api.vocabulary

api.vocabulary.get_vocabulary_names

Return a list of names for all vocabularies

Example:

from kitconcept import api


vocabularies = api.addon.get_vocabulary_names()

# List of str
assert isinstance(vocabularies, list)
assert isinstance(vocabularies[0], str)
assert "plone.app.vocabularies.Month" in vocabularies

api.vocabulary.get

Get one vocabulary.

Example:

from kitconcept import api
from zope.schema.vocabulary import SimpleVocabulary


# Return one vocabulary
vocabulary = api.vocabulary.get("plone.app.vocabularies.Month")
assert isinstance(vocabulary, SimpleVocabulary)
assert vocabulary.getTerm(0).title == "month_jan"

Wish List

  • api.concent.deserialize
  • plone.app.multilingual: Translations management

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

kitconcept.api-1.0.0a4.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

kitconcept.api-1.0.0a4-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file kitconcept.api-1.0.0a4.tar.gz.

File metadata

  • Download URL: kitconcept.api-1.0.0a4.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.12

File hashes

Hashes for kitconcept.api-1.0.0a4.tar.gz
Algorithm Hash digest
SHA256 c93623da5cc63773961a5f99f1671c031a5abadd733933744a4613f7e53e9ba7
MD5 65d6f89036022355781c56c8e426b884
BLAKE2b-256 e2b4d5a49387a140d6c5fa338d7a7a6cceef641b54c0eb91a85c1be0065da325

See more details on using hashes here.

File details

Details for the file kitconcept.api-1.0.0a4-py3-none-any.whl.

File metadata

File hashes

Hashes for kitconcept.api-1.0.0a4-py3-none-any.whl
Algorithm Hash digest
SHA256 7588ea2e04100e2c9ee5d1e91a97ea2e5d6398006c91cbc319656869960807a6
MD5 7620be74b9af9a159cd33690eb7477f3
BLAKE2b-256 2299bcc4f1b2b384d44bf02f40a647fa5856eb274e6412a4611233f4f2bba6ee

See more details on using hashes here.

Supported by

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