-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '146-display-calculated-usage'
Conflicts: wagtail/wagtailimages/models.py wagtail/wagtailimages/templates/wagtailimages/images/edit.html wagtail/wagtailimages/tests.py wagtail/wagtailimages/urls.py wagtail/wagtailimages/views/images.py
- Loading branch information
Showing
24 changed files
with
501 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from modelcluster.fields import ParentalKey | ||
|
||
from wagtail.wagtailcore.models import Page | ||
|
||
|
||
def get_object_usage(obj): | ||
"Returns a queryset of pages that link to a particular object" | ||
|
||
pages = Page.objects.none() | ||
|
||
# get all the relation objects for obj | ||
relations = type(obj)._meta.get_all_related_objects( | ||
include_hidden=True, | ||
include_proxy_eq=True | ||
) | ||
for relation in relations: | ||
# if the relation is between obj and a page, get the page | ||
if issubclass(relation.model, Page): | ||
pages |= Page.objects.filter( | ||
id__in=relation.model._base_manager.filter(**{ | ||
relation.field.name: obj.id | ||
}).values_list('id', flat=True) | ||
) | ||
else: | ||
# if the relation is between obj and an object that has a page as a | ||
# property, return the page | ||
for f in relation.model._meta.fields: | ||
if isinstance(f, ParentalKey) and issubclass(f.rel.to, Page): | ||
pages |= Page.objects.filter( | ||
id__in=relation.model._base_manager.filter( | ||
**{ | ||
relation.field.name: obj.id | ||
}).values_list(f.attname, flat=True) | ||
) | ||
|
||
return pages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
wagtail/wagtaildocs/templates/wagtaildocs/documents/usage.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{% extends "wagtailadmin/base.html" %} | ||
{% load i18n %} | ||
{% block titletag %}{% blocktrans with title=document.title %}Usage of {{ title }}{% endblocktrans %}{% endblock %} | ||
{% block content %} | ||
{% trans "Usage of" as usage_str %} | ||
{% include "wagtailadmin/shared/header.html" with title=usage_str subtitle=document.title %} | ||
|
||
<div class="nice-padding"> | ||
<table class="listing"> | ||
<col /> | ||
<col width="30%"/> | ||
<col width="15%"/> | ||
<col width="15%"/> | ||
<thead> | ||
<tr> | ||
<th class="title">{% trans "Title" %}</th> | ||
<th>{% trans "Parent" %}</th> | ||
<th>{% trans "Type" %}</th> | ||
<th>{% trans "Status" %}</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for page in used_by %} | ||
<tr> | ||
<td class="title" valign="top"> | ||
<h2><a href="{% url 'wagtailadmin_pages_edit' page.id %}" title="{% trans 'Edit this page' %}">{{ page.title }}</a></h2> | ||
</td> | ||
<td> | ||
{% if page.get_parent %} | ||
<a href="{% url 'wagtailadmin_explore' page.get_parent.id %}">{{ page.get_parent.title }}</a> | ||
{% endif %} | ||
</td> | ||
<td> | ||
{{ page.content_type.model_class.get_verbose_name }} | ||
</td> | ||
<td> | ||
{% if page.live %} | ||
<a href="{{ page.url }}" target="_blank" class="status-tag {% if page.status_string != "draft" %}primary{% endif %}">{{ page.status_string }}</a> | ||
{% else %} | ||
<span class="status-tag {% if page.status_string != "draft" %}primary{% endif %}">{{ page.status_string }}</span> | ||
{% endif %} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
</div> | ||
{% include "wagtailadmin/shared/pagination_nav.html" with items=used_by linkurl="-" %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.