{ "info": { "author": "Grzegorz T\u0119\u017cycki", "author_email": "grzegorz.tezycki@gmail.com", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Topic :: Utilities" ], "description": "django-popup-view-field\n------------------------\n\n.. image:: https://badge.fury.io/py/django-popup-view-field.svg\n :target: https://badge.fury.io/py/django-popup-view-field\n :alt: Latest PyPI version\n\n\n.. image:: https://travis-ci.org/djk2/django-popup-view-field.svg?branch=master\n :target: https://travis-ci.org/djk2/django-popup-view-field\n :alt: Travis CI\n\n\n.. image:: https://requires.io/github/djk2/django-popup-view-field/requirements.svg?branch=master\n :target: https://requires.io/github/djk2/django-popup-view-field/requirements/?branch=master\n :alt: Requirements Status\n\n\nField and widget can render bootstrap dialog with content from django view.\nYou can create normal django View and load this view in dialog for form field.\n\n- Support:\n\n * Python: 2.7, 3.6\n * Django: 1.8, 1.9, 1.10, 1.11, 2.0, 2.1\n * django-crispy-forms\n * django-bootstrap3\n\n- Require:\n\n * Django\n * bootstrap3\n * JQuery\n\n- Recommended:\n\n * django-bootstrap3 or\n * django-crispy-forms\n\n- Locale:\n\n * EN - (english)\n * PL - (polish)\n\n- Tested on browsers:\n\n * OK - Google Chrome 70.0 - Fedora 28\n * OK - Firefox 62.0.3 - Fedora 28\n * OK - Firefox 50.1.0 - Ubuntu 14.04\n * OK - Firefox 31.1 - CentOS 6.4\n * OK - Chromium 53.0 - Ubuntu 14.04\n * OK - Microsoft Edge 38 - Windows 10\n * OK - Internet Explorer 11.0 - Windows 10\n * OK - Internet Explorer 10.0 - Windows 7\n * OK - Internet Explorer 9.0 - Windows 7\n * ER - Internet Explorer <= 8 (no support \"html()\" for data-popup-view-value)\n\n\nScreenshots\n------------\n\n- Example: Form with several popup-view-fields\n\n.. image:: https://raw.githubusercontent.com/djk2/django-popup-view-field/master/doc/static/scr1.png\n :alt: Form with django-popup-view-fields\n\n- Example: Dialog for select sex\n\n.. image:: https://raw.githubusercontent.com/djk2/django-popup-view-field/master/doc/static/scr2.png\n :alt: Dialog for select sex\n\n- Example: Dialog for select color\n\n.. image:: https://raw.githubusercontent.com/djk2/django-popup-view-field/master/doc/static/scr3.png\n :alt: Dialog for select color\n\n- Example: Dialog with form\n\n.. image:: https://raw.githubusercontent.com/djk2/django-popup-view-field/master/doc/static/scr4.png\n :alt: Dialog with form\n\n\nRun demo\n---------\n1. Clone or download repository::\n\n git clone https://github.com/djk2/django-popup-view-field.git\n\n2. Create virtualenv or not (red more: http://docs.python-guide.org/en/latest/dev/virtualenvs/)\n\n3. Install requirements for demo::\n\n cd django-popup-view-field/demo\n\n pip install -r requirements.txt\n\n4. Run developing web server::\n\n python manage.py runserver\n\n5. Run your browser and call url: 127.0.0.1:8000 ::\n\n firefox 127.0.0.1:8000\n\n\nInstall\n--------\nInstall package - There are several solutions, choose your own\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n1. Install using pypi repository::\n\n pip install django-popup-view-field\n\n2. Install using pip + github repository url::\n\n pip install git+https://github.com/djk2/django-popup-view-field.git\n\n3. Install using pip + zip archive::\n\n wget https://github.com/djk2/django-popup-view-field/archive/master.zip\n pip install master.zip\n\n4. Clone or download application to your django project directory::\n\n wget https://github.com/djk2/django-popup-view-field/archive/master.zip -O /tmp/master.zip\n unzip /tmp/master.zip -d /tmp/\n cd my_project_dir\n cp -r /tmp/django-popup-view-field-master/django_popup_view_field/ ./\n\nAdd ``django_popup_view_field`` to your INSTALLED_APPS setting\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\n*settings.py* ::\n\n INSTALLED_APPS = [\n ...\n 'bootstrap3', # If you use django-bootstrap3\n 'crispy_forms', # If you user django-crispy-forms\n\n 'django_popup_view_field',\n ...\n ]\n\n**Warning**:\n Is recommended use django-bootstrap3 or django-crispy-forms\n to render forms and fields, but this is not necessary.\n You can still write django templates using pure CSS from bootstrap3.\n More information about bootstrap forms in here: http://getbootstrap.com/css/#forms\n\n\nAdd the django_popup_view_field urls to your root url patterns\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n*urls.py* ::\n\n urlpatterns = [\n ...\n url(\n r'^django_popup_view_field/',\n include('django_popup_view_field.urls', namespace=\"django_popup_view_field\")\n ),\n ]\n\n**Note**:\n The URL path can be whatever you want,\n but you must include 'django_popup_view_field.urls' with the 'django_popup_view_field' namespace.\n You may leave out the namespace in Django >= 1.9\n\n\nIn your base template, add ``django_popup_view_field_javascript`` tag\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n``django_popup_view_field_javascript`` template tag load all required javascripts and\ntemplate-scripts for application.\nTag should be append before body close tag and after jQuery and Bootstrap scripts.\n\n*base.html* ::\n\n \n {% load django_popup_view_field_tags %}\n\n \n \n ...\n \n ...\n \n\n \n ...\n ...\n \n \n ...\n ...\n {% django_popup_view_field_javascript %}\n \n \n\n\nSimple Example\n------------------------\n\n.. image:: https://raw.githubusercontent.com/djk2/django-popup-view-field/master/doc/static/simple_example.png\n :alt: Simple Example - screenshot\n\n\nCreate PopupView\n^^^^^^^^^^^^^^^^^\n\nHtml content rendered by this view will be loaded into bootstrap dialog.\nCreate your popup view same as normal django view.\n\n| **Your popup view must be subclass of django.views.generic.View**\n\n*templates/myapp/popups/colors.html* ::\n\n \n\nIf user click on the element with the attribute ``data-popup-view-value``,\nthe value of this attribute will be set in form field and dialog will close.\n\n|\n\nIf you want set content of element as value in form field, use ``html()`` for attribute::\n\n
  • This text will be use :)
  • \n\n*popups.py* ::\n\n from django.views.generic import TemplateView\n from django_popup_view_field.registry import registry_popup_view\n\n class ColorsPopupView(TemplateView):\n template_name = 'myapp/popups/colors.html'\n\n # REGISTER IS IMPORTANT\n registry_popup_view.register(ColorsPopupView)\n\nRemember that you must register your popup view.\nAfter register you can run your popup view by call url::\n\n ..../django_popup_view_field/ColorsPopupView\n\nIn template you can get url to popup view using url tag::\n\n {% url \"django_popup_view_field:get_popup_view\" 'ColorsPopupView' %}\n\nAfter register you can unregister your popup view::\n\n registry_popup_view.unregister(ColorsPopupView)\n\n # or unregister by view name\n\n registry_popup_view.unregister_by_name('ColorsPopupView')\n\nYou can also get popup view class by name::\n\n view_class = registry_popup_view.get('ColorsPopupView')\n view_class.as_view()\n\n\nCreate Form with PopupViewField\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n*forms.py* ::\n\n from django import forms\n from django_popup_view_field.fields import PopupViewField\n from myapp.popups import ColorsPopupView\n\n class ColorForm(forms.Form):\n\n color = PopupViewField(\n view_class=ColorsPopupView,\n popup_dialog_title='What is your favorite color',\n attrs={'readonly': True},\n required=True,\n help_text='be honest'\n )\n\n**class PopupViewField(view_class, popup_dialog_title, *args, **kwargs)**\n\n* ``view_class`` - **required** - popup view class, view to render dialog content, must be subclass of django.views.generic.View\n* ``popup_dialog_title`` - **not required** - Title for dialog, default ``Popup Dialog: Select value``\n* ``attrs`` - **not required** - provides attributes for Widget\n* ``args`` and ``kwargs`` are default for CharField\n\n\nCreate typical FormView\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n*views.py* ::\n\n from django.views.generic import FormView\n from myapp.forms import ColorForm\n from django.http import HttpResponse\n\n class ColorFormView(FormView):\n template_name = \"myapp/color_form.html\"\n form_class = ColorForm\n\n def form_valid(self, form):\n color = form.cleaned_data.get(\"color\")\n return HttpResponse(\"Your color: {0}\".format(color))\n\n**Template using django-crispy-forms**\n\n*templates/myapp/color_form.html* ::\n\n {% extends \"base.html\" %}\n {% load crispy_forms_tags %}\n {% crispy form %}\n\n\n**Template using django-bootstrap3**\n\n*templates/myapp/color_form.html* ::\n\n {% extends \"base.html\" %}\n {% load bootstrap3 %}\n\n
    \n {% csrf_token %}\n {% bootstrap_form form %}\n {% buttons %}\n \n {% endbuttons %}\n
    \n\n**Template with pure bootstrap3 css (without django-bootstrap3 and crispy)**\n\n*templates/myapp/color_form.html* ::\n\n {% extends \"base.html\" %}\n
    \n
    \n \n {{ form.color }}\n
    \n \n
    \n\n\ncallback_data attribute\n------------------------\nIf you want pass extra parameters to your popup view, you should use `callback_data`\nattribute for PopupViewField. This argument should be dictionary or OrderedDict.\nThis dictionary containing yours parameters will be encoded to ASCII text string and\nadded to url address. In your popup view You can take this parameters from `request.GET`.\n\n*popups.py* ::\n\n from django.views.generic import View\n from django_popup_view_field.registry import registry_popup_view\n\n class FooPopupView(View):\n def get(self, request):\n print(request.GET['extra_param']) # --> will be \"Foo Bar\"\n print(request.GET['my_pk']) # --> will be 666\n ....\n\n # REGISTER IS IMPORTANT\n registry_popup_view.register(FooPopupView)\n\n*forms.py* ::\n\n from django import forms\n from django_popup_view_field.fields import PopupViewField\n\n class FooForm(forms.Form):\n\n some_field = PopupViewField(\n view_class=FooPopupView,\n callback_data={\n 'extra_param': 'Foo Bar',\n 'my_pk': 666\n }\n )\n\n\n\nAdvanced Example\n------------------------\n\nAdvanced Example use django-bootstrap3.\nDialog is interactive, all links and forms will be send via Ajax and response will be loaded in dialog.\n\n.. image:: https://raw.githubusercontent.com/djk2/django-popup-view-field/master/doc/static/advanced_example.png\n :alt: Advanced Example - screenshot\n\n\nPopupView\n^^^^^^^^^^\n\n*templates/myapp/popups/alphabet.html* ::\n\n

    Select the first letter of your name

    \n\n {% for char in alphabet %}\n
    \n {{ char }}\n
    \n {% if forloop.counter|divisibleby:\"13\" and forloop.counter > 0 %}\n

    \n {% endif %}\n {% endfor %}\n\n {# Button to change order #}\n \n Reverse order\n \n\n*popups.py* ::\n\n from django.views.generic import TemplateView\n from django_popup_view_field.registry import registry_popup_view\n from string import ascii_uppercase\n\n class AlphabetPopupView(TemplateView):\n template_name = 'myapp/popups/alphabet.html'\n direction = 1\n\n def get_context_data(self, **kwargs):\n self.direction = int(self.request.GET.get(\"direction\") or self.direction)\n alphabet = ascii_uppercase[::self.direction]\n ctx = super(AlphabetPopupView, self).get_context_data(**kwargs)\n ctx['alphabet'] = alphabet\n ctx['direction'] = self.direction * -1\n return ctx\n\n # REGISTER IS IMPORTANT\n registry_popup_view.register(AlphabetPopupView)\n\n\nForm with PopupViewField\n^^^^^^^^^^^^^^^^^^^^^^^^^^\n*forms.py* ::\n\n from django import forms\n from django_popup_view_field.fields import PopupViewField\n from myapp.popups import AlphabetPopupView\n\n class AlphabetForm(forms.Form):\n\n char = PopupViewField(view_class=AlphabetPopupView, required=True)\n\nView\n^^^^^\n\n*templates/myapp/alphabet.html* ::\n\n {% extends \"base.html\" %}\n {% load bootstrap3 %}\n\n
    \n {% csrf_token %}\n {% bootstrap_form form %}\n {% buttons %}\n \n {% endbuttons %}\n
    \n\n*views.py* ::\n\n from django.views.generic import FormView\n from myapp.forms import AlphabetForm\n from django.http import HttpResponse\n\n class AlphabetFormView(FormView):\n template_name = \"myapp/alphabet.html\"\n form_class = AlphabetForm\n\n def form_valid(self, form):\n char = form.cleaned_data.get(\"char\")\n return HttpResponse(\"First letter of your name : {0}\".format(char))\n\n\nPopupViewModelField Example\n-----------------------------\n``PopupViewModelField`` allows you to send model objects through the form inheriting from ``ModelForm``.\n\n.. image:: https://raw.githubusercontent.com/djk2/django-popup-view-field/master/doc/static/PopupViewModelField_example.png\n :alt: PopupViewModelField Example - screenshot\n\n\nModel\n^^^^^^^\n*models.py* ::\n\n from django.db import models\n\n\n class Country(models.Model):\n code = models.CharField(max_length=2, primary_key=True)\n name = models.CharField(max_length=256)\n\n\n class ExampleUser(models.Model):\n first_name = models.CharField(max_length=30)\n last_name = models.CharField(max_length=30)\n country_code = models.ForeignKey(Country, on_delete=models.PROTECT)\n\n\nPopupView\n^^^^^^^^^^\n*templates/myapp/popups/country.html* ::\n\n