kopia lustrzana https://github.com/wagtail/wagtail
Move images and documents get_usage().count() call to view code (#12691)
The get_usage() method returns a ReferenceGroups instance that defines a __getitem__ method. Accessing get_usage().count() from the template means that Django tries to access the count via ["count"], which fails, then continues by using getattr(reference_groups, "count") before finally calling the count method. We have seen reports where the blocktranslate tag fails because the usage_count_val is not a number. We haven't got a reproducible example, but this would help surface any errors, as the exception would be raised from the Python code rather than the template.pull/12721/head
rodzic
57d141c701
commit
23b9f4aca9
docs/releases
wagtail
documents
templates/wagtaildocs/documents
views
|
@ -101,6 +101,7 @@ Changelog
|
|||
* Maintenance: Add a new Stimulus `FormsetController` (`w-formset`) to support dynamic formset insertion/deletion behavior (LB (Ben) Johnston)
|
||||
* Maintenance: Enable breadcrumbs by default on admin views using generic templates (Sage Abdullah)
|
||||
* Maintenance: Refactor pages `revisions_revert` view to be a subclass of `EditView` (Sage Abdullah)
|
||||
* Maintenance: Move images and documents `get_usage().count()` call to view code (Sage Abdullah)
|
||||
|
||||
|
||||
6.3.2 (xx.xx.xxxx) - IN DEVELOPMENT
|
||||
|
|
|
@ -119,6 +119,7 @@ depth: 1
|
|||
* Add a new Stimulus `FormsetController` (`w-formset`) to support dynamic formset insertion/deletion behavior (LB (Ben) Johnston)
|
||||
* Enable breadcrumbs by default on admin views using generic templates (Sage Abdullah)
|
||||
* Refactor pages `revisions_revert` view to be a subclass of `EditView` (Sage Abdullah)
|
||||
* Move images and documents `get_usage().count()` call to view code (Sage Abdullah)
|
||||
|
||||
## Upgrade considerations - changes affecting all projects
|
||||
|
||||
|
|
|
@ -24,9 +24,7 @@
|
|||
|
||||
<dt>{% trans "Usage" %}</dt>
|
||||
<dd>
|
||||
{% with usage_count_val=document.get_usage.count %}
|
||||
<a href="{{ document.usage_url }}">{% blocktrans trimmed with usage_count=usage_count_val|intcomma count usage_count_val=usage_count_val %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
|
||||
{% endwith %}
|
||||
<a href="{{ document.usage_url }}">{% blocktrans trimmed with usage_count=usage_count_val|intcomma count usage_count_val=usage_count_val %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
|
|
@ -251,6 +251,7 @@ class EditView(generic.EditView):
|
|||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["usage_count_val"] = self.object.get_usage().count()
|
||||
context["filesize"] = self.object.get_file_size()
|
||||
context["next"] = self.next_url
|
||||
return context
|
||||
|
|
|
@ -63,9 +63,7 @@
|
|||
|
||||
<dt>{% trans "Usage" %}</dt>
|
||||
<dd>
|
||||
{% with image.get_usage.count as usage_count_val %}
|
||||
<a href="{{ image.usage_url }}">{% blocktrans trimmed with usage_count=usage_count_val|intcomma count usage_count_val=usage_count_val %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
|
||||
{% endwith %}
|
||||
<a href="{{ image.usage_url }}">{% blocktrans trimmed with usage_count=usage_count_val|intcomma count usage_count_val=usage_count_val %}Used {{ usage_count }} time{% plural %}Used {{ usage_count }} times{% endblocktrans %}</a>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
|
|
|
@ -185,6 +185,7 @@ class EditView(generic.EditView):
|
|||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context["next"] = self.next_url
|
||||
context["usage_count_val"] = self.object.get_usage().count()
|
||||
|
||||
try:
|
||||
context["filesize"] = self.object.get_file_size()
|
||||
|
|
Ładowanie…
Reference in New Issue