Skip to content

Commit

Permalink
Syntax fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
srugano committed Nov 13, 2023
1 parent a1bc873 commit d9c79f4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
8 changes: 4 additions & 4 deletions docs/source/_ext/djangodocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ def finish(self):
templatebuiltins = {
"ttags": [
n
for ((t, n), (l, a)) in xrefs.items()
if t == "templatetag" and l == "ref/templates/builtins"
for ((t, n), (l, a)) in xrefs.items() # noqa
if t == "templatetag" and l == "ref/templates/builtins" # noqa
],
"tfilters": [
n
for ((t, n), (l, a)) in xrefs.items()
if t == "templatefilter" and l == "ref/templates/builtins"
for ((t, n), (l, a)) in xrefs.items() # noqa
if t == "templatefilter" and l == "ref/templates/builtins" # noqa
],
}
outfilename = os.path.join(self.outdir, "templatebuiltins.js")
Expand Down
11 changes: 7 additions & 4 deletions src/adminactions/bulk_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
from adminactions.exceptions import ActionInterrupted
from adminactions.forms import CSVConfigForm
from adminactions.perms import get_permission_codename
from adminactions.signals import (adminaction_end, adminaction_requested,
adminaction_start,)
from adminactions.signals import adminaction_end, adminaction_requested, adminaction_start

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -147,7 +146,9 @@ def bulk_update(modeladmin, request, queryset): # noqa
if "apply" in request.POST:
form = bulk_update_form(request.POST, request.FILES, initial=form_initial)
csv_form = CSVConfigForm(request.POST, initial=csv_initial, prefix="csv")
map_form = BulkUpdateMappingForm(request.POST, initial=map_initial, model=modeladmin.model, prefix="fld")
map_form = BulkUpdateMappingForm(
request.POST, initial=map_initial, model=modeladmin.model, prefix="fld"
)

if form.is_valid() and csv_form.is_valid() and map_form.is_valid():
header = csv_form.cleaned_data.pop("header")
Expand Down Expand Up @@ -280,7 +281,9 @@ def _bulk_update( # noqa: max-complexity: 18
model_field = queryset.model._meta.get_field(field)
if model_field.is_relation and model_field.many_to_one:
related_model = model_field.related_model
related_field_name = model_field.to_fields[0] if model_field.to_fields else "pk"
related_field_name = (
model_field.to_fields[0] if model_field.to_fields else "pk"
)
related_field = related_model._meta.get_field(related_field_name)

if isinstance(related_field, models.UUIDField):
Expand Down
3 changes: 1 addition & 2 deletions tests/demo/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import uuid

import demo.models
import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models

import demo.models


class Migration(migrations.Migration):
initial = True
Expand Down
19 changes: 13 additions & 6 deletions tests/test_bulk_update.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import csv
from pathlib import Path

from demo.models import DemoModel, DemoOneToOne, DemoRelated
from django.conf import settings
from django.contrib.auth.models import User
from django.test import TestCase
Expand All @@ -10,8 +11,6 @@
from utils import CheckSignalsMixin, SelectRowsMixin, user_grant_permission
from webtest import Upload

from demo.models import DemoModel, DemoOneToOne, DemoRelated

__all__ = [
"BulkUpdateMemoryFileUploadHandlerTest",
"BulkUpdateTemporaryFileUploadHandlerTest",
Expand All @@ -24,7 +23,9 @@ class BulkUpdate(SelectRowsMixin, CheckSignalsMixin, WebTestMixin):
csrf_checks = True

_selected_rows = [0, 1]
_selectedr_rows = [0,]
_selectedr_rows = [
0,
]

action_name = "bulk_update"
sender_model = DemoModel
Expand Down Expand Up @@ -83,7 +84,9 @@ def _run_action_related_model(self, steps=2, **kwargs):
self._select_rows(form, selected_rows)
res = form.submit()
if steps >= 2:
res.forms["bulk-update"]["_file"] = Upload(str(Path(__file__).parent / "related_model_bulk_update.csv"))
res.forms["bulk-update"]["_file"] = Upload(
str(Path(__file__).parent / "related_model_bulk_update.csv")
)
res.forms["bulk-update"]["fld-id"] = "id"
res.forms["bulk-update"]["fld-index_field"] = ["id"]
res.forms["bulk-update"]["fld-demo"] = "demo_uuid"
Expand Down Expand Up @@ -229,7 +232,9 @@ def test_bulk_update_with_one_to_one_field(self):
"fld-onetoone": "one_to_one_id",
}
)
self.assertTrue(DemoModel.objects.filter(pk=demo_model_instance.pk, onetoone=demo_one_to_one_instance).exists())
self.assertTrue(
DemoModel.objects.filter(pk=demo_model_instance.pk, onetoone=demo_one_to_one_instance).exists()
)
self.assertEqual(res.status_code, 200)

def test_bulk_update_with_foreign_key(self):
Expand All @@ -249,7 +254,9 @@ def test_bulk_update_with_foreign_key(self):
}
)

self.assertTrue(DemoRelated.objects.filter(pk=demo_related_instance.pk, demo=new_demo_model_instance).exists())
self.assertTrue(
DemoRelated.objects.filter(pk=demo_related_instance.pk, demo=new_demo_model_instance).exists()
)
self.assertEqual(res.status_code, 200)


Expand Down

0 comments on commit d9c79f4

Please sign in to comment.