Skip to main content

Neapolitan with namespaces - Django CRUD views

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Nominopolitan

This is an opinionated extension package for the excellent neapolitan package. It adds these features:

  • Namespaced URL handling
  • Display related field str() value in lists and details (instead of numeric id)
  • Property fields in list views
  • Separate create form class if specified
  • Support for crispy-forms if installed in project
  • Support for rendering templates using htmx
  • Header title context for partial updates (so the title is updated without a page reload)
  • Allow specification of base_template_path (to your base.html template)
  • Allow override of all nominopolitan templates by specifying templates_path

At the moment the templates are styled using Bulma. I aim to also support the native neapolitan templates in a future release. FYI it uses django-template-partials under the hood.

This is a very early alpha release; expect many breaking changes. You might prefer to just fork or copy and use whatever you need. Hopefully some or all of these features may make their way into neapolitan over time.

Installation

With pip: pip install django-nominopolitan

Poetry: poetry add django-nominopolitan

Configuration

Add these to your settings.py:

INSTALLED_APPS = [
    ...
    "nominopolitan", # put this before neapolitan
    "neapolitan",    # this is required to use the `NominopolitanMixin`
    ...
]

Usage

The best starting point is neapolitan's docs. The basic idea is to specify model-based CRUD views using:

# neapolitan approach
class ProjectView(CRUDView):
    model = projects.models.Project
    fields = ["name", "owner", "last_review", "has_tests", "has_docs", "status"]

The nominopolitan mixin adds a number of features to this.

from nominopolitan.mixins import NominopolitanMixin
from neapolitan.views import CRUDView

class ProjectCRUDView(NominopolitanMixin, CRUDView):
    model = models.Project
    fields = [
        "name", "owner", "last_review", "has_tests", "has_docs", "status",
        ]
    form_class = forms.ProjectUpdateForm # standard neapolitan setting if needed
    # ...other standard neapolitan attributes

    namespace = "my_app_name" # specify the namespace if your urls.py has app_name = "my_app_name"

    properties = ["selected_scenario",] # if you want to include @property fields in the list view

    use_crispy = True # will default to True if you have `crispy-forms` installed
        # if you set it to True without crispy-forms installed, it will resolve to False

    create_form_class = forms.TenderCreateForm # if you want a separate create form
        # the update form always uses form_class

    base_template_path = "core/base_with_nav.html" # optional, defaults to "nominopolitan/base.html"
    templates_path = "neapolitan" # if you want to override all the templates in another app

    use_htmx = True # if you want the View, Detail, Delete and Create forms to use htmx
        # you must have `htmx` installed in your base template
        # Will only work if use_htmx is True AND you call the list view using htmx
        # in which case these templates will be returned to the same hx-target as used for the list view

    htmx_crud_target = "crudModal" # if you want to use a different htmx target for the crud forms
        # different (or the same) as the target used for the list view
        # eg you may want to target a modal for the create, read, update and delete forms
        # required use_htmx = True 

nm_mktemplate management command

This is the same as neapolitan's mktemplate command except it copies from the nominopolitan templates instead of the neapolitan templates.

It's the same syntax as neapolitan's mktemplate command:

python manage.py nm_mktemplate <app_name>.<model_name> --<suffix>

Status

Extremely early alpha. No tests. Limited docs. Suggest at this stage just use it as a reference and take what you need. It works for me.

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

django_nominopolitan-0.0.7.tar.gz (10.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_nominopolitan-0.0.7-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

Details for the file django_nominopolitan-0.0.7.tar.gz.

File metadata

  • Download URL: django_nominopolitan-0.0.7.tar.gz
  • Upload date:
  • Size: 10.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for django_nominopolitan-0.0.7.tar.gz
Algorithm Hash digest
SHA256 0d17d15cb9be3880434d437d9c7d571f43347461b5ec52fb820f8ea46896a353
MD5 64ab737ec7c1c8eaf87c17538ce8fd8a
BLAKE2b-256 c1d5e505e18702cf04e7567ad26a12baef8f93baaf99567b4199c2625404324d

See more details on using hashes here.

File details

Details for the file django_nominopolitan-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: django_nominopolitan-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 13.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.5.0-1025-azure

File hashes

Hashes for django_nominopolitan-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 a2bb5d33f4a68a81b21024635f3861e0adf95f65d68e690300621e75c66c5de7
MD5 75f141aa7e8d74482b3b7d09a0e9932b
BLAKE2b-256 c6abdd9f4ebffdef6ac772248d41be6ba9a660769b1b260ed142d04b9f7b7a33

See more details on using hashes here.

Supported by

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