{ "info": { "author": "Phoenix Chen", "author_email": "phoenix0722chen@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# ContentfulORM\n***\nA Python toolkit for [Contentful](https://www.contentful.com/) to let you create/maintain your Content Type and queries in ORM style.\n\n## Install\n***\n- To install:\n ```\n pip install git+https://github.com/Phoenix-Chen/ContentfulORM.git\n ```\n\n## Usage\n***\n\n### ORM Environment\n***\n- Create an ORM Environment:\n ```python\n import contentful_management\n from contentful_orm import ORMEnvironment\n\n # First create an contentful_management.environment.Environment\n client = contentful_management.Client('CONTENTFUL_MANAGEMENT_TOKEN')\n space = client.spaces().find('CONTENTFUL_SPACE_ID')\n environment = space.environments().find('CONTENTFUL_ENVIRONMENT')\n\n # Then create ORMEnvironment use contentful_management.environment.Environment\n orm_env = ORMEnvironment.from_parent(environment)\n ```\n\n### Content Type Model\n***\n- Model your content type:\n ```python\n from datetime import datetime\n from contentful_orm.models import Model\n from contentful_orm.fields import ArrayField, BooleanField, DateField, DecimalField, IntegerField, MediaField, ReferenceField, SymbolField, TextField, LocationField\n from contentful_orm.fields.validations import In, Range, Unique, Size, Regex, ImageDimensions, FileSize\n\n # class name will become content type name\n # class name in camel case will become content type id\n class Person(Model):\n # docstring will become content type description\n \"\"\"Person model description\n \"\"\"\n __display_field__ = 'name'\n\n # Each field need to be a {SomeType}Field from contentful_orm.fields\n # Most of the fields have keyword argument: disabled, localized, omitted, required, validations and default\n # (disabled, localized, omitted and required default to False. validations defaults to []. default defaults to None)\n email = SymbolField(validations=[Unique, Regex('^\\\\w[\\\\w.-]*@([\\\\w-]+\\\\.)+[\\\\w-]+$', error_msg='Invalid email address.')], required=True)\n name = SymbolField(localized=True, required=True)\n # ArrayField takes an argument to specify content type\n title = ArrayField(SymbolField(validations=[In(['Manager', 'Seller'], error_msg='Invalid title')]), localized=True)\n age = IntegerField(validations=[Range(min=1, error_msg='age must be a positive integer.')])\n created_date = DateField(default=datetime.now().strftime(\"%Y-%m-%dT%H:%M-00:00\"))\n\n class Company(Model):\n \"\"\"Company model description\n \"\"\"\n __display_field__ = 'name'\n\n name = SymbolField(validations=[Unique], required=True)\n employees = ArrayField(ReferenceField(model_set={Person}, error_msg='employee has to be a Person entry'))\n address = LocationField()\n\n class Product(Model):\n \"\"\"Product model description\n \"\"\"\n __display_field__ = 'name'\n\n name = SymbolField(validations=[Unique], required=True)\n description = TextField(localized=True)\n # ReferenceField takes an additional keyword argument model_set to restrict reference content type.\n # (Currently doesn't support reference to the content type itself)\n seller = ReferenceField(model_set={Person, Company}, error_msg=\"seller has to be a Person or Company entry\")\n images = ArrayField(\n MediaField(\n # validations takes a list of contentful_orm.fields.validations\n # See: https://www.contentful.com/r/knowledgebase/validations/ for details\n validations=[\n ImageDimensions(max_width=12, max_height=12),\n FileSize(max=40000, error_msg='Maximum file size is 40000 Bytes')\n ]),\n validations=[Size(max=10, error_msg=\"At most 10 images\")]\n )\n sponsored = BooleanField(required=True)\n price = DecimalField(required=True)\n ```\n- Create and publish the content type using model:\n ```python\n orm_env.create(Person).publish()\n # Or\n orm_env.create(Person)\n orm_env.publish(Person)\n ```\n- Unpublish and delete the content type using model:\n ```python\n orm_env.unpublish(Product)\n orm_env.delete(Product)\n ```\n- Add and publish entry:\n ```python\n person1 = orm_env.add(Person(email='a@a.com', name='a', title=['Manager', 'Seller'], age=13)).publish()\n # You can specify entry id or it will randomly generate a UUID\n person2 = orm_env.add(Person(email='b@a.com', name='b', title=['Seller'], age=66), id='S9SN3JWKN3565D').publish()\n person3 = orm_env.add(Person(email='c@a.com', name='c', title=['Manager'], created_date='2019-08-11T00:00-07:00')).publish()\n company1 = orm_env.add(Company(name='Contentful', employees=[person1.to_link().to_json(), person2.to_link().to_json()])).publish()\n # Or\n product1 = Product(\n name='ContentfulORM',\n description='Write your Contentful in ORM style!',\n seller=company1.to_link().to_json(),\n sponsored=True,\n price=0.01\n )\n orm_env.add(product1).publish()\n ```\n- Query:\n ```python\n # Query all entries of a content type\n orm_env.query(Person).all()\n\n # Filter query\n # ORMContentTypeEntriesProxy extends ContentTypeEntriesProxy with additional filter function\n from contentful_orm.operators import all_, limit, select, skip\n\n # Filter with field names as keyword arguments for exact search\n orm_env.query(Person).filter(email='c@a.com', name='c')\n\n # Filter with operators, see operators all at: https://github.com/Phoenix-Chen/ContentfulORM/blob/dev/contentful_orm/operators.py\n orm_env.query(Person).filter(all_(title=['Manager', 'seller']), skip(1), limit(100), select('fields.name'))\n\n # Use combination of both\n orm_env.query(Person).filter(limit(1), name='c')\n\n ```\n- Serialize:\n ```python\n from contentful_orm.serializers import ModelSerializer\n\n class ProductSerializer(ModelSerializer):\n class Meta:\n model = Product\n # Specify fields to be serialized or use '__all__' for all the fields\n fields = [\n 'name',\n 'description',\n 'price'\n ]\n\n # Query the entry/entries you want to serialize\n products = orm_env.query(Product).all()\n\n # Serialize single entry\n serialized_product = ProductSerializer(products[0])\n\n # Serialize multiple entries\n serialized_products = ProductSerializer(products, many=True)\n\n # Currently links won't be recursively serialized, in case of circular references.\n ```\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/Phoenix-Chen/ContentfulORM", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "contentful-orm", "package_url": "https://pypi.org/project/contentful-orm/", "platform": "", "project_url": "https://pypi.org/project/contentful-orm/", "project_urls": { "Homepage": "https://github.com/Phoenix-Chen/ContentfulORM" }, "release_url": "https://pypi.org/project/contentful-orm/0.1.0/", "requires_dist": [ "contentful-management", "python-baseconv" ], "requires_python": "", "summary": "A Python toolkit for Contentful to let you create/maintain your Content Type and queries in ORM style.", "version": "0.1.0" }, "last_serial": 5800795, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "f5223f779706a0a186452aed9bf6b259", "sha256": "21da6cddb80e5615c6a4e3acfe671e5aedd9445116299b094d537e168c5dc263" }, "downloads": -1, "filename": "contentful_orm-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "f5223f779706a0a186452aed9bf6b259", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11967, "upload_time": "2019-09-08T21:42:07", "url": "https://files.pythonhosted.org/packages/7f/9d/a0fc901656a67824d053a6b0e4f1e0cd4b6afee4934e47e7d17365013adb/contentful_orm-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e479c613a4fd5f456085abeccddc302b", "sha256": "472d8a396d68d235f6bcab7828b96872a42121e119b44a5b08c66bef95caabdc" }, "downloads": -1, "filename": "contentful_orm-0.1.0.tar.gz", "has_sig": false, "md5_digest": "e479c613a4fd5f456085abeccddc302b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11031, "upload_time": "2019-09-08T21:42:10", "url": "https://files.pythonhosted.org/packages/d4/6a/fa88080f4288246f40f90c82f8b53aebdbeeafa295a4c3d228a0a7c8eba3/contentful_orm-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "f5223f779706a0a186452aed9bf6b259", "sha256": "21da6cddb80e5615c6a4e3acfe671e5aedd9445116299b094d537e168c5dc263" }, "downloads": -1, "filename": "contentful_orm-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "f5223f779706a0a186452aed9bf6b259", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11967, "upload_time": "2019-09-08T21:42:07", "url": "https://files.pythonhosted.org/packages/7f/9d/a0fc901656a67824d053a6b0e4f1e0cd4b6afee4934e47e7d17365013adb/contentful_orm-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "e479c613a4fd5f456085abeccddc302b", "sha256": "472d8a396d68d235f6bcab7828b96872a42121e119b44a5b08c66bef95caabdc" }, "downloads": -1, "filename": "contentful_orm-0.1.0.tar.gz", "has_sig": false, "md5_digest": "e479c613a4fd5f456085abeccddc302b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11031, "upload_time": "2019-09-08T21:42:10", "url": "https://files.pythonhosted.org/packages/d4/6a/fa88080f4288246f40f90c82f8b53aebdbeeafa295a4c3d228a0a7c8eba3/contentful_orm-0.1.0.tar.gz" } ] }