Commit b10f6e4f authored by Hervé  MENAGER's avatar Hervé MENAGER
Browse files

add ContributionManager to handle access to Contribution objects

WIP on #226
parent 948c7a66
......@@ -1479,7 +1479,48 @@ class DrugbankCompoundTanimoto(models.Model):
unique_together = (("compound", "drugbank_compound"),)
class ContributionManager(models.Manager):
Model manager for the `Contribution` class
provides selections to `validated` or `user-visible` contributions
def for_user(self, current_user):
Get contributions 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(validated=False)
elif not current_user.is_superuser:
qs = qs.exclude(
return qs
def validated(self):
Get validated contributions
return (
class Contribution(models.Model):
Contribution: structured information describing some
compound(s) and related effect(s) on some PPI(s) in a
given publication/patent
objects = ContributionManager()
contributor = models.ForeignKey(to=get_user_model(), on_delete=models.PROTECT)
ppi = models.ForeignKey(to=Ppi, on_delete=models.SET_NULL, null=True)
bibliography = models.ForeignKey(
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment