{ "info": { "author": "secnot", "author_email": "UNKNOWN", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 1.9", "Intended Audience :: Developers", "License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Topic :: Internet :: WWW/HTTP", "Topic :: Utilities" ], "description": "django-param-field\n==================\n\nA Django model field that uses a DSL to define, generate, and validate,\ncustom forms.\n\n**ParamField** allows you to store something like this:\n\n.. code:: bash\n\n width: Decimal -> max:50.0 min:5.0\n height: Decimal -> max:40.0 min:3.0\n painted : Bool-> default:False\n inscription: Text-> max_length:30\n\nand generate the django equivalent form as needed:\n\n.. code:: python\n\n from django import forms\n\n class CustomForm(forms.Form):\n width = forms.DecimalField(max_value=50, min=5)\n height = forms.DecimalField(max_valur=40, min=3)\n painted = forms.BooleanField()\n inscription = forms.CharField(max_length=30)\n\nThis is useful for creating user defined forms, or custom per models\nforms.\n\nRequirement\n-----------\n\nIt has been tested on\n\n- Python 3\n- Django 1.9, 1.10\n\nInstallation\n------------\n\nFrom the repository\n\n.. code:: bash\n\n $ git clone https://github.com/secnot/django-param-field\n $ python setup.py install\n\nor from pypi\n\n.. code:: bash\n\n $ pip intall django-param-field\n\nUsage\n-----\n\nAdd param\\_field to INSTALLED\\_APPS\n\n.. code:: python\n\n # settings.py\n INSTALLED_APPS = [\n ...\n 'param_field',\n ]\n\nAdd the field to your model:\n\n.. code:: python\n\n # models.py\n from djang.db import models\n from param_field import ParamField, ParamDict\n\n class CustomProduct(models.Model):\n name = models.CharField(max_length=44)\n ...\n params = ParamField(blank=True, max_length=3000)\n\nNow that you have a working model to create a new instance with its\nparameters write:\n\n.. code:: python\n\n params = \"\"\"\n width: Dimmension-> max:50.0 min:5.0\n height: Dimmension-> max:40.0 min:3.0\"\"\"\n\n CustomProduct.objects.create(\n name='Custom wooden box\",\n params=params)\n\nAnd the FormView that generates the forms from the model\n\n.. code:: python\n\n # views.py\n from django.shortcuts import render, get_object_or_404\n from django.views.generic import FormView\n from django import forms\n from .models import CustomProduct\n\n class CustomProductFormView(FormView):\n template_name = 'product_form.html'\n form_class = forms.Form\n\n def dispatch(self, request, *args, **kwargs):\n \"\"\"Find requested CustomProduct it's needed both in post and get \n requests so the form can be genereted\"\"\"\n pk = self.kwargs['pk']\n self.product = get_object_or_404(CustomProduct, pk=pk)\n return super().dispatch(request, *args, **kwargs)\n \n def get_context_data(self, **kwargs):\n \"\"\"Send product info to template\"\"\"\n context = super().get_context_data(**kwargs)\n context['product'] = self.product\n return context\n\n def get_form(self, form_class=None):\n \"\"\"Generate form form param_field\"\"\"\n # NOTE: params.form(...) will return None when it doesn't\n # containt any field.\n return self.product.params.form(**self.get_form_kwargs())\n\n def form_valid(self, form):\n \"\"\"Do what ever you want with the form, at this point it's a\n validated django form like any other\"\"\"\n custom_parameters = form.cleaned_data\n ...\n\nRead this `blog\npost `__ for a longer\ntutorial that includes an example on how to handle File and Image\nfields.\n\nSyntax\n------\n\nEach ParamField can have one or more fields with the following syntax\n\n.. code:: bash\n\n fieldname: type-> property: value\n\n- **fieldname** - A lowercase name starting with a letter and followed\n by letters, numbers, and/or underscores. The default max name length\n is 30 characters.\n\n- **type** - One of the supported field types (All starting with\n uppercase)\n\n - Bool\n - Decimal\n - Dimmension\n - Integer\n - Text\n - TextArea\n - File\n - Image\n\n- **property** - One or more of the properties supported by the field\n type followed by a value.\n\n - ALL: hidden. required, label, help\\_text\n - Bool: default\n - Integer: default, even, odd, max, min, choices\n - Decimal: default, max, min, choices, max\\_digits, max\\_decimals\n - Text: default, max\\_length, min\\_length, choices\n - TextArea: default, max\\_length\n - File: (doesn't support hidden)\n - Image: (doesn't support hidden)\n\n- **value** - One of the value types supported by the property to its\n left\n\n - Boolean - True/False\n - Decimal - 1.33, 6.44\n - Integer - 44\n - String - \"string with scape \\\\\"chars\\\\\" \"\n - Value list - [value, value, value]\n\nConfiguration\n-------------\n\nThe absolute limits for the fields properties are configurable through\n**settings.py**, for example **PARAM\\_INT\\_MAX** controls the max\nallowed value for integer **max** property, so creating a new Integer\nfield where **max** is bigger will fail.\n\nThese are the available options with their default value:\n\n.. code:: python\n\n # settings.py\n\n # Max lengths for label and help_text strings\n PARAM_LABEL_MAX_LENGTH = 40\n PARAM_HELP_TEXT_MAX_LENGTH = 200\n PARAM_NAME_MAX_LENGTH = 30\n\n # Max and Min integer values, these have been chosen so integers don't cause\n # problems when stored in any DB\n PARAM_INT_MAX = 2147483647\n PARAM_INT_MIN = -2147483648\n\n # The maximum number of digits allowed and the max decimal places\n PARAM_DECIMAL_MAX_DIGITS = 20\n PARAM_DECIMAL_MAX_DECIMALS = 4\n\n # Decimal max and min (must have valid number of digits/decimals)\n PARAM_DECIMAL_MAX = Decimal(\"9999999999999999.9999\") \n PARAM_DECIMAL_MIN = Decimal(\"-9999999999999999.9999\")\n\n # Dimmension digits/decimals\n PARAM_DIMMENSION_MAX_DIGITS = 12\n PARAM_DIMMENSION_MAX_DECIMALS = 4\n\n # Dimmension max and min\n PARAM_DIMMENSION_MAX = Decimal(\"99999999.9999\")\n PARAM_DIMMENSION_MIN = Decimal(\"0.0\")\n\n # Text/TextArea max length\n PARAM_TEXT_MAX_LENGTH = 300\n\n # max_length used by ParamField when it isn't supplied\n PARAM_FIELD_MAX_LENGTH = 3000\n\nTesting\n-------\n\nOnce the app has been added to settings.py, you can run the tests with:\n\n.. code:: bash\n\n $ python manage.py test param_field\n\nReferences\n----------\n\n- `Domain speficific languages python\n slide `__\n- `Small django-param-field\n tutorial `__ with a\n longer example than the one in this README.\n\nTODO\n----\n\n- Better parser error messages", "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/secnot/django-param-field", "keywords": "django,dsl,model,field,pyparsing", "license": "LPGL, see LICENSE file.", "maintainer": null, "maintainer_email": null, "name": "django-param-field", "package_url": "https://pypi.org/project/django-param-field/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-param-field/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/secnot/django-param-field" }, "release_url": "https://pypi.org/project/django-param-field/0.4.0/", "requires_dist": null, "requires_python": null, "summary": "A Django model field that uses a DSL to define, generate, and validate, custom forms", "version": "0.4.0" }, "last_serial": 2536876, "releases": { "0.2": [ { "comment_text": "", "digests": { "md5": "b557f26bea20dea828f17475f0d8e603", "sha256": "69259a7253deb63eaef10cbcf52515ac4a2e08bc399fb4704decf9fbe772627c" }, "downloads": -1, "filename": "django-param-field-0.2.tar.gz", "has_sig": false, "md5_digest": "b557f26bea20dea828f17475f0d8e603", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 20589, "upload_time": "2016-12-12T18:32:43", "url": "https://files.pythonhosted.org/packages/41/53/f780b6949c732671d415081a1fd149fa08015195e649ea92b277d4520b2f/django-param-field-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "0dd843575e7d8754373aa76f5fe83330", "sha256": "158f6e99df6902e8c4610398a1f72fc261266f584de89a03cbeb154f2c2286ca" }, "downloads": -1, "filename": "django-param-field-0.3.tar.gz", "has_sig": false, "md5_digest": "0dd843575e7d8754373aa76f5fe83330", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21302, "upload_time": "2016-12-14T15:18:48", "url": "https://files.pythonhosted.org/packages/57/51/f63c7c81a48cc48f74f51b6b4f5b35335f2e0deb595f0179412784706ee9/django-param-field-0.3.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "58cb14a8192a4686c44cac4767406a28", "sha256": "da01e9330bfa08eb2a80722613ef124695d8a9532c54574d4d2a04485286646d" }, "downloads": -1, "filename": "django-param-field-0.3.1.tar.gz", "has_sig": false, "md5_digest": "58cb14a8192a4686c44cac4767406a28", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23691, "upload_time": "2016-12-18T20:36:57", "url": "https://files.pythonhosted.org/packages/5f/a0/d9a6257aaf9998386a3acde4cdf196052a51650ff00bdc288e6da000153a/django-param-field-0.3.1.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "818f4eedc2aedf3a381b109f9daecafd", "sha256": "7d9cd5cb92f6812fc75d8f59a7230ffd6d7018d1a013804507bcc600b8522799" }, "downloads": -1, "filename": "django-param-field-0.4.0.tar.gz", "has_sig": false, "md5_digest": "818f4eedc2aedf3a381b109f9daecafd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27007, "upload_time": "2016-12-23T15:56:17", "url": "https://files.pythonhosted.org/packages/e3/83/99deb352ea77c7f53a2ec5cd158e4b542d7c4a8418a0b93498c1ceaba1ef/django-param-field-0.4.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "818f4eedc2aedf3a381b109f9daecafd", "sha256": "7d9cd5cb92f6812fc75d8f59a7230ffd6d7018d1a013804507bcc600b8522799" }, "downloads": -1, "filename": "django-param-field-0.4.0.tar.gz", "has_sig": false, "md5_digest": "818f4eedc2aedf3a381b109f9daecafd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 27007, "upload_time": "2016-12-23T15:56:17", "url": "https://files.pythonhosted.org/packages/e3/83/99deb352ea77c7f53a2ec5cd158e4b542d7c4a8418a0b93498c1ceaba1ef/django-param-field-0.4.0.tar.gz" } ] }