Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HL-861 | Use markdown format to display service terms #2172

Merged
merged 5 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/benefit/terms/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class TermsAdmin(admin.ModelAdmin):
inlines = (ApplicantConsentInline,)
list_display = ("id", "terms_type", "effective_from")

class Media:
css = {"all": ("css/markdown.css",)}


class ApprovedApplicantConsentInline(admin.ModelAdmin):
model = ApplicantConsent
Expand Down
3 changes: 3 additions & 0 deletions backend/benefit/terms/api/v1/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class Meta:
"terms_pdf_fi",
"terms_pdf_en",
"terms_pdf_sv",
"terms_md_fi",
"terms_md_en",
"terms_md_sv",
"applicant_consents",
]

Expand Down
9 changes: 9 additions & 0 deletions backend/benefit/terms/fixtures/default_terms.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"terms_pdf_fi": "/var/media/please_upload_actual_pdf_manually.pdf",
"terms_pdf_sv": "/var/media/please_upload_actual_pdf_manually.pdf",
"terms_pdf_en": "/var/media/please_upload_actual_pdf_manually.pdf",
"terms_md_en": "# Käyttöehdot",
"terms_md_fi": "# Terms of service",
"terms_md_sv": "# Vilkor för användning",
"created_at": "2021-01-01T00:00:00+02:00",
"modified_at": "2021-01-01T00:00:00+02:00"
}
Expand All @@ -33,6 +36,9 @@
"terms_pdf_fi": "/var/media/please_upload_actual_pdf_manually.pdf",
"terms_pdf_sv": "/var/media/please_upload_actual_pdf_manually.pdf",
"terms_pdf_en": "/var/media/please_upload_actual_pdf_manually.pdf",
"terms_md_en": "# Hakuehdot",
"terms_md_fi": "# Applicant terms",
"terms_md_sv": "# Sökandevillkor",
"created_at": "2021-01-01T00:00:00+02:00",
"modified_at": "2021-01-01T00:00:00+02:00"
}
Expand Down Expand Up @@ -98,6 +104,9 @@
"terms_pdf_fi": "/var/media/please_upload_actual_pdf_manually.pdf",
"terms_pdf_sv": "/var/media/please_upload_actual_pdf_manually.pdf",
"terms_pdf_en": "/var/media/please_upload_actual_pdf_manually.pdf",
"terms_md_en": "# Käsittelijän ehdot",
"terms_md_fi": "# Handler terms",
"terms_md_sv": "# Vilkor för hanterare",
"created_at": "2021-01-01T00:00:00+02:00",
"modified_at": "2021-01-01T00:00:00+02:00"
}
Expand Down
27 changes: 27 additions & 0 deletions backend/benefit/terms/migrations/0005_add_support_for_md_terms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.2.18 on 2023-08-15 13:02

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("terms", "0004_alter_terms_terms_type"),
]

operations = [
migrations.AddField(
model_name="terms",
name="terms_md_en",
field=models.TextField(blank=True, verbose_name="English terms (md)"),
),
migrations.AddField(
model_name="terms",
name="terms_md_fi",
field=models.TextField(blank=True, verbose_name="Finnish terms (md)"),
),
migrations.AddField(
model_name="terms",
name="terms_md_sv",
field=models.TextField(blank=True, verbose_name="Swedish terms (md)"),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.18 on 2023-08-15 13:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('terms', '0005_add_support_for_md_terms'),
]

operations = [
migrations.AlterField(
model_name='terms',
name='terms_pdf_en',
field=models.FileField(blank=True, upload_to='', verbose_name='english terms (pdf file)'),
),
migrations.AlterField(
model_name='terms',
name='terms_pdf_fi',
field=models.FileField(blank=True, upload_to='', verbose_name='finnish terms (pdf file)'),
),
migrations.AlterField(
model_name='terms',
name='terms_pdf_sv',
field=models.FileField(blank=True, upload_to='', verbose_name='swedish terms (pdf file)'),
),
]
47 changes: 44 additions & 3 deletions backend/benefit/terms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
from django.db import models
from django.forms import ValidationError
from django.utils.translation import gettext_lazy as _

from applications.models import Application
Expand Down Expand Up @@ -34,16 +35,56 @@ class Terms(UUIDModel, TimeStampedModel):
default=TermsType.APPLICANT_TERMS,
)

