Skip to content
Snippets Groups Projects
Commit 20ae3ea5 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[experiments][api] Refactor filter usage

Use list comprehension and sets.
parent e0d40a41
No related branches found
No related tags found
2 merge requests!2551.4.x,!242Py3 compatibility
......@@ -102,7 +102,7 @@ class ListCreateExperimentsView(ListCreateContributionView):
def get(self, request, author_name):
def _getStatusLabel(status):
return filter(lambda x: x[0] == status, Experiment.STATUS)[0][1]
return [s for s in Experiment.STATUS if s[0] == status][0][1]
def _custom_compare(exp1, exp2):
PENDING = _getStatusLabel(Experiment.PENDING)
......@@ -134,8 +134,8 @@ class ListCreateExperimentsView(ListCreateContributionView):
# Retrieve the experiments
fields_to_return_original = self.get_serializer_fields(request)
fields_to_return = fields_to_return_original + filter(lambda x: x not in fields_to_return_original,
['status', 'creation_date', 'start_date', 'end_date'])
mandatory_fields = set(['status', 'creation_date', 'start_date', 'end_date'])
fields_to_return = list(mandatory_fields.union(fields_to_return_original))
experiments = self.model.objects.from_author_and_public(request.user, author_name).select_related()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment