Skip to content

Commit

Permalink
Drop the inline upload form
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Jul 1, 2024
1 parent 5582039 commit f25e26c
Show file tree
Hide file tree
Showing 6 changed files with 3 additions and 84 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Next version
- Added the ``extra_context`` argument to our ``changelist_view``. Thanks
@underdoeg!
- Switched from ESLint to biome.
- Dropped the inline upload form in the cabinet foreign key widget. It was
extremely slow when having many folders and many cabinet foreign keys.


0.14 (2024-02-02)
Expand Down
18 changes: 0 additions & 18 deletions cabinet/fields.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,18 @@
from django import forms
from django.conf import settings
from django.contrib.admin.widgets import ForeignKeyRawIdWidget
from django.core.exceptions import ValidationError
from django.db import models
from django.urls import NoReverseMatch, reverse
from django.utils.text import Truncator
from django.utils.translation import gettext_lazy as _
from tree_queries.forms import TreeNodeChoiceField

from cabinet.models import Folder


class UploadForm(forms.Form):
folder = TreeNodeChoiceField(label=_("folder"), queryset=Folder.objects.all())
file = forms.FileField(label=_("file"))


class CabinetFileRawIdWidget(ForeignKeyRawIdWidget):
template_name = "admin/cabinet/cabinet_file_raw_id_widget.html"

class Media:
css = {"all": ["cabinet/inline-upload.css"]}
js = ["admin/js/jquery.init.js", "cabinet/inline-upload.js"]

def get_context(self, name, value, attrs):
context = super().get_context(name, value, attrs)
instance = getattr(self, "instance", None)
context["cabinet"] = {
"upload_form": UploadForm(
prefix=f"cu-{id(self)}",
initial={"folder": instance and instance.folder_id},
),
"instance": instance,
}
context["related_url"] += "&folder__id__exact={}".format(
Expand Down
18 changes: 0 additions & 18 deletions cabinet/static/cabinet/inline-upload.css

This file was deleted.

39 changes: 0 additions & 39 deletions cabinet/static/cabinet/inline-upload.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<div class="cabinet-inline-wrap" data-url="{% url 'admin:cabinet_upload' %}">
<div class="cabinet-inline-field">
{% include "admin/widgets/foreign_key_raw_id.html" %}
{% if cabinet.instance.image_file %}<img src="{{ cabinet.instance.image_file.url }}" alt="" style="max-width:4rem;max-height:4rem;margin-left:0.5rem;" />{% endif %} {# TODO replace thumbnail after inline upload #}
</div>
<div class="cabinet-inline-upload">
{{ cabinet.upload_form.folder }}
{{ cabinet.upload_form.file }}
{% if cabinet.instance.image_file %}<img src="{{ cabinet.instance.image_file.url }}" alt="" style="max-width:4rem;max-height:4rem;margin-left:0.5rem;" />{% endif %}
</div>
</div>
4 changes: 0 additions & 4 deletions tests/testapp/test_cabinet.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,6 @@ def test_cabinet_foreign_key(self):
c = self.login()
response = c.get("/admin/testapp/stuff/add/")

self.assertContains(response, 'class="cabinet-inline-upload"')
self.assertContains(response, 'type="file"')
self.assertContains(
response,
'href="/admin/cabinet/file/?_to_field=id&amp;folder__id__exact=last"',
Expand All @@ -386,8 +384,6 @@ def test_cabinet_foreign_key(self):
stuff = Stuff.objects.create(title="Test", file=file)
response = c.get(reverse("admin:testapp_stuff_change", args=(stuff.id,)))

self.assertContains(response, 'class="cabinet-inline-upload"')
self.assertContains(response, 'type="file"')
self.assertContains(
response,
f'href="/admin/cabinet/file/?_to_field=id&amp;folder__id__exact={folder.id}"',
Expand Down

0 comments on commit f25e26c

Please sign in to comment.