Skip to content

Commit

Permalink
#677: change Harvest TC selection to autocomplete, remove harvest_cle…
Browse files Browse the repository at this point in the history
…ar_tcs.html as it's no longer needed
  • Loading branch information
Fasand committed Aug 29, 2024
1 parent 7816029 commit f58a1be
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 11 deletions.
3 changes: 3 additions & 0 deletions Seeder/harvests/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def __init__(self, *args, **kwargs):
"custom_sources": autocomplete.ModelSelect2Multiple(
url="source:source_autocomplete"
),
"topic_collections": autocomplete.ModelSelect2Multiple(
url="harvests:internal_collection_autocomplete",
),
**custom_seeds_widget,
}

Expand Down
1 change: 0 additions & 1 deletion Seeder/harvests/templates/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ <h4 class="modal-title" id="myModalLabel">{% trans 'Add harvest' %}</h4>
{% bootstrap_form harvest_form %}
{% include "harvest_autoselect.html" %}
{% include "harvest_config_ajax.html" %}
{% include "harvest_clear_tcs.html" %}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">{% trans 'Close' %}</button>
Expand Down
1 change: 0 additions & 1 deletion Seeder/harvests/templates/harvest_add_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
{{ block.super }}
{% include "harvest_autoselect.html" %}
{% include "harvest_config_ajax.html" %}
{% include "harvest_clear_tcs.html" %}
{% endblock %}
7 changes: 0 additions & 7 deletions Seeder/harvests/templates/harvest_clear_tcs.html

This file was deleted.

1 change: 0 additions & 1 deletion Seeder/harvests/templates/harvest_edit_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
{{ block.super }}
{% include "harvest_autoselect.html" with editing=True %}
{% include "harvest_config_ajax.html" %}
{% include "harvest_clear_tcs.html" %}
{% endblock %}
3 changes: 3 additions & 0 deletions Seeder/harvests/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def to_url(self, value):
name='internal_collection_urls'),
path('<int:pk>/history', InternalCollectionHistory.as_view(),
name='internal_collection_history'),
path('internal_collection_autocomplete',
InternalCollectionAutocomplete.as_view(),
name="internal_collection_autocomplete")
]

# External Topic Collections
Expand Down
16 changes: 15 additions & 1 deletion Seeder/harvests/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import time
import re
from datetime import date

from dal import autocomplete
import datetime
from django.db.models import Q
from django.urls import reverse
from django.http import Http404
from django.contrib import messages
Expand Down Expand Up @@ -548,6 +549,19 @@ class InternalCollectionHistory(InternalTCView, generic_views.HistoryView):
"""
pass


class InternalCollectionAutocomplete(autocomplete.Select2QuerySetView):
def get_queryset(self):
if not self.request.user.is_authenticated:
return models.TopicCollection.objects.none()
qs = models.TopicCollection.objects.all()
if self.q:
qs = qs.filter(
Q(title__icontains=self.q) |
Q(collection_alias__icontains=self.q)
)
return qs.distinct()

# ========================== #
# External Topic Collections #
# ========================== #
Expand Down

0 comments on commit f58a1be

Please sign in to comment.