{ "info": { "author": "Martin Brochhaus", "author_email": "mbrochh@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "Django Forms Ajaxified\n======================\n\nA reusable Django app that allows to submit forms via AJAX.\n\n**This is useful for two usecases:**\n\n1. You have a very long form and you want to signal to your users that each\n field they fill out is saved immediately and you want to show validation\n errors immediately.\n2. You have a number of different forms that all have their own small\n AJAX-views and partial templates and you all include them in one bigger\n template. Each form should be able to communicate with it's own AJAX-view\n independently.\n\n**Features:**\n\n1. Error messages are displayed next to the field, when they happen\n2. A visual indicator is displayed on the field that has just been changed to\n indicate that this value has been saved.\n\n\nInstallation\n------------\n\nTo get the latest stable release from PyPi\n\n.. code-block:: bash\n\n pip install django-forms-ajaxified\n\nTo get the latest commit from GitHub\n\n.. code-block:: bash\n\n pip install -e git+git://github.com/bitmazk/django-forms-ajaxified.git#egg=forms_ajaxified\n\nAdd ``forms_ajaxified`` to your ``INSTALLED_APPS``\n\n.. code-block:: python\n\n INSTALLED_APPS = (\n ...,\n 'django_libs',\n 'forms_ajaxified',\n )\n\nAdd ``django_libs.middleware.AjaxRedirectMiddleware`` to your\n``MIDDLEWARE_CLASSES``\n\n.. code-block:: python\n\n MIDDLEWARE_CLASSES = [\n 'django.middleware.common.CommonMiddleware',\n 'django.contrib.sessions.middleware.SessionMiddleware',\n 'django.middleware.csrf.CsrfViewMiddleware',\n 'django.contrib.auth.middleware.AuthenticationMiddleware',\n 'django.contrib.messages.middleware.MessageMiddleware',\n ...\n 'django_libs.middleware.AjaxRedirectMiddleware',\n ]\n\nIn your ``base.html`` include the jQuery plugin that loads your forms and\nhandles the AJAX responses. You should place it somewhere below your jQuery\ninclude:\n\n.. code-block:: html\n\n {% load staticfiles %}\n ...\n \n \n\nAt the bottom of your ``base.html`` or whereever you run global\ninitialisations, activate the jQuery plugin:\n\n.. code-block:: html\n\n \n\nIf you are using Bootstrap, you can add a green border around an input element\nvia CSS transitions similar to the blue border when the element is focused.\nSimply add the following to your project's styles:\n\n.. code-block:: less\n\n input.success, textarea.success, select.success {\n @color-rgba: rgba(red(@brand-success), green(@brand-success), blue(@brand-success), .6);\n border-color: @color-rgba;\n .box-shadow(~\"inset 0 1px 1px rgba(0,0,0,.075), 0 0 8px @{color-rgba}\");\n }\n\nUsage\n-----\n\nThis example assumes that you have a big ``TemplateView`` that contains one\nor more small partial templates with forms. You could just as well just use\none big ``FormView``, as usual.\n\nFirst you should write a TemplateView that renders the whole template and\nreserves some space for its one or many forms to be loaded:\n\n.. code-block:: python\n\n from django.views.generic import TemplateView\n\n class MyTemplateView(TemplateView):\n template_name = 'myapp/my_template_view.html'\n\nThe template for this view should look something like this:\n\n.. code-block:: html\n\n {% extends \"base.html\" %}\n
\n\nAs you can see, the form is empty but thanks to the ``data-class`` attribute,\nour jQuery plugin will be able to find all such forms on your template. It will\nread the ``action`` attribute and send an AJAX GET request to the ``action``\nview and initially retrieve the returned partial.\n\nNow you should write a simple Form and a FormView that returns the partial\ntemplate that renders this form. By adding the ``AjaxFormViewMixin`` you\nenable your view to return proper JSON responses when handling POST requests.\nWe only show a code snippet for one such FormView but you could have many of\nthem and load them all in a TemplateView that ties everything together:\n\n.. code-block:: python\n\n from django.views.generic import FormView\n from forms_ajaxified.views import AjaxFormViewMixin\n from myapp.forms import MyForm\n\n class MyFormView(AjaxFormViewMixin, FormView):\n form_class = MyForm\n template_name = 'myapp/partials/my_form.html'\n\nThe partial template for your form should look something like below. Note that\nthe template does not contain a ``form`` tag because we already have that in\nthe \"outer\" template of the TemplateView above:\n\n.. code-block:: html\n\n {% for field in form %}\n {% include \"django_libs/partials/form_field.html\" %}\n {% endfor %}\n \n\nIf everything is setup correctly, the jQuery plugin will initially load all\nforms and then monitor all changes in their fields. On every data change, it\nwill send a POST request to the corresponding AJAX-view. If validation errors\nhappen, they will appear next to their fields. If data was saved successfully,\na visual indicator will inform the user about this. In theory, the form would\nnot even need a submit button, it is up to the developer to decide if it should\nbe there or not.\n\nRedirecting\n-----------\n\nSometimes a successful POST to your form changes thing so drastically that\nyou need to redirect to another page (i.e. when you change the title of an\nobject, which also changes it's slug and you need to redirect to a new URL with\nthe new slug).\n\nIn this case, please add the following hidden input to your form:\n\n.. code-block:: html\n\n \n\nMake sure that you have the ``AjaxRedirectMiddleware`` in your\n``MIDDLEWARE_CLASSES`` setting. Now your form will always redirect on a\nsuccessful submit.\n\nIf you want your form to only redirect in certain situations (i.e. only\nwhen the slug has been changed), you can do something like this in your view:\n\n.. code-block:: python\n\n class MyFormView(AjaxFormViewMixin, FormView):\n def form_valid(self, form):\n form_valid_redirect = self.request.POST.get('form_valid_redirect')\n if some_condition:\n form_valid_redirect = False\n return super(MyFormView, self).form_valid(\n form, form_valid_redirect=form_valid_redirect)\n\nAs you can see, the ``form_valid`` implementation of ``AjaxFormViewMixin``\nallows an additional kwarg ``form_valid_redirect``. When you don't pass in that\nkwarg, the mixin will try to get that value from the POST data (from your\nhidden field) but when you pass in that kwarg, it will override the POST data.\n\n\njQuery Plugin Options\n---------------------\n\nThe jQuery plugin supports the following options:\n\ndefault_loading_text\n++++++++++++++++++++\n\nDefault: `Submitting...`\n\nSet this if you want to use a different text to be shown on submit buttons when\nsubmitting the form. The original button text will be replaced with this one\nand the button will be disabled. When the request returns, the changes will\nbe undone.\n\njQuery Plugin Data Attributes\n-----------------------------\n\nThe following data attributes allow to adjust the behaviour of the plugin:\n\ndata-id=\"form_ajaxified\"\n++++++++++++++++++++++++\n\nSet this attribute on all forms that should be controlled by this app.\n\ndata-loading-text=\"Loading...\"\n++++++++++++++++++++++++++++++\n\nSet this attribute on submit buttons that should have special loading texts.\nThis overrides the plugin option `default_loading_text`.\n\ndata-autosave=\"1\"\n+++++++++++++++++\n\nSet this attribute on input elements and they will trigger a form submit every\n15 seconds.\n\ndata-autosave-interval=\"1000\"\n+++++++++++++++++++++++++++++\n\nSet this attribute alongside `data-autosave` to override the default interval\nof 15 seconds. The value represents milliseconds.\n\ndata-ajax-add-wrapper=\"[data-id='some-element']\"\n++++++++++++++++++++++++++++++++++++++++++++++++\n\nIf you have an \"Add item\" button somewhere on your page that should create\na new item and display a new partial form to edit that new item, you can\nadd this attribute to the button element. The value of the attribtue should\nbe a selector that selects the wrapper element that should get the new form\npartial appended.\n\ndata-ajax-delete-element=\"[data-id='some-element']\"\n+++++++++++++++++++++++++++++++++++++++++++++++++++\n\nIf you have \"Delete item\" buttons on your page that should delete a form\npartial from your page, you can add this attribute to the button element. The\nvalue of the attribtue should be a selector that selects the element that\nshould be deleted. The form that contains the delete button will be deleted as\nwell.\n\nContribute\n----------\n\nIf you want to contribute to this project, please perform the following steps\n\n.. code-block:: bash\n\n # Fork this repository\n # Clone your fork\n mkvirtualenv -p python2.7 django-forms-ajaxified\n make develop\n\n git co -b feature_branch master\n # Implement your feature and tests\n git add . && git commit\n git push -u origin feature_branch\n # Send us a pull request for your feature branch", "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/bitmazk/django-forms-ajaxified", "keywords": "django,app,reusable,forms,ajax", "license": "The MIT License", "maintainer": null, "maintainer_email": null, "name": "django-forms-ajaxified", "package_url": "https://pypi.org/project/django-forms-ajaxified/", "platform": "OS Independent", "project_url": "https://pypi.org/project/django-forms-ajaxified/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/bitmazk/django-forms-ajaxified" }, "release_url": "https://pypi.org/project/django-forms-ajaxified/0.2/", "requires_dist": null, "requires_python": null, "summary": "A reusable Django app that allows to load and submit forms via AJAX.", "version": "0.2" }, "last_serial": 2072331, "releases": { "0.1": [], "0.1.1": [ { "comment_text": "", "digests": { "md5": "aac9449da90a7e202eec2379a95f35cf", "sha256": "d92d9035e669b1ed47ef9094a43bad6374eca31ed863222fa27277494f8349cd" }, "downloads": -1, "filename": "django-forms-ajaxified-0.1.1.tar.gz", "has_sig": false, "md5_digest": "aac9449da90a7e202eec2379a95f35cf", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 51328, "upload_time": "2014-12-24T10:46:14", "url": "https://files.pythonhosted.org/packages/11/42/cc16ee7b4b947212e3e4cca8abf4fd6efdc3957911af24ed2f0269995375/django-forms-ajaxified-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "11704043ed014a329016de4997cbe699", "sha256": "995e49a773a42de1553da790c832dc20497f8ad7f5b7e604521846f9792bd549" }, "downloads": -1, "filename": "django-forms-ajaxified-0.1.2.tar.gz", "has_sig": false, "md5_digest": "11704043ed014a329016de4997cbe699", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 53265, "upload_time": "2015-02-25T01:06:19", "url": "https://files.pythonhosted.org/packages/cc/f4/eb5b79f5c67fef55f94e4db84b1edce7432875ca4937b5dfb35399788ab8/django-forms-ajaxified-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "047aaf27a248a6104ba52e7c90f03188", "sha256": "5f767571b6adaa9000c82b11c54ee7e10f4440a2335177cd3a1ca8ace1313cd5" }, "downloads": -1, "filename": "django-forms-ajaxified-0.1.3.tar.gz", "has_sig": false, "md5_digest": "047aaf27a248a6104ba52e7c90f03188", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 54477, "upload_time": "2015-02-25T02:14:52", "url": "https://files.pythonhosted.org/packages/af/5f/c8b6218bd0fa2f55a3c49fc9da5e7383131b886ec64659ed94de5a5fe0ce/django-forms-ajaxified-0.1.3.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "6fc836059af466d9adca77976727796e", "sha256": "ada016fe25788286dcc877f775566e1221f15aec3f0e51cf744a7191eb8aec38" }, "downloads": -1, "filename": "django-forms-ajaxified-0.2.tar.gz", "has_sig": false, "md5_digest": "6fc836059af466d9adca77976727796e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 51836, "upload_time": "2016-04-19T20:07:26", "url": "https://files.pythonhosted.org/packages/23/fb/28ac90415e9de7967cc975d173faa78157535f3538362cf40d2fec52ac89/django-forms-ajaxified-0.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "6fc836059af466d9adca77976727796e", "sha256": "ada016fe25788286dcc877f775566e1221f15aec3f0e51cf744a7191eb8aec38" }, "downloads": -1, "filename": "django-forms-ajaxified-0.2.tar.gz", "has_sig": false, "md5_digest": "6fc836059af466d9adca77976727796e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 51836, "upload_time": "2016-04-19T20:07:26", "url": "https://files.pythonhosted.org/packages/23/fb/28ac90415e9de7967cc975d173faa78157535f3538362cf40d2fec52ac89/django-forms-ajaxified-0.2.tar.gz" } ] }