from functools import wraps
from datetime import date
from django.shortcuts import redirect, get_object_or_404
from django.http import HttpResponseNotFound

def job_not_expired(view_func):
    @wraps(view_func)
    def _wrapped_view(request, job_id, *args, **kwargs):
        
        from .models import JobPosting
        job = get_object_or_404(JobPosting, pk=job_id)

        if job.expiration_date and job.application_deadline< date.today():
            return redirect('expired_job_page')
        
        return view_func(request, job_id, *args, **kwargs)
    return _wrapped_view