Commit 3ec8ed02 authored by Jean-Baptiste Pasquier's avatar Jean-Baptiste Pasquier

feature: virtual container for current, expired, self or owned offers

parent 564ff32e
Pipeline #3593 passed with stage
in 33 seconds
from django.conf.urls import url
from .views import JobOffersViewset, JobOffersCurrentViewset, \
JobOffersExpiredViewset, JobOffersSelfViewset, \
JobOffersOwnedViewset
urlpatterns = [
url(r'^job-offers/current/', JobOffersCurrentViewset.urls()),
url(r'^job-offers/expired/', JobOffersExpiredViewset.urls()),
url(r'^job-offers/self/', JobOffersSelfViewset.urls()),
url(r'^users/(?P<id>[0-9]*)/job-offers/', JobOffersOwnedViewset.urls()),
# Dirty fix for bad id change to job-offers/self/
url(r'^job-offers/', JobOffersViewset.urls()),
]
from djangoldp.views import LDPViewSet
from datetime import datetime
from .models import JobOffer
class JobOffersCurrentViewset(LDPViewSet):
model = JobOffer
def get_queryset(self):
return super().get_queryset() \
.filter(closingDate__gte=datetime.now())
class JobOffersExpiredViewset(LDPViewSet):
model = JobOffer
def get_queryset(self):
return super().get_queryset() \
.filter(closingDate__lte=datetime.now())
class JobOffersSelfViewset(LDPViewSet):
model = JobOffer
def get_queryset(self):
if self.request.user.is_authenticated():
return super().get_queryset() \
.filter(author=self.request.user.id)
raise Exception("User is not authentificated")
class JobOffersOwnedViewset(LDPViewSet):
model = JobOffer
def get_queryset(self):
return super().get_queryset() \
.filter(author=self.kwargs['id'])
# Dirty fix for bad id change to job-offers/self/
class JobOffersViewset(LDPViewSet):
model = JobOffer
def get_queryset(self):
return super().get_queryset()
Markdown is supported
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