Refactor approval queue to display last meaningful status #94

Merged
Oleg-Komarov merged 13 commits from approval-queue into main 2024-04-30 10:48:38 +02:00
3 changed files with 14 additions and 14 deletions
Showing only changes of commit c28dbc373b - Show all commits

View File

@ -294,9 +294,7 @@ class Extension(CreatedModifiedMixin, RatingMixin, TrackChangesMixin, models.Mod
def latest_version(self):
"""Retrieve the latest version."""
versions = [
v
for v in self.versions.select_related('file', 'file__validation').all()
if v.file and v.file.status in self.valid_file_statuses
v for v in self.versions.all() if v.file and v.file.status in self.valid_file_statuses
]
if not versions:
return None
@ -371,12 +369,8 @@ class Extension(CreatedModifiedMixin, RatingMixin, TrackChangesMixin, models.Mod
)
def suspicious_files(self):
versions = (
self.versions.select_related('file', 'file__validation')
.filter(file__validation__is_ok=False)
.all()
)
return [v.file for v in versions]
versions = self.versions.all()
return [v.file for v in versions if not v.file.validation.is_ok]
@classmethod
def get_lookup_field(cls, identifier):

View File

@ -12,13 +12,11 @@
<h3>Tags</h3>
<ul>
{% for list_tag in tags %}
{% if list_tag.versions.all|length %}
<li class="{% if tag == list_tag %}is-active{% endif %}">
<a href="{% url "extensions:by-tag" tag_slug=list_tag.slug %}" title="{{ list_tag.name }}">
{{ list_tag.name }}
</a>
</li>
{% endif %}
{% endfor %}
</ul>
</div>

View File

@ -104,7 +104,15 @@ class SearchView(ListedExtensionsView):
| Q(versions__tags__name__icontains=token)
)
queryset = queryset.filter(search_query).distinct()
return queryset
return queryset.prefetch_related(
'authors',
'preview_set',
'preview_set__file',
'ratings',
'versions',
'versions__file',
'versions__tags',
)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
@ -121,9 +129,9 @@ class SearchView(ListedExtensionsView):
# Determine which tags to list depending on the context.
if context.get('type'):
tag_type_id = self._get_type_id_by_slug()
context['tags'] = Tag.objects.filter(type=tag_type_id)
context['tags'] = Tag.objects.filter(type=tag_type_id).exclude(versions=None)
elif context.get('tag'):
tag_type_id = context['tag'].type
context['tags'] = Tag.objects.filter(type=tag_type_id)
context['tags'] = Tag.objects.filter(type=tag_type_id).exclude(versions=None)
return context