-
Notifications
You must be signed in to change notification settings - Fork 168
Use server side search for user fields #2677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
hansegucker
wants to merge
11
commits into
e-valuation:main
Choose a base branch
from
hansegucker:server-side-user-search
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f8ad165
Migrate some user fields to server side search
hansegucker 2a3c3d1
Use more server side search
hansegucker 28e1cbd
Use server side search for more user fields
hansegucker 0d2cb40
Clean up naming and structure of user profile server side search
hansegucker a85aabf
Fix more things for user profile options
hansegucker 23734a6
Use fuzzy matching for searching user profiles
hansegucker 7fc093b
Add tests for user profile select
hansegucker 46fa8a6
Solve more review comments
hansegucker f0eb866
Fix some tests
hansegucker fafdf19
Try to fix live server tests
hansegucker 35fc683
Fix tests
hansegucker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
| @@ -1,11 +1,15 @@ | ||
| from datetime import datetime | ||
|
|
||
| from django import forms | ||
| from django.db.models import Q | ||
| from django.db.models import Q, QuerySet | ||
| from django.forms.widgets import CheckboxSelectMultiple | ||
| from django.urls import reverse | ||
| from django.utils.translation import gettext_lazy as _ | ||
|
|
||
| from evap.evaluation.forms import UserModelChoiceField, UserModelMultipleChoiceField | ||
| from evap.evaluation.forms import ( | ||
| UserModelChoiceField, | ||
| UserModelMultipleChoiceField, | ||
| ) | ||
| from evap.evaluation.models import Course, Evaluation, Questionnaire, UserProfile | ||
| from evap.evaluation.tools import vote_end_datetime | ||
| from evap.staff.forms import ContributionForm | ||
|
|
@@ -69,10 +73,8 @@ def __init__(self, *args, **kwargs): | |
| self.fields["vote_start_datetime"].localize = True | ||
| self.fields["vote_end_date"].localize = True | ||
|
|
||
| queryset = UserProfile.objects.exclude(is_active=False) | ||
| if self.instance.pk is not None: | ||
| queryset = (queryset | self.instance.participants.all()).distinct() | ||
| self.fields["participants"].queryset = queryset | ||
| self.fields["participants"].queryset = self.get_participants_queryset(self.instance) | ||
| self.fields["participants"].widget.options_endpoint = reverse("contributor:participant_options") | ||
|
|
||
| if general_contribution := self.instance.general_contribution: | ||
| self.fields["general_questionnaires"].initial = [ | ||
|
|
@@ -90,6 +92,13 @@ def __init__(self, *args, **kwargs): | |
| self.fields["participants"].disabled = True | ||
| self.cms_disclaimer = _("Participants are regularly updated with registrations from the CMS.") | ||
|
|
||
| @classmethod | ||
| def get_participants_queryset(cls, evaluation: Evaluation | None) -> QuerySet[UserProfile]: | ||
| queryset = UserProfile.objects.exclude(is_active=False) | ||
| if evaluation is not None and evaluation.pk is not None: | ||
| queryset = (queryset | evaluation.participants.all()).distinct() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had hoped we would not need this anymore (by just passing the initial options in HTML) -- why is this still needed here? |
||
| return queryset | ||
|
|
||
| def clean(self): | ||
| super().clean() | ||
|
|
||
|
|
@@ -157,6 +166,8 @@ def __init__(self, *args, **kwargs): | |
|
|
||
|
|
||
| class DelegateSelectionForm(forms.Form): | ||
| delegate_to = UserModelChoiceField( | ||
| label=_("Delegate to"), queryset=UserProfile.objects.exclude(is_active=False).exclude(is_proxy_user=True) | ||
| ) | ||
| delegate_to = UserModelChoiceField(label=_("Delegate to"), queryset=UserProfile.objects.get_delegate_options()) | ||
|
|
||
| def __init__(self, *args, **kwargs): | ||
| super().__init__(*args, **kwargs) | ||
| self.fields["delegate_to"].widget.options_endpoint = reverse("contributor:delegate_options") | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
| from django.contrib.postgres.operations import TrigramExtension | ||
| from django.db import migrations | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("evaluation", "0164_remove_questionnaire_questionnaire_visibility_choices_and_more"), | ||
| ] | ||
|
|
||
| operations = [TrigramExtension()] |
This file contains hidden or 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 hidden or 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
12 changes: 12 additions & 0 deletions
12
evap/evaluation/templates/django/forms/widgets/server_side_options_select.html
This file contains hidden or 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,12 @@ | ||
| <select class="form-select 2" name="{{ widget.name }}"{% include 'django/forms/widgets/attrs.html' %} autocomplete="off"> | ||
| {# Use this to render currently selected options, new options are fetched from server #} | ||
| {% for group_name, group_choices, group_index in widget.optgroups %} | ||
| {% if group_name %} | ||
| <optgroup label="{{ group_name }}"> | ||
| {% endif %} | ||
| {% for option in group_choices %}{% if option.selected %}{% include option.template_name with widget=option %}{% endif %}{% endfor %} | ||
| {% if group_name %} | ||
| </optgroup> | ||
| {% endif %} | ||
| {% endfor %} | ||
|
hansegucker marked this conversation as resolved.
|
||
| </select> | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.