Skip to content

Commit

Permalink
Add ability to edit supplier declarations
Browse files Browse the repository at this point in the history
This adds the ability for a CCS Sourcing team member to view and edit
G-Cloud 7 supplier declarations. In the supplier listing the only link
they will see alongside a supplier is 'G-Cloud 7 declaration'. This will
take them to the G-Cloud 7 supplier declaration overview where they can
edit each section. This uses the new ContentLoader but hard codes the
G-Cloud 7 link in the supplier list as it is the only framework they can
edit at the moment.

Note that this does no validation, it is assumed that the CCS Sourcing
team know the rules.
  • Loading branch information
robyoung committed Oct 12, 2015
1 parent 30b57e7 commit c303bec
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 16 deletions.
1 change: 1 addition & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

content_loader = ContentLoader('app/content')
content_loader.load_manifest('g-cloud-6', 'edit_service_as_admin', 'services')
content_loader.load_manifest('g-cloud-7', 'declaration', 'declaration')


from app.main.helpers.service import parse_document_upload_time
Expand Down
1 change: 1 addition & 0 deletions app/assets/scss/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ $path: "/admin/static/images/";
@import "views/view_audits";
@import "_diff.scss";
@import "views/statistics";
@import "views/view_declaration";

// Graphs
@import "_c3";
3 changes: 3 additions & 0 deletions app/assets/scss/views/_view_declaration.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.my-special-page thead .summary-item-field-heading-first {
width: 60%;
}
78 changes: 73 additions & 5 deletions app/main/views/suppliers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@

from .. import main
from . import get_template_data
from ... import data_api_client
from ... import data_api_client, content_loader
from ..forms import EmailAddressForm
from ..auth import role_required
from dmutils.apiclient.errors import HTTPError
from dmutils.apiclient.errors import HTTPError, APIError
from dmutils.audit import AuditTypes
from dmutils.email import send_email, \
generate_token, MandrillException
from dmutils.email import send_email, generate_token, MandrillException


@main.route('/suppliers', methods=['GET'])
@login_required
@role_required('admin', 'admin-ccs-category')
@role_required('admin', 'admin-ccs-category', 'admin-ccs-sourcing')
def find_suppliers():
suppliers = data_api_client.find_suppliers(prefix=request.args.get("supplier_name_prefix"))

Expand All @@ -39,6 +38,75 @@ def edit_supplier_name(supplier_id):
)


@main.route('/suppliers/<string:supplier_id>/edit/declarations/<string:framework_slug>', methods=['GET'])
@login_required
@role_required('admin-ccs-sourcing')
def view_supplier_declaration(supplier_id, framework_slug):
supplier = data_api_client.get_supplier(supplier_id)['suppliers']
framework = data_api_client.get_framework(framework_slug)['frameworks']
declaration = data_api_client.get_supplier_declaration(supplier_id, framework_slug)['declaration']

content = content_loader.get_builder(framework_slug, 'declaration').filter(declaration)

return render_template(
"suppliers/view_declaration.html",
supplier=supplier,
framework=framework,
declaration=declaration,
content=content,
**get_template_data())


@main.route(
'/suppliers/<string:supplier_id>/edit/declarations/<string:framework_slug>/<string:section_id>',
methods=['GET'])
@login_required
@role_required('admin-ccs-sourcing')
def edit_supplier_declaration_section(supplier_id, framework_slug, section_id):
supplier = data_api_client.get_supplier(supplier_id)['suppliers']
framework = data_api_client.get_framework(framework_slug)['frameworks']
declaration = data_api_client.get_supplier_declaration(supplier_id, framework_slug)['declaration']

content = declaration_content.get_builder().filter(declaration)

return render_template(
"suppliers/edit_declaration.html",
supplier=supplier,
framework=framework,
declaration=declaration,
section=content.get_section(section_id),
**get_template_data())


@main.route(
'/suppliers/<string:supplier_id>/edit/declarations/<string:framework_slug>/<string:section_id>',
methods=['POST'])
def update_supplier_declaration_section(supplier_id, framework_slug, section_id):
supplier = data_api_client.get_supplier(supplier_id)['suppliers']
framework = data_api_client.get_framework(framework_slug)['frameworks']
declaration = data_api_client.get_supplier_declaration(supplier_id, framework_slug)['declaration']

content = declaration_content.get_builder().filter(declaration)
section = content.get_section(section_id)

posted_data = section.get_data(request.form)

if section.has_changes_to_save(declaration, posted_data):
declaration.update(posted_data)
data_api_client.set_supplier_declaration(
supplier_id, framework_slug, declaration,
current_user.email_address)

next_section = content.get_next_editable_section_id(section_id)
if next_section:
return redirect(url_for('.edit_supplier_declaration_section',
supplier_id=supplier_id, framework_slug=framework_slug,
section_id=next_section))
else:
return redirect(url_for('.view_supplier_declaration',
supplier_id=supplier_id, framework_slug=framework_slug))


@main.route('/suppliers/<string:supplier_id>/edit/name', methods=['POST'])
@login_required
@role_required('admin')
Expand Down
2 changes: 1 addition & 1 deletion app/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{% include "toolkit/page-heading.html" %}
{% endwith %}

{% if current_user.has_role('admin') or current_user.has_role('admin-ccs-category') %}
{% if current_user.has_any_role('admin', 'admin-ccs-category', 'admin-ccs-sourcing') %}
<div class="grid-row">
<div class="column-two-thirds">
<form action="{{ url_for('.find') }}" method="get" class="question">
Expand Down
46 changes: 46 additions & 0 deletions app/templates/suppliers/edit_declaration.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{% import 'macros/toolkit_forms.html' as forms %}

{% extends "_base_page.html" %}

{% block page_title %}
Change {{ framework.name }} declaration
{% endblock %}

{% block content %}
<div class="page-container edit-section">
<div class="grid-row">
<div class="service-title">
{%
with
context = supplier.name,
heading = section.name,
smaller = True
%}
{% include "toolkit/page-heading.html" %}
{% endwith %}
</div>
</div>

<form method="post" enctype="multipart/form-data">
<div class="grid-row">
<div class="column-two-thirds">
<div style="display:none;"><input id="csrf_token" name="csrf_token" type="hidden" value="{{ csrf_token() }}"></div>
{% for question in section.questions %}
{{ forms[question.type](question, declaration, {}) }}
{% endfor %}
{%
with
type = "save",
label = "Save and return to summary"
%}
{% include "toolkit/button.html" %}
{% endwith %}
<p>
<a href="{{ url_for('.view_supplier_declaration', supplier_id=supplier.id, framework_slug=framework.slug) }}">Return without saving</a>
</p>
</div>
</div>
</div>
</form>
</div>
{% endblock %}
44 changes: 44 additions & 0 deletions app/templates/suppliers/view_declaration.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{% import "toolkit/summary-table.html" as summary %}

{% extends "_base_page.html" %}

{% block page_title %}
Change {{ framework.name }} declaration
{% endblock %}

{% block content %}
<div class="page-container my-special-page">
<div class="grid-row">
<div class="service-title">
{%
with
context = supplier.name,
heading = framework.name + " declaration",
smaller = True
%}
{% include "toolkit/page-heading.html" %}
{% endwith %}
</div>
</div>

{% for section in content %}
{{ summary.heading(section.name) }}
{{ summary.top_link("Edit", url_for('.edit_supplier_declaration_section', supplier_id=supplier.id, framework_slug=framework.slug, section_id=section.id)) }}
{% call(item) summary.list_table(
section.questions,
caption="Declaration",
empty_message="This supplier not made a declaration",
field_headings=[
'Declaration question',
'Declaration answer'
]
) %}
{% call summary.row() %}
{{ summary.field_name(item.question) }}
{{ summary[item.type](declaration[item.id]) }}
{% endcall %}
{% endcall %}
{% endfor %}
</div>

{% endblock %}
36 changes: 26 additions & 10 deletions app/templates/view_suppliers.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,45 @@
{% endwith %}

<div class="page-section">
{% call(item) summary.list_table(
suppliers,
caption="Suppliers",
empty_message="No suppliers were found",
field_headings=[
{% if current_user.has_role("admin") %}
{% set field_headings = [
"Name",
summary.hidden_field_heading("Edit name"),
summary.hidden_field_heading("Change name"),
summary.hidden_field_heading("Users"),
summary.hidden_field_heading("Services"),
] if current_user.has_role('admin') else [
] %}
{% elif current_user.has_role("admin-ccs-sourcing") %}
{% set field_headings = [
"Name",
summary.hidden_field_heading("Change declarations"),
] %}
{% else %}
{% set field_headings = [
"Name",
summary.hidden_field_heading("Users"),
summary.hidden_field_heading("Services"),
],
] %}
{% endif %}

{% call(item) summary.list_table(
suppliers,
caption="Suppliers",
empty_message="No suppliers were found",
field_headings=field_headings,
field_headings_visible=True)
%}
{% call summary.row() %}
{{ summary.field_name(item.name) }}
{% if current_user.has_role('admin') %}
{{ summary.edit_link("Change name", url_for(".edit_supplier_name", supplier_id=item.id)) }}
{% endif %}
{{ summary.edit_link("Users", url_for(".find_supplier_users", supplier_id=item.id)) }}
{{ summary.edit_link("Services", url_for(".find_supplier_services", supplier_id=item.id)) }}
{% if current_user.has_role('admin-ccs-sourcing') %}
{{ summary.edit_link("G-Cloud 7 declaration", url_for(".view_supplier_declaration", supplier_id=item.id, framework_slug="g-cloud-7")) }}
{% endif %}
{% if current_user.has_any_role('admin', 'admin-ccs-category') %}
{{ summary.edit_link("Users", url_for(".find_supplier_users", supplier_id=item.id)) }}
{{ summary.edit_link("Services", url_for(".find_supplier_services", supplier_id=item.id)) }}
{% endif %}
{% endcall %}
{% endcall %}
</div>
Expand Down

0 comments on commit c303bec

Please sign in to comment.