Skip to content

Commit

Permalink
v9.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronny Vedrilla committed Nov 3, 2023
1 parent ea65f43 commit 78d8add
Show file tree
Hide file tree
Showing 100 changed files with 904 additions and 903 deletions.
52 changes: 26 additions & 26 deletions .ambient-package-update/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
from ambient_package_update.metadata.ruff_ignored_inspection import RuffIgnoredInspection

METADATA = PackageMetadata(
package_name='ambient_toolbox',
company='Ambient Innovation: GmbH',
package_name="ambient_toolbox",
company="Ambient Innovation: GmbH",
authors=[
PackageAuthor(
name='Ambient Digital',
email='[email protected]',
name="Ambient Digital",
email="[email protected]",
),
],
development_status='5 - Production/Stable',
development_status="5 - Production/Stable",
license=LICENSE_MIT,
license_year=2012,
readme_content=ReadmeContent(
tagline='Python toolbox of Ambient Digital containing an abundance of useful tools and gadgets.',
tagline="Python toolbox of Ambient Digital containing an abundance of useful tools and gadgets.",
content="""## Features
* Useful classes and mixins for Django admin
Expand Down Expand Up @@ -51,38 +51,38 @@
""",
),
dependencies=[
'Django>=3.2.20',
'bleach>=1.4,<6',
'python-dateutil>=2.5.3',
"Django>=3.2.20",
"bleach>=1.4,<6",
"python-dateutil>=2.5.3",
],
supported_django_versions=SUPPORTED_DJANGO_VERSIONS,
supported_python_versions=SUPPORTED_PYTHON_VERSIONS,
has_migrations=True,
optional_dependencies={
'dev': [
"dev": [
*DEV_DEPENDENCIES,
'gevent~=22.10',
"gevent~=22.10",
],
'drf': [
'djangorestframework>=3.8.2',
"drf": [
"djangorestframework>=3.8.2",
],
'graphql': [
'graphene-django>=2.2.0',
'django-graphql-jwt>=0.2.1',
"graphql": [
"graphene-django>=2.2.0",
"django-graphql-jwt>=0.2.1",
],
'sentry': [
'sentry-sdk>=1.19.1',
"sentry": [
"sentry-sdk>=1.19.1",
],
'view-layer': [
'django-crispy-forms>=1.4.0',
"view-layer": [
"django-crispy-forms>=1.4.0",
],
},
ruff_ignore_list=[
RuffIgnoredInspection(key='N999', comment="Project name contains underscore, not fixable"),
RuffIgnoredInspection(key='A003', comment="Django attributes shadow python builtins"),
RuffIgnoredInspection(key='DJ001', comment="Django model text-based fields shouldn't be nullable"),
RuffIgnoredInspection(key='B905', comment="Can be enabled when Python <=3.9 support is dropped"),
RuffIgnoredInspection(key='DTZ001', comment="TODO will affect \"tz_today()\" method"),
RuffIgnoredInspection(key='DTZ005', comment="TODO will affect \"tz_today()\" method"),
RuffIgnoredInspection(key="N999", comment="Project name contains underscore, not fixable"),
RuffIgnoredInspection(key="A003", comment="Django attributes shadow python builtins"),
RuffIgnoredInspection(key="DJ001", comment="Django model text-based fields shouldn't be nullable"),
RuffIgnoredInspection(key="B905", comment="Can be enabled when Python <=3.9 support is dropped"),
RuffIgnoredInspection(key="DTZ001", comment='TODO will affect "tz_today()" method'),
RuffIgnoredInspection(key="DTZ005", comment='TODO will affect "tz_today()" method'),
],
)
4 changes: 2 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[run]
omit =
setup.py,
*_test.py,
tests.py,
tests/*,
testapp/*,
*tests*,
conftest.py

[report]
Expand Down
16 changes: 6 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
# https://pre-commit.com/

repos:
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.10.0
hooks:
- id: black
args: [ --check, --diff, --config, ./pyproject.toml ]
stages: [ push ]

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.1.1'
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.3
hooks:
# Run the Ruff linter.
- id: ruff
args: [ --fix, --unsafe-fixes, --exit-non-zero-on-fix ]
args: [--fix, --exit-non-zero-on-fix]
# Run the Ruff formatter.
- id: ruff-format

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
Expand Down
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
**9.1.6** (2023-10-31)
* Added migration docs to Readme
* Added migration check to GitHub actions
* Switched formatter from `black` to `ruff`
* Updates from ambient updater
* Fixes typos

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
[![Downloads](https://static.pepy.tech/badge/ambient-toolbox)](https://pepy.tech/project/ambient-toolbox)
[![Coverage](https://img.shields.io/badge/Coverage-100%25-success)](https://github.com/ambient-innovation/ambient-toolbox/actions?workflow=CI)
[![Linting](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![Coding Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/python/black)
[![Coding Style](https://img.shields.io/badge/code%20style-Ruff-000000.svg)](https://github.com/astral-sh/ruff)
[![Documentation Status](https://readthedocs.org/projects/ambient-toolbox/badge/?version=latest)](https://ambient-toolbox.readthedocs.io/en/latest/?badge=latest)

Python toolbox of Ambient Digital containing an abundance of useful tools and gadgets.
Expand Down
2 changes: 1 addition & 1 deletion ambient_toolbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Python toolbox of Ambient Digital containing an abundance of useful tools and gadgets."""

__version__ = '9.1.6'
__version__ = "9.1.6"
10 changes: 5 additions & 5 deletions ambient_toolbox/admin/model_admins/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ def get_readonly_fields(self, request, obj=None):
]
return self.readonly_fields

def changeform_view(self, request, object_id=None, form_url='', extra_context=None):
def changeform_view(self, request, object_id=None, form_url="", extra_context=None):
extra_context = extra_context or {}
extra_context['show_save_and_continue'] = False
extra_context['show_save'] = False
extra_context["show_save_and_continue"] = False
extra_context["show_save"] = False
return super().changeform_view(request, object_id, extra_context=extra_context)

def has_add_permission(self, request):
Expand All @@ -39,8 +39,8 @@ class EditableOnlyAdmin(admin.ModelAdmin):
def get_actions(self, request):
# Disable delete
actions = super().get_actions(request)
if 'delete_selected' in actions:
del actions['delete_selected']
if "delete_selected" in actions:
del actions["delete_selected"]
return actions

def has_add_permission(self, request):
Expand Down
2 changes: 1 addition & 1 deletion ambient_toolbox/admin/model_admins/inlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ def get_readonly_fields(self, request, obj=None):
+ [field.name for field in self.opts.local_many_to_many]
)
)
result.remove('id')
result.remove("id")
return result
16 changes: 8 additions & 8 deletions ambient_toolbox/admin/model_admins/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AdminCreateFormMixin:
def get_form(self, request, obj=None, **kwargs):
defaults = {}
if obj is None:
defaults['form'] = self.add_form
defaults["form"] = self.add_form
defaults.update(kwargs)
return super().get_form(request, obj, **defaults)

Expand Down Expand Up @@ -58,7 +58,7 @@ def _resolve_url(request):
def get_parent_object_from_request(self, request):
resolved = self._resolve_url(request)
if resolved.kwargs:
return self.parent_model.objects.get(pk=resolved.kwargs.get('object_id', None))
return self.parent_model.objects.get(pk=resolved.kwargs.get("object_id", None))
return None

def get_formset(self, request, obj=None, **kwargs):
Expand All @@ -75,7 +75,7 @@ class FetchObjectMixin:
def get_object_from_request(self, request):
resolved = resolve(request.path_info)
if resolved.kwargs:
return self.model.objects.get(pk=resolved.kwargs.get('object_id', None))
return self.model.objects.get(pk=resolved.kwargs.get("object_id", None))
return None


Expand All @@ -90,10 +90,10 @@ def get_readonly_fields(self, request, obj=None):
Set the fields CommonInfo handles to readonly to avoid users fiddling around with them.
"""
return super().get_readonly_fields(request, obj) + (
'created_by',
'lastmodified_by',
'created_at',
'lastmodified_at',
"created_by",
"lastmodified_by",
"created_at",
"lastmodified_at",
)

def get_user_obj(self, request) -> Optional[AbstractUser]:
Expand Down Expand Up @@ -145,7 +145,7 @@ def change_view(self, request, *args, **kwargs):
else:
opts = self.model._meta
url = reverse(
'admin:{app}_{model}_changelist'.format(
"admin:{app}_{model}_changelist".format(
app=opts.app_label,
model=opts.model_name,
)
Expand Down
16 changes: 8 additions & 8 deletions ambient_toolbox/admin/views/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ class AdminCrispyForm(forms.Form):
Base crispy form to be used in custom views within the django admin.
"""

section_title = _('No title defined')
button_label = _('Save')
section_title = _("No title defined")
button_label = _("Save")

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

# Build fieldset
fieldset_list = ['']
fieldset_list = [""]
for field in self.fields:
fieldset_list.append(Div(field, css_class='form-row field-name')) # noqa: PERF401
fieldset_list.append(Div(field, css_class="form-row field-name")) # noqa: PERF401

# Crispy
self.helper = FormHelper()
self.helper.form_method = 'post'
self.helper.add_input(Submit('submit', self.button_label, css_class="button btn-primary"))
self.helper.form_method = "post"
self.helper.add_input(Submit("submit", self.button_label, css_class="button btn-primary"))
self.helper.layout = Layout(
Div(
Div(HTML(f'<h2>{self.section_title}</h2>'), Fieldset(*fieldset_list), css_class='module aligned'),
css_class='custom-form',
Div(HTML(f"<h2>{self.section_title}</h2>"), Fieldset(*fieldset_list), css_class="module aligned"),
css_class="custom-form",
),
)
32 changes: 16 additions & 16 deletions ambient_toolbox/admin/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AdminViewMixin:
"""

model = None
admin_page_title = ''
admin_page_title = ""

def has_view_permission(self, user, **kwargs) -> bool:
"""
Expand Down Expand Up @@ -39,23 +39,23 @@ def get_context_data(self, **kwargs):
admin_site = self.get_admin_site()
context.update(
{
'site_header': admin_site.site_header,
'site_title': admin_site.site_title,
'title': self.admin_page_title,
'name': self.admin_page_title,
'original': self.admin_page_title,
'is_nav_sidebar_enabled': True,
'available_apps': admin.site.get_app_list(self.request),
'opts': {
'app_label': self.model._meta.app_label,
'verbose_name': self.model._meta.verbose_name,
'verbose_name_plural': self.model._meta.verbose_name_plural,
'model_name': self.model._meta.model_name,
'app_config': {
'verbose_name': self.model._meta.app_config.verbose_name,
"site_header": admin_site.site_header,
"site_title": admin_site.site_title,
"title": self.admin_page_title,
"name": self.admin_page_title,
"original": self.admin_page_title,
"is_nav_sidebar_enabled": True,
"available_apps": admin.site.get_app_list(self.request),
"opts": {
"app_label": self.model._meta.app_label,
"verbose_name": self.model._meta.verbose_name,
"verbose_name_plural": self.model._meta.verbose_name_plural,
"model_name": self.model._meta.model_name,
"app_config": {
"verbose_name": self.model._meta.app_config.verbose_name,
},
},
'has_permission': admin_site.has_permission(request=self.request),
"has_permission": admin_site.has_permission(request=self.request),
}
)
return context
4 changes: 2 additions & 2 deletions ambient_toolbox/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@


class AmbientToolboxConfig(AppConfig):
name = 'ambient_toolbox'
verbose_name = _('Ambient Toolbox')
name = "ambient_toolbox"
verbose_name = _("Ambient Toolbox")
2 changes: 1 addition & 1 deletion ambient_toolbox/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@


def server_settings(request):
return {'DEBUG_MODE': settings.DEBUG, 'SERVER_URL': settings.SERVER_URL}
return {"DEBUG_MODE": settings.DEBUG, "SERVER_URL": settings.SERVER_URL}
2 changes: 1 addition & 1 deletion ambient_toolbox/drf/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def to_representation(self, value):
# parent serializer.
# Explanation: With `many=True` DRF creates an intermediate `ListSerializer`. It has `many=True`, so we'll end
# up in the first if-case. If we do not use `many=True`, the "many" attribute is not set.
if getattr(self.parent, 'many', False):
if getattr(self.parent, "many", False):
parent = self.parent.parent
else:
parent = self.parent
Expand Down
6 changes: 3 additions & 3 deletions ambient_toolbox/drf/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class CommonInfoSerializer(BaseModelSerializer):

def validate(self, data):
data = super().validate(data)
request = self.context.get('request', None)
request = self.context.get("request", None)

if request.user:
data['lastmodified_by'] = request.user
data["lastmodified_by"] = request.user
if not self.instance:
# If this is a new instance, set created_by
data['created_by'] = request.user
data["created_by"] = request.user

return data
4 changes: 2 additions & 2 deletions ambient_toolbox/drf/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ def execute_request( # noqa: PLR0913
*,
url,
view_kwargs=None,
method='get',
method="get",
data=None,
view_class=None,
user=None,
viewset_kwargs=None,
data_format='json',
data_format="json",
) -> Response:
"""
Helper method which wraps all relevant setup to execute a request to the backends api
Expand Down
Loading

0 comments on commit 78d8add

Please sign in to comment.