{ "info": { "author": "Juan Gutierrez", "author_email": "UNKNOWN", "bugtrack_url": null, "classifiers": [], "description": "Django REST Framework SaaS Plugin\n=================================\n\n### Overview\n\nThis is a SaaS driven plugin for Django REST Framework. It offers a simple way\nto separate client customizations for your core API web services. Currently, this\ninitial version only supports client API routing via ViewSets in conjunction with\nan extension of the Django REST Framework SimpleRouter. Future releases will\nhave broader coverage of DRF features for custom client routing.\n\n### Install\n```pip install djangorestframework-saasy```\n\n### Requirements\n- Python (2.7)\n- Django (1.4.2+)\n- Django rest framework (2.3.14+)\n\n### Example\n\nDefine the client model in your django rest framework settings:\n```python\nREST_SETTINGS = {\n ...\n \"SAAS\": {\n \"MODEL\": \"path.to.model.ClientModel\"\n }\n ...\n}\n```\n\nUse the saas client mixin provided by the SaaS plugin, and define the required class methods:\n```python\nfrom django.db import models\nfrom rest_framework_saasy.client import ClientMixin\n\n\nclass ClientModel(models.Model, ClientMixin):\n \"\"\"client model\"\"\"\n name = models.CharField(max_length=128)\n\n @staticmethod\n def saas_lookup_field():\n \"\"\"DRF-SaaS lookup field definition\"\"\"\n return 'name'\n\n def saas_client_module(self, saas_url_kw, *args, **kwargs):\n return 'customizations.{}'.format(self.name)\n```\n\n#### ClientMixin methods\n\n- *saas_lookup_field* **[required]**\n\n This method defines what field in your client model to use when looking up\n the client in the database, to verify they exist.\n\n- *saas_client_module* **[required]**\n\n Parameters:\n - *saas_url_kw* - [string] - value from URL key word argument - the client\n idenfitication value.\n\n All client code should be separated from the core and also from each other.\n A good practice to follow is that there is a folder for all client specific code,\n separate from the core, with a folder for each client. That said, you can impose\n any kind of path rules you wish.\n \n ```\n project\n \u251c\u2500\u2500 customizations\n \u2502 \u2514\u2500\u2500 client_name\n \u2502 \u2514\u2500\u2500 app\n \u2502 \u2514\u2500\u2500 subpackage\n \u2502 \u2514\u2500\u2500 module.py\n \u2514\u2500\u2500 app\n \u2514\u2500\u2500 subpackage \n \u2514\u2500\u2500 module.py\n ```\n\n### ViewSets\n\nThe idea is there is a core web service ViewSet, *WebService*, defined \nin **app.subpackage.module** and in **customizations.client_name.app.subpackage.module** \nwhere there is also a class named *WebService*\n\n**app.subpackage.module**\n```python\nfrom rest_framework import viewsets\nfrom rest_framework_saasy import viewsets as saas_viewsets\n\nfrom .models import WebServiceModel\nfrom .serializers import WebServiceSerializer\n\nclass WebService(saas_viewsets.ViewSetMixin, viewsets.ModelViewSet):\n queryset = WebServiceModel.objects.all()\n serializer_class = WebServiceSerializer\n```\n\n**customizations.client.app.subpackage.module**\n```python\nfrom app.subpackage.module import WebService as CoreWebService\n\nclass WebService(CoreWebService):\n # client customizations\n```\n\nYou can define the module path of client code and you can also define the subpackage\npath for the ViewSet mixed with the *saas_viewsets.ViewSetMixin*.\n\nWhat cannot be customized is the name of the class - the class name *WebService* in the\ncore must be defined identically in the client custom module.\n\n#### ViewSetMixin methods\n\n- *saas_module* **[optional]**\n\n By default, viewset will be routed in a similar way as in the diagram above:\n \n ```\n project\n \u251c\u2500\u2500 customizations\n \u2502 \u2514\u2500\u2500 client_name\n \u2502 \u2514\u2500\u2500 app\n \u2502 \u2514\u2500\u2500 subpackage\n \u2502 \u2514\u2500\u2500 module.py\n \u2514\u2500\u2500 app\n \u2514\u2500\u2500 subpackage \n \u2514\u2500\u2500 module.py\n ```\n \n However, the SaaS viewset has an optional method that can be defined, *saas_module*\n This returns the path that should be used in the client package. **It must be \n defined with the staticmethod decorator.** Let's slightly alter our *WebService* example above:\n \n ```python\n class WebService(saas_viewsets.ViewSetMixin, viewsets.ModelViewSet):\n ...\n @staticmethod\n def saas_module():\n return 'other.package.name'\n ```\n \n The expected file system package defintion for *WebService* customizations would be:\n \n ```\n project\n \u251c\u2500\u2500 customizations\n \u2502 \u2514\u2500\u2500 client_name\n \u2502 \u2514\u2500\u2500 other\n \u2502 \u2514\u2500\u2500 package\n \u2502 \u2514\u2500\u2500 name.py\n \u2514\u2500\u2500 app\n \u2514\u2500\u2500 subpackage \n \u2514\u2500\u2500 module.py\n ```\n\n#### ViewSet attributes\n\n*saas_url_kw* is a new attribute made available to the ViewSet instance. \nThe value of the valid identifier from the URL key word argument can be \naccessed at any time. If no client specific route was used, *saas_url_kw*\ndefaults to None.\n\n### SaaS SimpleRouter\n\nYou'll register your new SaaSy viewsets in exactly the same way Django\nREST Framework defines.\n\n#### app.urls\n```python\nfrom rest_framework_saasy import routers\nfrom .views import NoteViewSet\n\n\nrouter = routers.SimpleRouter()\nrouter.register(r'notes', NoteViewSet)\n```\n\nClient specific routes will be made available immediately:\n```\n^notes/$ [name='note-list']\n^notes/(?P[^/]+)/$ [name='note-detail']\n^(?P.*)/notes/$ [name='note-list']\n^(?P.*)/notes/(?P[^/]+)/$ [name='note-detail']\n```\n\n**Note:** If a client key word argument is provided, but the client cannot\nbe retreived from the database with the given identifier, the\nplugin will simply return a 404.\n\nLicense\n=======\nThe MIT License (MIT)\n\nCopyright (c) 2014 Juan Gutierrez\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/juannyg/django-rest-framework-saasy", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "djangorestframework-saasy", "package_url": "https://pypi.org/project/djangorestframework-saasy/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/djangorestframework-saasy/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/juannyg/django-rest-framework-saasy" }, "release_url": "https://pypi.org/project/djangorestframework-saasy/0.1/", "requires_dist": null, "requires_python": null, "summary": "SaaS plugin for the django rest framework", "version": "0.1" }, "last_serial": 1200935, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "a7c5c078219d8ffb8ce3d46b68456983", "sha256": "ae7e3d96e5959f5fdcc5fbe6870ed691489889f5bf1fa860dbc8ef6dcdf7e24c" }, "downloads": -1, "filename": "djangorestframework-saasy-0.1.tar.gz", "has_sig": false, "md5_digest": "a7c5c078219d8ffb8ce3d46b68456983", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13407, "upload_time": "2014-08-25T03:35:13", "url": "https://files.pythonhosted.org/packages/64/68/77792f339d7e9ab7b2a0e397e36474fa3159eb87651974ac2f7db406cb01/djangorestframework-saasy-0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a7c5c078219d8ffb8ce3d46b68456983", "sha256": "ae7e3d96e5959f5fdcc5fbe6870ed691489889f5bf1fa860dbc8ef6dcdf7e24c" }, "downloads": -1, "filename": "djangorestframework-saasy-0.1.tar.gz", "has_sig": false, "md5_digest": "a7c5c078219d8ffb8ce3d46b68456983", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13407, "upload_time": "2014-08-25T03:35:13", "url": "https://files.pythonhosted.org/packages/64/68/77792f339d7e9ab7b2a0e397e36474fa3159eb87651974ac2f7db406cb01/djangorestframework-saasy-0.1.tar.gz" } ] }