Skip to content

Commit

Permalink
Merge pull request #879 from rdmorganiser/fix_options
Browse files Browse the repository at this point in the history
Fix options endpoint for option set providers
  • Loading branch information
jochenklar authored Dec 21, 2023
2 parents d4266af + 0459498 commit bb58bf2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
<li ng-repeat="option in value.items"
ng-class="{'active': option.active}"
ng-mousedown="service.selectAutocomplete(value, option)">
<span ng-show="option.text_and_help">{$ option.text_and_help $}</span>
<span ng-show="option.text">{$ option.text $}</span>
{$ option.text_and_help $}
</li>
</ul>
</div>
Expand Down
7 changes: 5 additions & 2 deletions rdmo/projects/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ def resolve(self, request, pk=None):
@action(detail=True, permission_classes=(HasModelPermission | HasProjectPermission, ))
def options(self, request, pk=None):
project = self.get_object()

try:
try:
optionset_id = request.GET.get('optionset')
Expand All @@ -163,9 +162,13 @@ def options(self, request, pk=None):
raise NotFound() from e

# check if the optionset belongs to this catalog and if it has a provider
project.catalog.prefetch_elements()
if Question.objects.filter_by_catalog(project.catalog).filter(optionsets=optionset) and \
optionset.provider is not None:
options = optionset.provider.get_options(project, search=request.GET.get('search'))
options = [
dict(**option, text_and_help=option.get('text_and_help', 'text'))
for option in optionset.provider.get_options(project, search=request.GET.get('search'))
]
return Response(options)

except OptionSet.DoesNotExist:
Expand Down

0 comments on commit bb58bf2

Please sign in to comment.