views.py 989 Bytes
Newer Older
Benoit Alessandroni's avatar
Benoit Alessandroni committed
1
from djangoldp.views import LDPViewSet
2
from .models import Resource, Step
Benoit Alessandroni's avatar
Benoit Alessandroni committed
3

4

5
class ValidatedResourcesByStepViewSet(LDPViewSet):
6 7 8
  model = Resource

  def get_queryset(self, *args, **kwargs):
9
    step_id = self.kwargs['id']
10 11 12 13 14 15 16
    if self.request.user.mentor_profile:
      target='mentor'
    elif self.request.user.entrepreneur_profile:
      target='entrepreneur'
    else:
      target='public'

17
    return super().get_queryset(*args, **kwargs)\
18
          .filter(steps__in=step_id, review__status='validated', target__value=target)\
19 20
          .exclude(submitter__username=self.request.user.username)

Benoit Alessandroni's avatar
Benoit Alessandroni committed
21 22 23 24 25
class PendingResourcesViewSet(LDPViewSet):
  model = Resource

  def get_queryset(self, *args, **kwargs):
    return super().get_queryset(*args, **kwargs)\
26
          .filter(review__status='pending', language__in=self.request.user.mentor_profile.languages.all(), fields__in=self.request.user.mentor_profile.fields.all())\
27
          .exclude(submitter__username=self.request.user.username)