diff --git a/ippisite/ippidb/models.py b/ippisite/ippidb/models.py index 6a886aeac82eaa78fb95f1829fb467729df630d5..d1d5f4736370f51a9a9748c5eac916a921408e77 100644 --- a/ippisite/ippidb/models.py +++ b/ippisite/ippidb/models.py @@ -479,6 +479,11 @@ class PpiComplex(models.Model): class CompoundsManager(models.Manager): def for_user(self, current_user): + """ + Get compounds visible to a given user + i.e. validated or created by the user or + all of them if the user is an admin + """ qs = self.get_queryset() if current_user.is_anonymous: qs = qs.exclude(compoundaction__ppi__contribution__validated=False) @@ -489,6 +494,16 @@ class CompoundsManager(models.Manager): ) return qs + def validated(self): + """ + Get validated compounds + """ + return ( + super() + .get_queryset() + .exclude(compoundaction__ppi__contribution__validated=False) + ) + class Compound(AutoFillableModel): """ diff --git a/ippisite/ippidb/tests_contribute.py b/ippisite/ippidb/tests_contribute.py index fdb39cc1c35c28d88095412a75ccb6178088b583..385dcefd1a8ac03338abba11909e0c58c6145658 100644 --- a/ippisite/ippidb/tests_contribute.py +++ b/ippisite/ippidb/tests_contribute.py @@ -131,8 +131,8 @@ class ContributionViewsTestCase(TestCase): "Compounds count", ), ( - models.Compound.validated.count, - models.Compound.validated.count(), + models.Compound.objects.validated().count, + models.Compound.objects.validated().count(), "Validated Compounds count", ), ( @@ -164,7 +164,7 @@ class ContributionViewsTestCase(TestCase): self.assertEqual(fcn(), results, msg=msg) post_validation_expected_equals = [ ( - models.Compound.validated.count, + models.Compound.objects.validated().count, models.Compound.objects.count(), "Validated Compounds count", )