mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-23 15:57:23 -04:00
Add letter jobs page, client and test
This commit is contained in:
@@ -52,6 +52,7 @@ from app.notify_client.events_api_client import EventsApiClient
|
||||
from app.notify_client.provider_client import ProviderClient
|
||||
from app.notify_client.organisations_client import OrganisationsClient
|
||||
from app.notify_client.models import AnonymousUser
|
||||
from app.notify_client.letter_jobs_client import LetterJobsClient
|
||||
|
||||
login_manager = LoginManager()
|
||||
csrf = CsrfProtect()
|
||||
@@ -69,6 +70,7 @@ provider_client = ProviderClient()
|
||||
organisations_client = OrganisationsClient()
|
||||
asset_fingerprinter = AssetFingerprinter()
|
||||
statsd_client = StatsdClient()
|
||||
letter_jobs_client = LetterJobsClient()
|
||||
|
||||
# The current service attached to the request stack.
|
||||
current_service = LocalProxy(partial(_lookup_req_object, 'service'))
|
||||
@@ -100,6 +102,7 @@ def create_app():
|
||||
events_api_client.init_app(application)
|
||||
provider_client.init_app(application)
|
||||
organisations_client.init_app(application)
|
||||
letter_jobs_client.init_app(application)
|
||||
|
||||
login_manager.init_app(application)
|
||||
login_manager.login_view = 'main.sign_in'
|
||||
|
||||
@@ -1,45 +1,31 @@
|
||||
from flask import (render_template, url_for, redirect, request, abort)
|
||||
import datetime
|
||||
|
||||
from flask import render_template, request
|
||||
from flask_login import login_required
|
||||
|
||||
from app import letter_jobs_client, format_datetime_24h
|
||||
from app.main import main
|
||||
from app import convert_to_boolean
|
||||
from flask_login import (login_required, current_user)
|
||||
from app.utils import user_has_permissions
|
||||
|
||||
|
||||
@main.route("/letter-jobs", methods=['GET', 'POST'])
|
||||
@login_required
|
||||
@user_has_permissions(admin_override=True)
|
||||
def letter_jobs():
|
||||
letter_jobs_list = get_letter_jobs()
|
||||
|
||||
msg = ''
|
||||
if request.method == 'POST':
|
||||
send_letters = request.form.getlist('send_letter')
|
||||
for job_id in send_letters:
|
||||
job = [j for j in letter_jobs_list if job_id == j['job_id']][0]
|
||||
job['send'] = True
|
||||
letter_jobs_list = letter_jobs_client.get_letter_jobs()
|
||||
|
||||
msg = 'sending:{}'.format(send_letters)
|
||||
if request.method == 'POST':
|
||||
if len(request.form.getlist('job_id')) > 0:
|
||||
job_ids = request.form.getlist('job_id')
|
||||
|
||||
response = letter_jobs_client.send_letter_jobs(job_ids)
|
||||
msg = response['response']
|
||||
|
||||
for job_id in job_ids:
|
||||
job = [j for j in letter_jobs_list if job_id == j['id']][0]
|
||||
job['sending'] = 'sending'
|
||||
else:
|
||||
msg = 'No jobs selected'
|
||||
|
||||
return render_template('views/letter-jobs.html', letter_jobs_list=letter_jobs_list, message=msg)
|
||||
|
||||
|
||||
def get_letter_jobs():
|
||||
return [
|
||||
{
|
||||
'service_name': 'test_name',
|
||||
'job_id': 'test_id',
|
||||
'status': 'test_status',
|
||||
'created_at': '2017-04-01'
|
||||
},
|
||||
{
|
||||
'service_name': 'test_name 2',
|
||||
'job_id': 'test_id 2',
|
||||
'status': 'test_status 2',
|
||||
'created_at': '2017-04-02'
|
||||
|
||||
},
|
||||
{
|
||||
'service_name': 'test_name 3',
|
||||
'job_id': 'test_id 3',
|
||||
'status': 'test_status 3',
|
||||
'created_at': '2017-04-03'
|
||||
}
|
||||
]
|
||||
|
||||
21
app/notify_client/letter_jobs_client.py
Normal file
21
app/notify_client/letter_jobs_client.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from app.notify_client import NotifyAdminAPIClient
|
||||
|
||||
|
||||
class LetterJobsClient(NotifyAdminAPIClient):
|
||||
|
||||
def __init__(self):
|
||||
super().__init__("a", "b", "c")
|
||||
|
||||
def init_app(self, app):
|
||||
self.base_url = app.config['API_HOST_NAME']
|
||||
self.service_id = app.config['ADMIN_CLIENT_USER_NAME']
|
||||
self.api_key = app.config['ADMIN_CLIENT_SECRET']
|
||||
|
||||
def get_letter_jobs(self):
|
||||
return self.get(url='/letter-jobs')['data']
|
||||
|
||||
def send_letter_jobs(self, job_ids):
|
||||
return self.post(
|
||||
url='/send-letter-jobs',
|
||||
data={"job_ids": job_ids}
|
||||
)['data']
|
||||
@@ -17,25 +17,31 @@
|
||||
<th>Service name</th>
|
||||
<th>Job ID</th>
|
||||
<th>Status</th>
|
||||
<th colspan="2">Created at</th>
|
||||
<th colspan="3">Created at</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for job in letter_jobs_list %}
|
||||
<tr>
|
||||
<td>{{ job.service_name }}</td>
|
||||
<td>{{ job.job_id }}</td>
|
||||
<td>{{ job.status }}</td>
|
||||
<td>{{ job.created_at }}</td>
|
||||
<td><input name="send_letter" value='{{ job.job_id }}' type="checkbox"{% if job.send %} checked{% endif %}></td>
|
||||
<td>{{ job.service_name.name }}</td>
|
||||
<td>{{ job.id }}</td>
|
||||
<td>{{ job.job_status }}</td>
|
||||
<td>{{ job.created_at|format_datetime_short }}</td>
|
||||
<td><input name="job_id" value='{{ job.id }}' type="checkbox"{% if job.send %} checked{% endif %}></td>
|
||||
<td>{{ job.sending }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</p>
|
||||
{{ page_footer('Send') }}
|
||||
|
||||
{% if message %}
|
||||
<p>
|
||||
<p id='message'>
|
||||
{{ message }}
|
||||
{% if message != 'No jobs selected' %}
|
||||
<div>Refresh page to see status updates</div>
|
||||
{% endif %}
|
||||
</p>
|
||||
{% endif %}
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user