Skip to content

Commit

Permalink
1855: Add Page.updated_url to 12-week retest
Browse files Browse the repository at this point in the history
  • Loading branch information
ahernp committed Jan 8, 2025
1 parent 5fb1a06 commit d8ffd8c
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 19 deletions.
17 changes: 17 additions & 0 deletions accessibility_monitoring_platform/apps/audits/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,23 @@ class Meta:
]


class AuditRetestPageUpdateForm(forms.ModelForm):
"""Form for updating a page at 12-week retest"""

updated_url = AMPURLField(label="New URL of page if changed")

class Meta:
model = Page
fields = [
"updated_url",
]


AuditRetestPageFormset: forms.formsets.BaseFormSet = forms.modelformset_factory(
Page, AuditRetestPageUpdateForm, extra=0
)


class AuditRetestPageChecksForm(forms.Form):
"""
Form for retesting checks for a page
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.1.4 on 2024-12-31 08:13

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("audits", "0011_remove_audit_accessibility_statement_backup_url_and_more"),
]

operations = [
migrations.AddField(
model_name="page",
name="updated_url",
field=models.TextField(blank=True, default=""),
),
]
3 changes: 2 additions & 1 deletion accessibility_monitoring_platform/apps/audits/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class DisproportionateBurden(models.TextChoices):
audit_retest_metadata_notes = models.TextField(default="", blank=True)
audit_retest_metadata_complete_date = models.DateField(null=True, blank=True)

# Retest pages
# Update page links
audit_retest_pages_complete_date = models.DateField(null=True, blank=True)

# Retest website compliance
Expand Down Expand Up @@ -550,6 +550,7 @@ class Type(models.TextChoices):
)
name = models.TextField(default="", blank=True)
url = models.TextField(default="", blank=True)
updated_url = models.TextField(default="", blank=True)
location = models.TextField(default="", blank=True)
complete_date = models.DateField(null=True, blank=True)
no_errors_date = models.DateField(null=True, blank=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
{% extends 'common/case_form.html' %}

{% block preform %}
{% for page in case.audit.testable_pages %}
{% if page.failed_check_results.count > 0 %}
<h2 class="govuk-heading-m">{{ page }}</h2>
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<div class="govuk-form-group">
<label class="govuk-label"><b>URL</b></label>
<div class="govuk-hint">{{ page.url }}</div>
</div>
<div class="govuk-form-group">
<label class="govuk-label"><b>Page location description if single page app</b></label>
<div class="govuk-hint">{% if page.location %}{{ page.location }}{% else %}None{% endif %}</div>
</div>
</div>
{% if audit_retest_pages_formset.errors %}
{% for form in audit_retest_pages_formset.forms %}
{% if form.errors %}
{% include 'common/error_summary.html' %}
{% endif %}
{% endfor %}
{% endif %}
{% endblock %}

{% block form %}
<form method="post" action="{% url sitemap.current_platform_page.url_name object.id %}">
{% csrf_token %}
{{ audit_retest_pages_formset.management_form }}

<table class="govuk-table">
<tbody class="govuk-table__body">
{% for page_form in audit_retest_pages_formset %}
<tr class="govuk-table__row">
<td class="govuk-table__cell">
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<h2 class="govuk-heading-m">{{ page_form.instance }}</h2>
<div class="govuk-form-group">
<label class="govuk-label"><b>URL</b></label>
<div class="govuk-hint">{{ page_form.instance.url }}</div>
</div>
<div class="govuk-form-group">
<label class="govuk-label"><b>Page location description if single page app</b></label>
<div class="govuk-hint">{% if page_form.instance.location %}{{ page_form.instance.location }}{% else %}None{% endif %}</div>
</div>
{% include 'common/form_errors.html' with errors=page_form.non_field_errors %}
{% include 'common/form_hidden_fields.html' with hidden_fields=page_form.hidden_fields %}
{% for field in page_form.visible_fields %}
{% include 'common/amp_field.html' %}
{% endfor %}
</div>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
{% include 'common/amp_form_snippet.html' %}
</div>
<div class="govuk-grid-column-full govuk-button-group">
{% include 'cases/helpers/save_continue_cancel.html' %}
</div>
{% endif %}
{% endfor %}
</div>
</form>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,10 @@ def test_audit_edit_redirects_based_on_button_pressed(
"version": audit.version,
button_name: "Button value",
"case-compliance-version": audit.case.compliance.version,
"form-TOTAL_FORMS": "0",
"form-INITIAL_FORMS": "0",
"form-MIN_NUM_FORMS": "0",
"form-MAX_NUM_FORMS": "1000",
},
)

Expand Down
33 changes: 33 additions & 0 deletions accessibility_monitoring_platform/apps/audits/views/twelve_week.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
AuditRetestCheckResultFormset,
AuditRetestMetadataUpdateForm,
AuditRetestPageChecksForm,
AuditRetestPageFormset,
AuditRetestPagesUpdateForm,
AuditRetestStatementCheckResultFormset,
AuditRetestStatementComplianceUpdateForm,
Expand Down Expand Up @@ -84,6 +85,38 @@ class AuditRetestPagesView(AuditUpdateView):
form_class: type[AuditRetestPagesUpdateForm] = AuditRetestPagesUpdateForm
template_name: str = "audits/forms/twelve_week_pages.html"

def get_context_data(self, **kwargs: dict[str, Any]) -> dict[str, Any]:
"""Get context data for template rendering"""
context: dict[str, Any] = super().get_context_data(**kwargs)
audit: Audit = self.object
if self.request.POST:
audit_retest_pages_formset: AuditRetestPageFormset = AuditRetestPageFormset(
self.request.POST
)
else:
audit_retest_pages_formset: AuditRetestPageFormset = AuditRetestPageFormset(
queryset=audit.testable_pages
)
context["audit_retest_pages_formset"] = audit_retest_pages_formset
return context

def form_valid(self, form: ModelForm):
"""Process contents of valid form"""
context: dict[str, Any] = self.get_context_data()
audit_retest_pages_formset: AuditRetestPageFormset = context[
"audit_retest_pages_formset"
]

if audit_retest_pages_formset.is_valid():
pages: list[Page] = audit_retest_pages_formset.save(commit=False)
for page in pages:
record_model_update_event(user=self.request.user, model_object=page)
page.save()
else:
return super().form_invalid(form)

return super().form_valid(form)

def get_success_url(self) -> str:
"""Detect the submit button used and act accordingly"""
if "save_continue" in self.request.POST:
Expand Down
2 changes: 1 addition & 1 deletion accessibility_monitoring_platform/apps/common/sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,7 @@ def populate_from_case(self, case: Case):
case_details_template_name="cases/details/details.html",
),
AuditRetestPagesPlatformPage(
name="Retest pages",
name="Update page links",
url_name="audits:edit-audit-retest-pages",
complete_flag_name="audit_retest_pages_complete_date",
subpages=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('Create case, tests and report', () => {
cy.title().should('eq', `${newOrganisationName} | 12-week retest metadata`)
cy.contains('Save and continue').click()

cy.title().should('eq', `${newOrganisationName} | Retest pages`)
cy.title().should('eq', `${newOrganisationName} | Update page links`)
cy.contains('Save and continue').click()

cy.title().should('eq', `${newOrganisationName} | Home page retest`)
Expand Down

0 comments on commit d8ffd8c

Please sign in to comment.