Skip to content

Commit

Permalink
Move Evidence.set_upload_destination to set_evidence_upload_destination
Browse files Browse the repository at this point in the history
Fixes lint issue about set_upload_destination, a regular method,
referenced via a class. Can't use `@staticmethod` because it's not
serializable and won't work with migrations.
  • Loading branch information
ColonelThirtyTwo committed Nov 20, 2023
1 parent dacc579 commit b24a65d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ghostwriter/reporting/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ class Migration(migrations.Migration):
(
"document",
models.FileField(
blank=True, upload_to=ghostwriter.reporting.models.Evidence.set_upload_destination
blank=True, upload_to=ghostwriter.reporting.models.set_evidence_upload_destination
),
),
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Migration(migrations.Migration):
name="document",
field=models.FileField(
blank=True,
upload_to=ghostwriter.reporting.models.Evidence.set_upload_destination,
upload_to=ghostwriter.reporting.models.set_evidence_upload_destination,
validators=[ghostwriter.reporting.validators.validate_evidence_extension],
),
),
Expand Down
11 changes: 6 additions & 5 deletions ghostwriter/reporting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,18 +537,19 @@ def __str__(self):
return f"{self.title}"


def set_evidence_upload_destination(this, filename):
"""Sets the `upload_to` destination to the evidence folder for the associated report ID."""
return os.path.join("evidence", str(this.associated_report.id), filename)


class Evidence(models.Model):
"""
Stores an individual evidence file, related to :model:`reporting.ReportFindingLink`
and :model:`users.User`.
"""

def set_upload_destination(self, filename):
"""Sets the `upload_to` destination to the evidence folder for the associated report ID."""
return os.path.join("evidence", str(self.finding.report.id), filename)

document = models.FileField(
upload_to=set_upload_destination,
upload_to=set_evidence_upload_destination,
validators=[validate_evidence_extension],
blank=True,
)
Expand Down

0 comments on commit b24a65d

Please sign in to comment.