diff --git a/beat/web/experiments/api.py b/beat/web/experiments/api.py index cdd76b830432d6dc25cbe03a377bc0f49e8f5adb..b21eb32c6111cb6e00a9d15a50d019c34d203cf7 100755 --- a/beat/web/experiments/api.py +++ b/beat/web/experiments/api.py @@ -62,7 +62,7 @@ from ..common.api import ( from ..common.mixins import CommonContextMixin from ..common.exceptions import ShareError from ..common.serializers import SharingSerializer -from ..common.utils import validate_restructuredtext, ensure_html +from ..common.utils import validate_restructuredtext, ensure_html, py3_cmp from ..toolchains.models import Toolchain @@ -111,15 +111,6 @@ class ListCreateExperimentsView(ListCreateContributionView): def _getStatusLabel(status): return [s for s in Experiment.STATUS if s[0] == status][0][1] - def _cmp(a, b): - """ - cmp is not available anymore in Python 3. This method is implemetend - as recommended in the documentation for this kind of use case. - Based on: - https://docs.python.org/3.0/whatsnew/3.0.html#ordering-comparisons - """ - return (a > b) - (a < b) - def _custom_compare(exp1, exp2): PENDING = _getStatusLabel(Experiment.PENDING) @@ -129,7 +120,7 @@ class ListCreateExperimentsView(ListCreateContributionView): if exp2["status"] != PENDING: return -1 elif exp1["creation_date"] != exp2["creation_date"]: - return _cmp(exp1["creation_date"], exp2["creation_date"]) + return py3_cmp(exp1["creation_date"], exp2["creation_date"]) else: return 1 elif exp2["status"] == PENDING: @@ -142,7 +133,7 @@ class ListCreateExperimentsView(ListCreateContributionView): ] if (exp1["status"] in tier3_states) and (exp2["status"] in tier3_states): - return _cmp(exp2["end_date"], exp1["end_date"]) + return py3_cmp(exp2["end_date"], exp1["end_date"]) elif (exp1["status"] in tier3_states) and ( exp2["status"] not in tier3_states ): @@ -152,7 +143,7 @@ class ListCreateExperimentsView(ListCreateContributionView): ): return 1 - return _cmp(exp1["start_date"], exp2["start_date"]) + return py3_cmp(exp1["start_date"], exp2["start_date"]) # Retrieve the experiments fields_to_return_original = self.get_serializer_fields(request)