Skip to content

Commit 518dda2

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 64db882 commit 518dda2

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

api/metadata/models.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from urllib.parse import urlparse
21
from typing import cast
2+
from urllib.parse import urlparse
3+
34
from django.contrib.contenttypes.fields import GenericForeignKey
45
from django.contrib.contenttypes.models import ContentType
56
from django.db import models
@@ -29,13 +30,18 @@ class FieldType(models.TextChoices):
2930

3031
class MetadataField(AbstractBaseExportableModel):
3132
"""This model represents a metadata field(specific to an organisation) that can be attached to any model"""
33+
3234
id: models.AutoField[int, int]
3335
name: models.CharField[str, str] = models.CharField(max_length=255)
3436
type: models.CharField[str, str] = models.CharField(
3537
max_length=255, choices=FieldType.choices, default=FieldType.STRING
3638
)
37-
description: models.TextField[str | None, str | None] = models.TextField(blank=True, null=True)
38-
organisation: models.ForeignKey[Organisation, Organisation] = models.ForeignKey(Organisation, on_delete=models.CASCADE)
39+
description: models.TextField[str | None, str | None] = models.TextField(
40+
blank=True, null=True
41+
)
42+
organisation: models.ForeignKey[Organisation, Organisation] = models.ForeignKey(
43+
Organisation, on_delete=models.CASCADE
44+
)
3945

4046
def is_field_value_valid(self, field_value: str) -> bool:
4147
if len(field_value) > FIELD_VALUE_MAX_LENGTH:
@@ -64,7 +70,7 @@ def validate_url(self, field_value: str) -> bool:
6470
def validate_str(self, field_value: str) -> bool:
6571
return True
6672

67-
def validate_multiline_str(self, field_value: str) -> bool:
73+
def validate_multiline_str(self, field_value: str) -> bool:
6874
return True
6975

7076
class Meta:
@@ -115,10 +121,15 @@ class Metadata(AbstractBaseExportableModel):
115121
class Meta:
116122
unique_together = ("model_field", "content_type", "object_id")
117123

118-
def deep_clone_for_new_entity(self, cloned_entity: models.Model, content_type: ContentType) -> "Metadata":
119-
return cast(Metadata, Metadata.objects.create(
120-
model_field=self.model_field,
121-
content_type=content_type,
122-
object_id=cloned_entity.pk,
123-
field_value=self.field_value,
124-
))
124+
def deep_clone_for_new_entity(
125+
self, cloned_entity: models.Model, content_type: ContentType
126+
) -> "Metadata":
127+
return cast(
128+
Metadata,
129+
Metadata.objects.create(
130+
model_field=self.model_field,
131+
content_type=content_type,
132+
object_id=cloned_entity.pk,
133+
field_value=self.field_value,
134+
),
135+
)

0 commit comments

Comments
 (0)