Skip to main content

A CRUD framework that uses HTML popups for CRUD operations.

Project description

A CRUD framework leveraging Django’s generic views that implements CRUD operations through HTML popups.

Latest PyPI version Number of PyPI downloads per month

Requirements

  • Python >= 3.4

  • Django >= 2.2.8

  • django-bootstrap3

  • django-pure-pagination

Documentation

Available at django-popupcrud.readthedocs.io.

Quickstart

  1. Install django-popupcrud using pip:

    pip install django-popucrud

    Or install it directly from the source repository:

    pip install git+https://github.com/harikvpy/django-popupcrud.git

    Yet another way would be to clone this repository and install from the cloned root folder via pip install -e ..

  2. Install the dependencies - django-bootstrap3 and django-pure-pagination. Add the dependencies and popupcrud to INSTALLED_APPS in your project’s settings.py:

    INSTALLED_APPS = [
        ...
        'bootstrap3',
        'pure_pagination',
        'popupcrud',
        ...
    ]
  3. Let PopupCrudViewSet know of your base template file name. This defaults to base.html, but if your project uses a different base template filename, inform PopupCrudViewSet about it in settings.py:

    POPUPCRUD = {
        'base_template': 'mybase.html',
    }

    Include Bootstrap CSS & JS resources in this base template. If you were to use django-bootstrap3 tags for these, your base template should look something like this:

    <head>
        {% bootstrap_css %}
        <script src="{% bootstrap_jquery_url %}" type="text/javascript" charset="utf-8"></script>
        {% bootstrap_javascript %}
        {% block extrahead %}{% endblock extrahead %}
    </head>

    Also, define a block named extrahead within the <head> element. PopupCrudViewSet views use a few custom CSS styles to show column sorting options and sort priority. These styles are defined in static/popupcrud/css/popupcrud.css which is inserted into the extrahead block. If you don’t declare this block, you will have to explicitly load the stylesheet into your base template.

  4. In your app’s views.py, create a ViewSet for each model for which you want to support CRUD operations.

    Models.py:

    from django.db import models
    
    class Author(models.Model):
        name = models.CharField("Name", max_length=128)
        penname = models.CharField("Pen Name", max_length=128)
        age = models.SmallIntegerField("Age", null=True, blank=True)
    
        class Meta:
            ordering = ('name',)
            verbose_name = "Author"
            verbose_name_plural = "Authors"
    
        def __str__(self):
            return self.name

    Views.py:

    from django.core.urlresolvers import reverse_lazy, reverse
    from popupcrud.views import PopupCrudViewSet
    
    class AuthorViewSet(PopupCrudViewSet):
        model = Author
        fields = ('name', 'penname', 'age')
        list_display = ('name', 'penname', 'age')
        list_url = reverse_lazy("library:authors:list")
        new_url = reverse_lazy("library:authors:create")
    
        def get_edit_url(self, obj):
            return reverse("library:authors:update", kwargs={'pk': obj.pk})
    
        def get_delete_url(self, obj):
            return reverse("library:authors:delete", kwargs={'pk': obj.pk})
  5. Wire up the CRUD views generated by the viewset to the URLconf:

    urlpatterns= [
        url(r'^authors/', views.AuthorCrudViewset.urls()),
    ]

    This will register the following urls:

    • authors/ - list view

    • authors/create/ - create view

    • authors/<pk>/ - detail view

    • authors/<pk>/update/ - update view

    • authors/<pk>/delete/ - delete view

    The urls are registered under its own namespace, which defaults to the model’s verbose_name_plural meta value.

  6. Thats it! Your modern HTML popup based CRUD for your table is up and running.

    PopupCrudViewSet has many options to customize the fields displayed in list view, form used for create/update operations, permission control and more. Refer to the Reference and How-to sections of the documentation for more details.

License

Distributed under BSD 3-Clause License. See LICENSE file for details.

History

0.1.0 (2017-09-25)

  • Initial release

0.1.2 (2017-09-26)

  • Merge Quickstart section into README

0.1.3 (2017-09-26)

  • Add missing HISTORY.rst to manifst

0.1.4 (2017-09-26)

  • Support for order_field attribute for list_display method fields. This works similar to ModelAdmin method fields’ admin_order_field property.

0.1.5 (2017-09-26)

  • Better unicode support

