SciPost Code Repository

Skip to content
Snippets Groups Projects
Commit 6d6b2a50 authored by Jean-Sébastien Caux's avatar Jean-Sébastien Caux
Browse files

Remove redundant name field from SubsidyAttachment

parent 6b6f61c6
No related branches found
No related tags found
No related merge requests found
......@@ -116,6 +116,8 @@ class SubsidyPaymentForm(forms.ModelForm):
"reference",
"amount",
"date_scheduled",
"invoice",
"proof_of_payment",
)
......@@ -126,34 +128,27 @@ class SubsidyAttachmentForm(forms.ModelForm):
"subsidy",
"attachment",
"kind",
"name",
"date",
"description",
"name",
"visibility",
)
def clean_attachment(self):
attachment = self.cleaned_data["attachment"]
print(f"{attachment.name = }")
return attachment
def clean_name(self):
name = self.cleaned_data["name"]
name_regex = (
filename_regex = (
"^SciPost_"
"[0-9]{4,}(-[0-9]{4,})?_[A-Z]{2,}_[\w]+_"
"(Agreement|Invoice|ProofOfPayment|Other)"
"(-[0-9]{2,})?\.(pdf|docx|png)$"
"(-[0-9]{2,})?(_[\w]+)?\.(pdf|docx|png)$"
)
pattern = re.compile(name_regex)
if not pattern.match(name):
pattern = re.compile(filename_regex)
if not pattern.match(attachment.name):
self.add_error(
"name",
"attachment",
"The filename does not match the required regex pattern "
f"'{name_regex}'"
f"'{filename_regex}'"
)
return name
return attachment
......
# Generated by Django 3.2.17 on 2023-02-27 14:17
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('finances', '0026_subsidypayment'),
]
operations = [
migrations.RemoveField(
model_name='subsidyattachment',
name='name',
),
]
......@@ -220,6 +220,13 @@ class SubsidyAttachment(models.Model):
(VISIBILITY_FINADMINONLY, "SciPost FinAdmin only"),
)
subsidy = models.ForeignKey(
"finances.Subsidy",
related_name="attachments",
blank=True,
on_delete=models.CASCADE,
)
attachment = models.FileField(
upload_to=subsidy_attachment_path, storage=SecureFileStorage()
)
......@@ -230,19 +237,10 @@ class SubsidyAttachment(models.Model):
default=KIND_AGREEMENT,
)
name = models.CharField(max_length=128)
date = models.DateField(blank=True, null=True)
description = models.TextField(blank=True)
subsidy = models.ForeignKey(
"finances.Subsidy",
related_name="attachments",
blank=True,
on_delete=models.CASCADE,
)
visibility = models.CharField(
max_length=32,
choices=VISIBILITY_CHOICES,
......@@ -252,7 +250,7 @@ class SubsidyAttachment(models.Model):
objects = SubsidyAttachmentQuerySet.as_manager()
def __str__(self):
return "%s, attachment to %s" % (self.name, self.subsidy)
return "%s, attachment to %s" % (self.attachment.name, self.subsidy)
def get_absolute_url(self):
if self.subsidy:
......
......@@ -27,6 +27,7 @@
_<span class="text-muted">[Organization acronym or short name]</span>
_<span class="text-muted">[document type]</span>
<span class="text-muted">(-##)</span>
<span class="text-muted">_(extra info)
.<span class="text-muted">[filetype]</span>
</em>&emsp;<span class="text-danger">NOTE: careful with hyphens and underscores!</span>
<br/>in which:
......@@ -34,7 +35,7 @@
<li><span class="text-muted">[year]</span> is the year or year range of validity of the Agreement</li>
<li><span class="text-muted">[document type]</span> can be <em>Agreement</em>, <em>Invoice</em>, <em>ProofOfPayment</em> or <em>Other</em> (the last case should be explicited in the attachment's description)</li>
<li>(-##) represents a two-digit number obligatory for invoices, but optional for other types</li>
<li>the full filename must of course be unique</li>
<li>_(extra info) is an optional suffix, e.g. <em>_Collaboration</em>
</ul>
</p>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment