mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-08 06:58:25 -04:00
Use a ModelList for lists of jobs
This follows the pattern of what we’ve done with services, users and events. It gives us a way of neatly instantiating a model for each item in the list we get back from the API and reduces the complexity of the view layer code. Now is a good time to do this because we’re going to be making a bunch of changes to the jobs pages, and those changes will be easier to code and understand with a sensible model behind them.
This commit is contained in:
@@ -5,6 +5,12 @@ from notifications_utils.take import Take
|
||||
from werkzeug.utils import cached_property
|
||||
|
||||
from app.models import JSONModel
|
||||
from app.models.job import (
|
||||
ImmediateJobs,
|
||||
PaginatedJobs,
|
||||
PaginatedUploads,
|
||||
ScheduledJobs,
|
||||
)
|
||||
from app.models.organisation import Organisation
|
||||
from app.models.user import InvitedUsers, User, Users
|
||||
from app.notify_client.api_key_api_client import api_key_api_client
|
||||
@@ -103,10 +109,28 @@ class Service(JSONModel):
|
||||
def has_permission(self, permission):
|
||||
return permission in self.permissions
|
||||
|
||||
def get_page_of_jobs(self, page):
|
||||
return PaginatedJobs(self.id, page=page)
|
||||
|
||||
def get_page_of_uploads(self, page):
|
||||
return PaginatedUploads(self.id, page=page)
|
||||
|
||||
@cached_property
|
||||
def has_jobs(self):
|
||||
return job_api_client.has_jobs(self.id)
|
||||
|
||||
@cached_property
|
||||
def immediate_jobs(self):
|
||||
if not self.has_jobs:
|
||||
return []
|
||||
return ImmediateJobs(self.id)
|
||||
|
||||
@cached_property
|
||||
def scheduled_jobs(self):
|
||||
if not self.has_jobs:
|
||||
return []
|
||||
return ScheduledJobs(self.id)
|
||||
|
||||
@cached_property
|
||||
def invited_users(self):
|
||||
return InvitedUsers(self.id)
|
||||
|
||||
Reference in New Issue
Block a user