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

View File

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

View File

@ -104,7 +104,15 @@ class SearchView(ListedExtensionsView):
| Q(versions__tags__name__icontains=token) | Q(versions__tags__name__icontains=token)
) )
queryset = queryset.filter(search_query).distinct() 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): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
@ -121,9 +129,9 @@ class SearchView(ListedExtensionsView):
# Determine which tags to list depending on the context. # Determine which tags to list depending on the context.
if context.get('type'): if context.get('type'):
tag_type_id = self._get_type_id_by_slug() 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'): elif context.get('tag'):
tag_type_id = context['tag'].type 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 return context