terms_md_fi = models.TextField(
verbose_name=_("Finnish terms (md)"), blank=True, default=""
)
terms_md_en = models.TextField(
verbose_name=_("English terms (md)"), blank=True, default=""
)
terms_md_sv = models.TextField(
verbose_name=_("Swedish terms (md)"), blank=True, default=""
)

"""
If effective_from is set to null, that means the terms are not to be displayed to the applicant.
"""
effective_from = models.DateField(
verbose_name=_("first day these terms are in effect"), null=True, blank=True
)

terms_pdf_fi = models.FileField(verbose_name=_("finnish terms (pdf file)"))
terms_pdf_en = models.FileField(verbose_name=_("english terms (pdf file)"))
terms_pdf_sv = models.FileField(verbose_name=_("swedish terms (pdf file)"))
terms_pdf_fi = models.FileField(
verbose_name=_("finnish terms (pdf file)"), blank=True
)
terms_pdf_en = models.FileField(
verbose_name=_("english terms (pdf file)"), blank=True
)
terms_pdf_sv = models.FileField(
verbose_name=_("swedish terms (pdf file)"), blank=True
)

def clean(self):
required_fields_pdf = [
self.terms_pdf_en,
self.terms_pdf_fi,
self.terms_pdf_sv,
]
required_fields_md = [
self.terms_md_en,
self.terms_md_fi,
self.terms_md_sv,
]
if not all(required_fields_md) and not all(required_fields_pdf):
raise ValidationError(
_("PDF or MD fields are missing for FI/EN/SV! Fill in either or")
)
if all(required_fields_pdf) and any(required_fields_md):
raise ValidationError(
_("PDF or MD fields are missing for FI/EN/SV! Fill in either or")
)
if all(required_fields_md) and any(required_fields_pdf):
raise ValidationError(
_("PDF or MD fields are missing for FI/EN/SV! Fill in either or")
)

@property
def is_editable(self):
Expand Down
45 changes: 45 additions & 0 deletions backend/benefit/terms/static/css/markdown.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.module .EasyMDEContainer h1,
.module .EasyMDEContainer h2,
.module .EasyMDEContainer h3,
.module .EasyMDEContainer h4,
.module .EasyMDEContainer h5,
.module .EasyMDEContainer h6 {
color: #000;
background: none;
margin: 0;
padding: 0;
margin-bottom: 1.2rem;
font-weight: 400;
text-transform: none;
letter-spacing: 0;
line-height: 1.25;
}

.module .EasyMDEContainer h1 {
font-size: 2em;
}
.module .EasyMDEContainer h2 {
font-size: 1.75em;
}

.module .EasyMDEContainer h3 {
font-size: 1.5em;
}

.module .EasyMDEContainer h4,
.module .EasyMDEContainer h5,
.module .EasyMDEContainer h6 {
font-size: 1.25em;
}

.module .EasyMDEContainer ul {
margin-left: 1em;
}
.module .EasyMDEContainer ul li {
list-style: disc;
font-size: 1em;
}

label[for*="id_terms_md_"] {
float: none;
}
7 changes: 7 additions & 0 deletions backend/benefit/terms/static/css/vendor/easymde.min.css
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be downloaded as dependencies and not be in repo? Then put in the correct place with manage.py collectstatic?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea how this works. Through npm, then point the resource on Django somehow and use collectstatic?

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions backend/benefit/terms/static/js/vendor/easymde.min.js

Large diffs are not rendered by default.

Loading
Loading