westerveltco / django-twc-toolbox Goto Github PK
View Code? Open in Web Editor NEWVarious tools for Django projects at The Westervelt Company
Home Page: https://django-twc-toolbox.westervelt.dev
License: MIT License
Various tools for Django projects at The Westervelt Company
Home Page: https://django-twc-toolbox.westervelt.dev
License: MIT License
Full Changelog: westerveltco/django-twc-package@v2024.20...v2024.21
Full Changelog: westerveltco/django-twc-package@v2024.19...v2024.20
django-twc-package
v2024.19Full Changelog: westerveltco/django-twc-package@v2024.18...v2024.19
In one of our private projects, we have a messages
app that handles common messages that need to be sent externally, e.g. email, webhooks, or Teams. That should be ported over to this public package so that our other projects can use it.
coverage
Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: actions/setup-python@v4. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.
types
Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: actions/setup-python@v4. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.
If I go to the trouble of defining a custom Form
for a CRUDView
, shouldn't the view just use the fields from that form? As it stands right now, you have to duplicate the fields across the form and view, as CRUDView.get_fields
expects either the fields
attribute to be defined or for get_fields
to be overridden.
Let's say I have a model with a status field that I want rendered as radio buttons in the form.
# models.py
from django.db import models
class Book(models.Model):
author = models.CharField(max_length=255)
class Status(models.TextChoices):
DRAFT = "D", "Draft"
PUBLISHED = "P", "Published"
status = models.CharField(max_length=1, choices=Status.choices, default=Status.DRAFT)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
# forms.py
from django import forms
from .models import Book
class BookModelForm(forms.ModelForm):
class Meta:
model = Book
fields = ["author", "status"]
widgets = {
"status": forms.RadioSelect(),
}
This is what neapolitan
expects at the moment:
# views.py
from neapolitan.views import CRUDView
from .forms import BookModelForm
from .models import Book
class BookCRUDView(CRUDView):
model = Book
form_class = BookModelForm
fields = ["author", "status"]
To me, if I've gone to the trouble to define a custom form_class
on the view but no fields, it should fallback to the form class.
TimeStamped
DatePaginator
and DatePage
This snuck in with all the furious coding to get it shipped. In addition to the start_date
and end_date
of the DatePage
, which correspond to the first and last object's date, respectively, I wanted to also include the oldest and newest date regardless of the sorting.
Looks like I let hasattr
slip in, instead of getattr
for checking if a request is an HTMX request.
Similar to #7, it'd be nice if regardless of the order of the object_list
, that there was two properties for the min and max date of a paginator.
There's already a bunch of duplicated logic in the paginator methods dealing with this anyway, should be consolidated.
django-twc-toolbox/src/django_twc_toolbox/paginator.py
Lines 45 to 53 in 7fb68cb
django-twc-toolbox/src/django_twc_toolbox/paginator.py
Lines 170 to 178 in 7fb68cb
Trying to use CRUDView
with a tables.Table
-- setting an order_by
in the table's Meta
causes a TypeError
exception to be raised.
class ClubTable(tables.Table):
class Meta:
fields = [
"name",
"primary_tract_number",
"lease_manager_name",
"officer",
]
model = Club
order_by = ("primary_tract_number", "name")
template_name = "twc_tables/table.html"
class ClubCRUDView(LoginRequiredMixin, CRUDView):
model = Club
queryset = Club.objects.with_primary_tract_info()
table_class = ClubTable
Traceback:
Environment:
Request Method: GET
Request URL: http://localhost:8000/club/
Django Version: 5.0.7
Python Version: 3.12.4
Installed Applications:
['debug_toolbar',
'whitenoise.runserver_nostatic',
'lease.adjustments',
'lease.charges',
'lease.clubs',
'lease.clubtracts',
'lease.contrib.ordered_model',
'lease.core',
'lease.customers',
'lease.finance',
'lease.invoices',
'lease.leases',
'lease.managers',
'lease.members',
'lease.mgmtunits',
'lease.payments',
'lease.search',
'lease.surveys',
'lease.system',
'lease.tracts',
'lease.users',
'django_twc_ui',
'django_twc_ui.favicons',
'django_twc_ui.forms',
'django_twc_ui.layouts',
'django_twc_ui.tables',
'django_q_registry',
'django_simple_nav',
'django_twc_toolbox',
'django_twc_toolbox.crud',
'email_relay',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.okta',
'corsheaders',
'django_browser_reload',
'django_extensions',
'django_filters',
'django_htmx',
'django_q',
'django_tables2',
'django_tailwind_cli',
'django_vite',
'health_check',
'health_check.cache',
'health_check.contrib.migrations',
'health_check.db',
'health_check.storage',
'heroicons',
'import_export',
'ordered_model',
'rangefilter',
'rest_framework',
'rest_framework.authtoken',
'sequences',
'simple_history',
'template_partials',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.gis',
'django.contrib.humanize',
'django.contrib.messages',
'django.contrib.postgres',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.staticfiles',
'django.forms']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'corsheaders.middleware.CorsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'allauth.account.middleware.AccountMiddleware',
'simple_history.middleware.HistoryRequestMiddleware',
'django_htmx.middleware.HtmxMiddleware',
'django_flyio.middleware.FlyResponseMiddleware',
'django_browser_reload.middleware.BrowserReloadMiddleware']
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/core/handlers/base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/neapolitan/views.py", line 472, in view
return self.dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/contrib/auth/mixins.py", line 73, in dispatch
return super().dispatch(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/views/generic/base.py", line 143, in dispatch
return handler(request, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django_twc_toolbox/crud/views.py", line 135, in list
context = self.get_context_data(
File "/usr/local/lib/python3.12/site-packages/django_tables2/views.py", line 161, in get_context_data
table = self.get_table(**self.get_table_kwargs())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django_tables2/views.py", line 122, in get_table
table = table_class(data=self.get_table_data(), **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django_tables2/tables.py", line 364, in __init__
self.order_by = order_by
^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django_tables2/tables.py", line 542, in order_by
self.data.order_by(self._order_by)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django_tables2/data.py", line 224, in order_by
self.data = self.data.order_by(*order_by_accessors)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/db/models/query.py", line 1698, in order_by
raise TypeError("Cannot reorder a query once a slice has been taken.")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exception Type: TypeError at /club/
Exception Value: Cannot reorder a query once a slice has been taken.
Looks like it's line 135 in django_twc_toolbox.crud.views
:
paginator=None,
filterset=filterset,
)
else:
# Paginated response
page = self.paginate_queryset(queryset, paginate_by)
self.object_list = page.object_list
context = self.get_context_data(
โฆ
page_obj=page,
is_paginated=page.has_other_pages(),
paginator=page.paginator,
filterset=filterset,
)
Last time I tried, CRUDView
and the SingleTableMixin
from django-tables2 did not play well together. Not sure how much of a lift this will be TBH..
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.