### Example Usage of CRUDView.get_urls Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Demonstrates how to include all CRUD URLs for a view in your project's urlpatterns. ```python urlpatterns = [ *BookmarkView.get_urls(), ] ``` -------------------------------- ### Install Neapolitan Source: https://github.com/carltongibson/neapolitan/blob/main/README.rst Installs the Neapolitan package using pip. This is the first step to using Neapolitan in a Django project. ```bash pip install neapolitan ``` -------------------------------- ### CRUDView.show_form Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Handles the HTTP GET request for displaying a form (for create or update). It retrieves the form and renders it. ```python def show_form(self, request, *args, **kwargs): """Handle GET requests for a form view.""" return self.render_to_response(self.get_context_data()) ``` -------------------------------- ### Example Usage of CRUDView.get_urls with Role Filtering Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Shows how to include only specific CRUD URLs (List and Detail) for a view in your project's urlpatterns. ```python urlpatterns = [ *BookmarkView.get_urls(roles={Role.LIST, Role.DETAIL}), ] ``` -------------------------------- ### Route Subset of CRUD Roles Source: https://github.com/carltongibson/neapolitan/blob/main/CHANGELOG.rst Example of how to route only a subset of CRUD roles by passing a set of roles to get_urls(). ```python from neapolitan.views import CRUDView, Role from .models import Bookmark class BookmarkView(CRUDView): model = Bookmark fields = ["url", "title", "note"] filterset_fields = [ "favourite", ] urlpatterns = [ *BookmarkView.get_urls(roles={Role.LIST, Role.DETAIL}), ] ``` -------------------------------- ### Neapolitan CRUDView Setup Source: https://github.com/carltongibson/neapolitan/blob/main/README.rst Sets up a Neapolitan CRUDView for the Bookmark model, specifying fields and filterset options. This snippet demonstrates how to integrate Neapolitan into Django's URL configuration. ```python # urls.py from neapolitan.views import CRUDView from .models import Bookmark class BookmarkView(CRUDView): model = Bookmark fields = ["url", "title", "note"] filterset_fields = [ "favourite", ] urlpatterns = [ *BookmarkView.get_urls(), ] ``` -------------------------------- ### CRUDView.list Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Handles the HTTP GET request for listing objects. It retrieves a queryset and renders a list view. ```python def list(self, request, *args, **kwargs): """Handle GET requests for a list view.""" return self.render_to_response(self.get_context_data()) ``` -------------------------------- ### CRUDView.detail Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Handles the HTTP GET request for displaying a single object's detail. It retrieves the object and renders a detail view. ```python def detail(self, request, *args, **kwargs): """Handle GET requests for a detail view.""" return self.render_to_response(self.get_context_data()) ``` -------------------------------- ### CRUDView.confirm_delete Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Handles the HTTP GET request for confirming deletion of an object. It retrieves the object and renders a confirmation template. ```python def confirm_delete(self, request, *args, **kwargs): """Handle GET requests for a delete confirmation view.""" return self.render_to_response(self.get_context_data()) ``` -------------------------------- ### mktemplate Management Command Usage Source: https://github.com/carltongibson/neapolitan/blob/main/CHANGELOG.rst Illustrates how to use the mktemplate management command to create an override template. ```bash ./manage.py mktemplate --help ``` -------------------------------- ### CRUDView.as_view Method Usage Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Illustrates how to manually route individual URLs using `as_view()` and specifying a role. ```python path( "bookmarks/", BookmarkCRUDView.as_view(role=Role.LIST), name="bookmark-list", ) ``` -------------------------------- ### Create a Custom Template with mktemplate Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/templates.rst Use the `mktemplate` management command to copy a default Neapolitan template to your app's template directory. This is useful for overriding specific templates for your models. ```shell python manage.py mktemplate myapp.MyModel --list ``` -------------------------------- ### Create CRUD Views with Neapolitan Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/index.rst This snippet demonstrates how to create a CRUDView for the Bookmark model using Neapolitan. It specifies the model and the fields to be included in the CRUD operations. ```python # urls.py from neapolitan.views import CRUDView from .models import Bookmark class BookmarkView(CRUDView): model = Bookmark fields = ["url", "title", "note"] urlpatterns = [ ... ] + BookmarkView.get_urls() ``` -------------------------------- ### Define Project Model Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/tutorial.rst Defines the Project model with fields for name, owner, test status, documentation status, project status, and last review date. Includes status choices and a method to check if a project is at risk. ```Python class Project(models.Model): name = models.CharField(max_length=200) owner = models.CharField(max_length=200) has_tests = models.BooleanField() has_docs = models.BooleanField() NA = "na" PLANNED = "PL" STARTED = "ST" FIRST_RESULTS = "FR" MATURE_RESULTS = "MR" DONE = "DO" DEFERRED = "DE" BLOCKED = "BL" INACTIVE = "IN" STATUS_CHOICES = [ (PLANNED, "Planned"), (STARTED, "Started"), (FIRST_RESULTS, "First results"), (MATURE_RESULTS, "Mature results"), (DONE, "Done"), (DEFERRED, "Deferred"), (BLOCKED, "Blocked"), (INACTIVE, "Inactive"), ] status = models.CharField( max_length=2, choices=STATUS_CHOICES, ) last_review = models.DateField(null=True, blank=True) def is_at_risk(self): return self.status in {self.BLOCKED, self.INACTIVE} def __str__(self): return self.name ``` -------------------------------- ### Custom URL Generation with Path Converters Source: https://github.com/carltongibson/neapolitan/blob/main/CHANGELOG.rst Demonstrates customizing URL generation by setting lookup_field, path_converter, and url_base attributes on a CRUDView subclass. ```python from django.db import models import uuid from neapolitan.views import CRUDView class NamedCollection(models.Model): name = models.CharField(max_length=25, unique=True) code = models.UUIDField(unique=True, default=uuid.uuid4) class NamedCollectionView(CRUDView): model = NamedCollection fields = ["name", "code"] lookup_field = "code" path_converter = "uuid" url_base = "named-collections" ``` -------------------------------- ### CRUDView.get_form Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Instantiates and returns the form for the view. Handles initial data and instance for updates. ```python def get_form(self, form_class=None): """Return an instance of the form for this view. The `form_class` will be the one returned by `get_form_class()`. `**kwargs` will be used to get the form instance. """ if form_class is None: form_class = self.get_form_class() kwargs = self.get_form_kwargs() return form_class(**kwargs) ``` -------------------------------- ### Detail Partial Template Logic Source: https://github.com/carltongibson/neapolitan/blob/main/examples/bootstrap/partial/detail.html This snippet shows how to iterate over an object's fields and display each field name capitalized, followed by its value. It is useful for rendering detailed views of objects. ```html {# partial/detail.html - Detail partial template #} {% for field, val in object %} {{ field|capfirst }}: {{ val }} {% endfor %} ``` -------------------------------- ### List Iteration and Field Rendering Source: https://github.com/carltongibson/neapolitan/blob/main/examples/bootstrap/partial/list.html Iterates through headers, objects, and fields to render list data. Displays the header capitalized and includes actions for objects. ```html {# partial/list.html - List partial template #} {% for header in headers %} {% endfor %} {% for object in object_list %} {% for field in object.fields %} {% endfor %} {% endfor %} {{ header|capfirst }} Actions {{ field.value }} {{ object.actions }} ``` -------------------------------- ### Add Neapolitan to INSTALLED_APPS Source: https://github.com/carltongibson/neapolitan/blob/main/README.rst Configures a Django project to use Neapolitan by adding it to the INSTALLED_APPS setting. This is required for Neapolitan's features to be recognized by Django. ```python INSTALLED_APPS = [ ... "neapolitan", ] ``` -------------------------------- ### Define a Django Model Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/index.rst This snippet shows a basic Django model definition for a Bookmark, including URL, title, and note fields. ```python from django.db import models class Bookmark(models.Model): url = models.URLField(unique=True) title = models.CharField(max_length=255) note = models.TextField(blank=True) ``` -------------------------------- ### Load Neapolitan Template Tags Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/templates.rst To use Neapolitan's template tags, load them at the beginning of your template file using the `{% load neapolitan %}` tag. Ensure 'neapolitan' is in your `INSTALLED_APPS`. ```html+django {% load neapolitan %} ``` -------------------------------- ### CRUDView.show_form Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Displays the form for creating or updating an object. This handler is typically used to present a blank or pre-filled form to the user. ```APIDOC ## CRUDView.show_form ### Description Displays the form for creating or updating an object. This handler is typically used to present a blank or pre-filled form to the user. ### Method GET ### Endpoint (Not explicitly defined, typically inferred from URL routing) ### Parameters (Not explicitly defined in the source for this method) ### Request Example (Not explicitly defined in the source) ### Response (Not explicitly defined in the source, typically an HTML response with a form) #### Success Response (200) (Not explicitly defined in the source) #### Response Example (Not explicitly defined in the source) ``` -------------------------------- ### Register Project Model in Admin Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/tutorial.rst Registers the Project model with the Django admin site, making it manageable through the admin interface. ```Python from .models import Project admin.site.register(Project) ``` -------------------------------- ### CRUDView.paginate_queryset Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Paginates the queryset based on `paginate_by`. Returns the paginated queryset and the paginator object. ```python def paginate_queryset(self, queryset, page_number): """Return a slice of the queryset that corresponds to the requested page. And a boolean indicating whether to display the pagination controls. """ page_size = self.get_paginate_by() if page_size: paginator = self.get_paginator( queryset, page_size, orphans=self.get_paginate_orphans(), allow_empty_first_page=self.get_allow_empty_first_page() ) try: return paginator.page(page_number), paginator except PageNotAnInteger: # If page is not an integer, deliver first page. return paginator.page(1), paginator except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. return paginator.page(paginator.num_pages), paginator return None, None ``` -------------------------------- ### Neapolitan Template Directory Structure Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/templates.rst This shows the default directory structure for Neapolitan's templates. You can override these by creating corresponding templates in your project's template directories. ```shell templates └── neapolitan ├── object_confirm_delete.html ├── object_detail.html ├── object_form.html ├── object_list.html └── partial ├── detail.html └── list.html ``` -------------------------------- ### CRUDView.get_template_names Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Determines the template names to use for rendering. Tries specific templates first, then falls back to generic ones. ```python def get_template_names(self): """Return a list of template names to be used for this view. Tries to find a template named ``/_.html``, then falls back to ``/.html``. """ opts = self.model._meta return [ f"{opts.app_label}/{opts.model_name}_{self.request.resolver_match.url_name}.html", f"{opts.app_label}/{opts.model_name}.html", f"{opts.app_label}/crud_view.html", "crud_view.html", ] ``` -------------------------------- ### CRUDView.as_view Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Provides a lower-level method for manually routing individual URLs. It extends Django's View.as_view() and requires a Role to specify exposed handlers. ```APIDOC ## CRUDView.as_view ### Description Provides a lower-level method for manually routing individual URLs. It extends Django's View.as_view() and requires a Role to specify exposed handlers. ### Method Class Method ### Endpoint (Not applicable, used in URL configuration) ### Parameters - **role** (Role) - The role specifying which handlers to expose. ### Request Example ```python path( "bookmarks/", BookmarkCRUDView.as_view(role=Role.LIST), name="bookmark-list", ) ``` ### Response (Returns a callable view function) #### Success Response (Not applicable) #### Response Example (Not applicable) ``` -------------------------------- ### Define Custom CRUDView Base Class Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/how-tos.rst Create a custom base class for Neapolitan's CRUDView to implement project-level overrides. This allows for centralized modifications to view behavior. ```python from neapolitan.views import CRUDView as BaseCRUDView class CRUDView(BaseCRUDView): # Add your overrides here. class MyModelCRUDView(CRUDView): model = "MyModel" fields = ["name", "description"] ``` -------------------------------- ### CRUDView.render_to_response Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Renders the response using the determined template and context. Handles HTTP status codes. ```python def render_to_response(self, context, **response_kwargs): """Return a response with the given template rendered with the given context. """ response_kwargs.setdefault("mimetype", self.content_type) return self.template_engine.from_string(self.get_template_names()[0]).render( context, self.request, ) ``` -------------------------------- ### CRUDView.get_paginate_by Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Returns the number of items to display per page. Can be an integer or None. ```python def get_paginate_by(self): """Return the number of items to display per page.""" return self.paginate_by ``` -------------------------------- ### CRUDView.process_form Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Handles the HTTP POST request for processing a submitted form (create or update). It validates the form and redirects on success. ```python def process_form(self, request, *args, **kwargs): """Handle POST requests for a form view.""" form = self.get_form() if self.form_valid(form): return self.form_valid(form) return self.form_invalid(form) ``` -------------------------------- ### Define Neapolitan CRUD View Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/tutorial.rst Defines a ProjectView that extends Neapolitan's CRUDView, specifying the model and fields to be managed. This automatically generates URLs for CRUD operations. ```Python from neapolitan.views import CRUDView import projects class ProjectView(CRUDView): model = projects.models.Project fields = ["name", "owner", "last_review", "has_tests", "has_docs", "status"] urlpatterns += ProjectView.get_urls() ``` -------------------------------- ### CRUDView.list Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Handles the HTTP request for listing objects. It is responsible for retrieving and presenting a list of items, typically from a queryset. ```APIDOC ## CRUDView.list ### Description Handles the HTTP request for listing objects. It is responsible for retrieving and presenting a list of items, typically from a queryset. ### Method GET ### Endpoint (Not explicitly defined, typically inferred from URL routing) ### Parameters (Not explicitly defined in the source for this method) ### Request Example (Not explicitly defined in the source) ### Response (Not explicitly defined in the source, but typically an HTML page or JSON response) #### Success Response (200) (Not explicitly defined in the source) #### Response Example (Not explicitly defined in the source) ``` -------------------------------- ### Django Model Definition Source: https://github.com/carltongibson/neapolitan/blob/main/README.rst Defines a Django model named Bookmark with fields for URL, title, note, and favourite status. ```python from django.db import models class Bookmark(models.Model): url = models.URLField(unique=True) title = models.CharField(max_length=255) note = models.TextField(blank=True) favourite = models.BooleanField(default=False) ``` -------------------------------- ### CRUDView.detail Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Handles the HTTP request for displaying a single object's details. It retrieves a specific object based on the request and renders its details. ```APIDOC ## CRUDView.detail ### Description Handles the HTTP request for displaying a single object's details. It retrieves a specific object based on the request and renders its details. ### Method GET ### Endpoint (Not explicitly defined, typically inferred from URL routing, often includes an object identifier) ### Parameters (Not explicitly defined in the source for this method, but typically includes an object identifier in the path) ### Request Example (Not explicitly defined in the source) ### Response (Not explicitly defined in the source, but typically an HTML page or JSON response) #### Success Response (200) (Not explicitly defined in the source) #### Response Example (Not explicitly defined in the source) ``` -------------------------------- ### CRUDView.get_urls Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Generates URL patterns for all CRUD operations for a given model. Can be filtered by roles. ```python def get_urls(self, roles=None): """Return a list of URL patterns for the CRUD view. By default, it returns URLs for all CRUD operations. You can provide a set of roles to limit the handlers exposed. """ if roles is None: roles = { Role.LIST, Role.DETAIL, Role.CREATE, Role.UPDATE, Role.DELETE, } urlpatterns = [] if Role.LIST in roles: urlpatterns += [path( "", self.as_view(role=Role.LIST), name=f"{self.model.__name__.lower()}-list", )] if Role.DETAIL in roles: urlpatterns += [path( "/", self.as_view(role=Role.DETAIL), name=f"{self.model.__name__.lower()}-detail", )] if Role.CREATE in roles: urlpatterns += [path( "create/", self.as_view(role=Role.CREATE), name=f"{self.model.__name__.lower()}-create", )] if Role.UPDATE in roles: urlpatterns += [path( "/update/", self.as_view(role=Role.UPDATE), name=f"{self.model.__name__.lower()}-update", )] if Role.DELETE in roles: urlpatterns += [path( "/delete/", self.as_view(role=Role.DELETE), name=f"{self.model.__name__.lower()}-delete", )] return urlpatterns ``` -------------------------------- ### Base HTML Template for Neapolitan Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/tutorial.rst A minimal base HTML template required by Neapolitan. It defines a content block where Neapolitan's generated templates will be rendered. ```HTML {% block content %}{% endblock %} ``` -------------------------------- ### CRUDView.get_paginator Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Returns the paginator class to be used. Defaults to Django's Paginator. ```python def get_paginator(self, queryset, per_page, orphans=0, allow_empty_first_page=True): """Return an instance of the paginator for this view.""" return Paginator( queryset, per_page, orphans=orphans, \ allow_empty_first_page=allow_empty_first_page ) ``` -------------------------------- ### Update object_list Template Usage Source: https://github.com/carltongibson/neapolitan/blob/main/CHANGELOG.rst Shows the updated usage for the object_list template tag when overriding the object_list.html template. ```html+django {% object_list object_list view %} ``` -------------------------------- ### CRUDView.get_success_url Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Returns the URL to redirect to after a successful form submission or deletion. Defaults to the list view. ```python def get_success_url(self): """Return the URL to redirect to after successful form processing.""" return reverse_lazy( f"{self.model.__name__.lower()}-list" ) ``` -------------------------------- ### CRUDView.get_urls Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Generates URL patterns for all standard CRUD operations. This method is the primary entry point for routing CRUD URLs in a single pass. ```APIDOC ## CRUDView.get_urls ### Description Generates URL patterns for all standard CRUD operations. This method is the primary entry point for routing CRUD URLs in a single pass. ### Method Class Method ### Endpoint (Not applicable, generates URL patterns) ### Parameters - **roles** (set, optional) - A set of roles to limit the exposed handlers. ### Request Example ```python urlpatterns = [ *BookmarkView.get_urls(), ] # With limited roles: urlpatterns = [ *BookmarkView.get_urls(roles={Role.LIST, Role.DETAIL}), ] ``` ### Response (Returns a list of URL patterns) #### Success Response (Not applicable) #### Response Example (Not applicable) ``` -------------------------------- ### CRUDView.get_object Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Retrieves a single object from the queryset based on URL parameters. Raises Http404 if the object is not found. ```python def get_object(self, queryset=None): """Get the object the view is supposed to act upon. By default, returns the `self.queryset`. Subclasses may override the method in order to return a different queryset. """ if queryset is None: queryset = self.get_queryset() # `pk` and `slug` are supported as URL kwarg names by default. queryset = queryset.filter( **{self.lookup_field: self.kwargs[self.lookup_field]} ) try: # Get the single object record from the queryset obj = queryset.get() except queryset.model.DoesNotExist: raise Http404(_("No %(verbose_name)s found matching the query") % {'verbose_name': queryset.model._meta.verbose_name}) return obj ``` -------------------------------- ### CRUDView.get_context_data Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Adds context variables to the template. Includes object, queryset, form, and pagination data. ```python def get_context_data(self, **kwargs): """Return the context data for this view. Adds ``object`` and ``queryset`` to the context. """ queryset = kwargs.pop("queryset", self.get_queryset()) object = kwargs.pop("object", None) form = kwargs.pop("form", None) context = { self.get_context_object_name(queryset.model): object or queryset, "view": self, } if form: context["form"] = form # Add pagination context if enabled page_number = self.kwargs.get("page") if page_number and self.get_paginate_by(): page_obj, paginator = self.paginate_queryset(queryset, page_number) context["object_list"] = page_obj.object_list context["page_obj"] = page_obj context["paginator"] = paginator context.update(kwargs) return context ``` -------------------------------- ### CRUDView.confirm_delete Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Displays a confirmation page before deleting an object. This handler ensures the user explicitly confirms the deletion action. ```APIDOC ## CRUDView.confirm_delete ### Description Displays a confirmation page before deleting an object. This handler ensures the user explicitly confirms the deletion action. ### Method GET ### Endpoint (Not explicitly defined, typically inferred from URL routing, often includes an object identifier) ### Parameters (Not explicitly defined in the source for this method, but typically includes an object identifier in the path) ### Request Example (Not explicitly defined in the source) ### Response (Not explicitly defined in the source, typically an HTML response with a confirmation prompt) #### Success Response (200) (Not explicitly defined in the source) #### Response Example (Not explicitly defined in the source) ``` -------------------------------- ### CRUDView.process_deletion Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Handles the HTTP POST request for processing the deletion of an object. It deletes the object and redirects. ```python def process_deletion(self, request, *args, **kwargs): """Handle POST requests for a delete confirmation view.""" object = self.get_object() object.delete() return self.form_valid(None) ``` -------------------------------- ### Integrate TailwindCSS with Play CDN Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/tutorial.rst Includes the TailwindCSS Play CDN script in the base HTML template to enable styling. This method is not recommended for production environments. ```HTML {% block content %}{% endblock %} ``` -------------------------------- ### CRUDView.get_queryset Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Returns the queryset that will be used to retrieve objects for this view. Subclasses may override this to filter or modify the queryset. ```python def get_queryset(self): """Return the list of items for this view. This must be an iterable. """ return getattr(self.model, "objects") ``` -------------------------------- ### CRUDView.get_context_object_name Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Returns the name of the context variable for the object. Defaults to the lowercase model name. ```python def get_context_object_name(self, obj): """Get the context object name for this view. Defaults to the lowercase name of the model. """ return self.context_object_name or obj._meta.model_name ``` -------------------------------- ### CRUDView.process_form Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Processes the submitted form data for creating or updating an object. It validates the data and saves the object if valid. ```APIDOC ## CRUDView.process_form ### Description Processes the submitted form data for creating or updating an object. It validates the data and saves the object if valid. ### Method POST ### Endpoint (Not explicitly defined, typically inferred from URL routing) ### Parameters (Not explicitly defined in the source for this method) ### Request Body (Not explicitly defined in the source, but would typically contain form data) ### Request Example (Not explicitly defined in the source) ### Response (Not explicitly defined in the source, typically a redirect or an HTML response with form errors) #### Success Response (200 or 302) (Not explicitly defined in the source) #### Response Example (Not explicitly defined in the source) ``` -------------------------------- ### CRUDView.get_filterset Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Returns the filterset class to be used for filtering the queryset. Defaults to None. ```python def get_filterset(self): """Return the filterset class to be used for this view.""" return self.filterset_class ``` -------------------------------- ### CRUDView.get_form_class Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Returns the form class to be used for this view. Defaults to Django's ModelForm. ```python def get_form_class(self): """Return the form class to be used for this view.""" return self.form_class ``` -------------------------------- ### CRUDView.process_deletion Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Processes the deletion of an object after confirmation. This handler performs the actual deletion operation. ```APIDOC ## CRUDView.process_deletion ### Description Processes the deletion of an object after confirmation. This handler performs the actual deletion operation. ### Method POST or DELETE ### Endpoint (Not explicitly defined, typically inferred from URL routing, often includes an object identifier) ### Parameters (Not explicitly defined in the source for this method, but typically includes an object identifier in the path) ### Request Example (Not explicitly defined in the source) ### Response (Not explicitly defined in the source, typically a redirect after deletion) #### Success Response (200 or 302) (Not explicitly defined in the source) #### Response Example (Not explicitly defined in the source) ``` -------------------------------- ### CRUDView.form_valid Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Called when a form is valid. Handles saving the object and redirecting to the success URL. ```python def form_valid(self, form): """Called when a valid form is submitted. This method is called by `process_form()` whenever a valid form has been submitted. """ obj = form.save() return redirect(self.get_success_url()) ``` -------------------------------- ### CRUDView.form_invalid Method Source: https://github.com/carltongibson/neapolitan/blob/main/docs/source/crud-view.rst Called when a form is invalid. Re-renders the form with errors. ```python def form_invalid(self, form): """Called when an invalid form is submitted.""" return self.render_to_response(self.get_context_data(form=form)) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.