0.1.6 (2017-09-27)

  • Better access control support through ‘login_url’ & ‘raise_exception’ PopupCrudViewSet properties

0.1.7 (2017-10-13)

  • Object detail view support

0.1.8 (2017-10-16)

  • Add PopupCrudViewSet.urls() – a single method to return all the CRUD urls that can be added to urlpatterns[].

  • When related object popup is activated on a multiselect select and it adds a new object, the object is added to the existing list of selections. (old code used to replace all the current selections with the newly added item)

  • Insert all form media into ListView through ListView.media property.

  • Fix broken support for django-select2 in modals by setting control’s dropdownParent to the modal (rather than parent window)

  • Use the ‘create-edit-modal’ modal as the template for secondary modals activated through related-model modal popups. This ensures consistent modal look and feel if the user customized the modal template by overriding popupcrud/modal.html template.

  • Fix ALLOWED_HOSTS in settings - issue #1

0.2.0 (2017-10-18)

  • Bumping minor version as reflection of new features legacy_crud dict, media & out-of-the-box django_select2 support in previous release

  • Added ‘crudform.ready’ JavaScript event, which is triggered when create/update form is activated. This event provides clients an uniform way to apply their own optional initialization code to the CRUD forms.

  • Added 6 more tests to cover new legacy_crud dict value support & form media injection.

0.3.0 (2017-10-26)

  • List view content is rendered in its own block, popupcrud_list, in the template file. This allows the list content to be relocated to different parts of the base template.

  • Add ViewSet.empty_list_icon and ViewSet.empty_list_message properties. These properties provide for prettier rendering of empty table states.

0.3.1 (2017-10-26)

  • Use custom style for empty-list-state icon sizing. Earlier code was using font awesome style.

0.4.0 (2017-11-2)

  • Breadcrumbs support

  • ListView queryset custom filtering through PopupCrudViewSet.get_queryset()

  • Support custom form init args through PopupCrudViewSet.get_form_kwargs()

  • PopupCrudViewSet.new_url and PopupCrudViewSet.list_url are determined through PopupCrudViewSet.get_new_url() and PopupCrudViewSet.get_list_url() throughout the code.

0.4.1 (2017-11-6)

  • Fix an issue where when form with errors is rendered select2 and add-related widgets are not bound correctly

0.5.0 (2017-11-10)

  • Add custom item action support

  • Clean up JavaScript by encapsulating all methods in its own namespace & reducing code duplication

  • Add missing CSS styles to popupcrud.css

  • Empty_list_message class variable now allows embedded html tags (value is wrapped in mark_safe() before placing in template context)

0.6.0 (2018-03-15)

  • Add formset support in CRUD create/update views

  • Add size option to bsmodal template tags

  • Fixes to some minor bugs

0.6.1 (2018-03-16)

  • Make formset alignment consistent with bootstrap3 settings horizontal_label_class & horizontal_field_class.

0.6.2 (2018-03-17)

  • Fix bug where forms with m2m fields were not saved

  • Reflect formset form field ‘required’ status in field column header

  • Make formsets work in legacy crud mode

  • django-select2 support in formset forms

  • Minor formset layout formatting improvements

0.6.3 (2018-03-18)

  • Fix incorrect formset detection logic

0.6.4 (2018-03-26)

  • Optimize listview media when create & edit are set to legacy

  • Breadcrumbs obeys custom page title

  • Fix bug in ListView.media optimization

  • Introduce permissions_required attribute

  • PopupCrudViewSet.get_page_title now used in for all CRUD(legacy) views

0.7.0 (2018-06-20)

  • Add support for pk_url_kwarg, slug_field, slug_url_kwarg & context_object_name ViewSet attributes.

  • Improve documentation

0.7.1 (2018-06-20)

  • Update release history

0.8.0 (2018-10-31)

  • Allow html tags in custom column headers; hide Action column if there’re no item actions

  • Support view template context data in ViewSet

0.9.0 (2019-12-25)

  • Django 3.0 support

0.10.0 (2019-12-26)

  • Fix rendering bugs owing to changes in Django 3.0

0.11.0 (2019-12-26)

  • Bump min Django ver to 2.2.8

0.12.0 (2019-12-26)

  • Fix README formatting errors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-popupcrud-0.12.0.tar.gz (42.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page