Open susanodd opened 2 months ago
@susanodd I cannot see what the problem is. I ran the code in a Django shell and it seems fine:
>>> from django.db.models import OuterRef, Subquery, Count, Prefetch
>>> unassigned_glosses = Gloss.objects.filter(
... lemma__dataset=None,
... signlanguage=OuterRef('pk')
... ).order_by().values('signlanguage')
>>> count_unassigned_glosses = unassigned_glosses.annotate(cnt=Count('pk')).values('cnt')
>>> signlanguages = SignLanguage.objects.prefetch_related(
... Prefetch(
... 'dataset_set',
... queryset=Dataset.objects.all(),
... to_attr='datasets'
... )
... ).annotate(
... num_unassigned_glosses=Subquery(
... count_unassigned_glosses,
... output_field=models.IntegerField()
... )
... )
>>> signlanguages
<QuerySet [<SignLanguage: ASL>, <SignLanguage: AdaSL>, <SignLanguage: BISINDO>, <SignLanguage: Berbey SL>, <SignLanguage: CSL>, <SignLanguage: Catalan Sign Languag>, <SignLanguage: David Rose Signs>, <SignLanguage: EmblemsNL>, <SignLanguage: IS>, <SignLanguage: ISL>, <SignLanguage: JSL>, <SignLanguage: Kata Kolok>, <SignLanguage: Konchri Sain>, <SignLanguage: Korean Sign Language>, <SignLanguage: LSFB>, <SignLanguage: LaSiMa>, <SignLanguage: NGT>, <SignLanguage: NTS>, <SignLanguage: Sign Languages of CA>, <SignLanguage: TSL>, '...(remaining elements truncated)...']>
>>> signlanguages.count()
22
The page https://signbank.cls.ru.nl/datasets/unassigned_glosses also seems to work fine.
Yes, the code works without bugs, but the column on the right ought to show a selection of datasets that use the sign language. (It's supposed to be the 'dataset_set' but it is empty. It should show "datasets for this sign language" in the menu.
@susanodd I see what you mean now.
The problem is in this bit:
Because of the first line, if there are no unassigned glosses, it will go to the else and display "No datasets for this sign language".
A possible patch:
diff --git a/signbank/dictionary/templates/dictionary/unassigned_glosses.html b/signbank/dictionary/templates/dictionary/unassigned_glosses.html
index f1224837..42671971 100644
--- a/signbank/dictionary/templates/dictionary/unassigned_glosses.html
+++ b/signbank/dictionary/templates/dictionary/unassigned_glosses.html
@@ -74,6 +74,8 @@
<option value="{{ dataset.id }}">{{ dataset.name }}</option>
{% endfor %}
</select>
+ {% elif not signlanguage.num_unassigned_glosses %}
+ {% trans "No glosses to assign" %}
{% else %}
{% trans "No datasets for this sign language" %}
{% endif %}
This query finds no datasets for the sign language
https://github.com/Signbank/Global-signbank/blob/c11e21db589f0bf34582d07c05da3c9a9d4ea7e0/signbank/dictionary/views.py#L2463-L2474
It is used in the template at datasets/unassigned_glosses
The related model reference "dataset_set" does not find anything.