Skip to content

Commit 977f4f8

Browse files
committed
File and comment formatting + simplifications
1 parent 71d43e3 commit 977f4f8

File tree

8 files changed

+38
-32
lines changed

8 files changed

+38
-32
lines changed

backend/authentication/models.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class Support(models.Model):
8383
creation_date = models.DateTimeField(auto_now_add=True)
8484

8585
def __str__(self) -> str:
86-
return f"{self.id}"
86+
return str(self.id)
8787

8888

8989
class UserModel(AbstractUser, PermissionsMixin):

backend/communities/groups/models.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class GroupImage(models.Model):
5151
sequence_index = models.IntegerField()
5252

5353
def __str__(self) -> str:
54-
return f"{self.id}"
54+
return str(self.id)
5555

5656

5757
class GroupMember(models.Model):
@@ -68,7 +68,7 @@ class GroupMember(models.Model):
6868
is_comms = models.BooleanField(default=False)
6969

7070
def __str__(self) -> str:
71-
return f"{self.id}"
71+
return str(self.id)
7272

7373

7474
class GroupSocialLink(SocialLink):

backend/communities/organizations/models.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class OrganizationApplication(models.Model):
6868
creation_date = models.DateTimeField(auto_now_add=True)
6969

7070
def __str__(self) -> str:
71-
return f"{self.creation_date}"
71+
return str(self.creation_date)
7272

7373

7474
class OrganizationApplicationStatus(models.Model):
@@ -85,7 +85,7 @@ class OrganizationImage(models.Model):
8585
sequence_index = models.IntegerField()
8686

8787
def __str__(self) -> str:
88-
return f"{self.id}"
88+
return str(self.id)
8989

9090

9191
class OrganizationMember(models.Model):
@@ -96,7 +96,7 @@ class OrganizationMember(models.Model):
9696
is_comms = models.BooleanField(default=False)
9797

9898
def __str__(self) -> str:
99-
return f"{self.id}"
99+
return str(self.id)
100100

101101

102102
class OrganizationSocialLink(SocialLink):
@@ -114,7 +114,7 @@ class OrganizationTask(models.Model):
114114
)
115115

116116
def __str__(self) -> str:
117-
return f"{self.id}"
117+
return str(self.id)
118118

119119

120120
class OrganizationText(models.Model):

backend/content/models.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Discussion(models.Model):
2626
tags = models.ManyToManyField("content.Tag", blank=True)
2727

2828
def __str__(self) -> str:
29-
return f"{self.id}"
29+
return str(self.id)
3030

3131

3232
class Faq(models.Model):
@@ -45,9 +45,10 @@ def __str__(self) -> str:
4545
# This is used to set the filename to the UUID of the model, in the Image model.
4646
def set_filename_to_uuid(instance: Any, filename: str) -> str:
4747
"""Generate a new filename using the model's UUID and keep the original extension."""
48-
ext = os.path.splitext(filename)[1] # Extract file extension
49-
new_filename = f"{instance.id}{ext}" # Use model UUID as filename
50-
return os.path.join("images/", new_filename) # Store in 'images/' folder
48+
ext = os.path.splitext(filename)[1] # extract file extension
49+
new_filename = f"{instance.id}{ext}" # use model UUID as filename
50+
51+
return os.path.join("images/", new_filename) # store in 'images/' folder
5152

5253

5354
class Image(models.Model):
@@ -72,7 +73,7 @@ class Location(models.Model):
7273
display_name = models.CharField(max_length=255)
7374

7475
def __str__(self) -> str:
75-
return f"{self.id}"
76+
return str(self.id)
7677

7778

7879
class Resource(models.Model):
@@ -128,7 +129,7 @@ class Tag(models.Model):
128129
creation_date = models.DateTimeField(auto_now_add=True)
129130

130131
def __str__(self) -> str:
131-
return f"{self.id}"
132+
return str(self.id)
132133

133134

134135
class Task(models.Model):
@@ -174,4 +175,4 @@ class DiscussionEntry(models.Model):
174175
deletion_date = models.DateTimeField(blank=True, null=True)
175176

176177
def __str__(self) -> str:
177-
return f"{self.id}"
178+
return str(self.id)

backend/content/serializers.py

+16-13
Original file line numberDiff line numberDiff line change
@@ -39,46 +39,50 @@ class Meta:
3939
fields = "__all__"
4040

4141

42-
# MARK: Clear out image meta data. Used in Image Serializer, below.
42+
# MARK: Clear Metadata
43+
44+
4345
def scrub_exif(image_file: InMemoryUploadedFile) -> InMemoryUploadedFile:
4446
"""
45-
Remove EXIF data from JPEGs and text metadata from PNGs.
47+
Remove EXIF metadata from JPEGs and text metadata from PNGs.
4648
"""
4749
try:
4850
img: PILImage.Image = PILImage.open(image_file)
4951
output_format = img.format
5052

5153
if output_format == "JPEG":
5254
img = img.convert("RGB")
55+
5356
elif output_format == "PNG":
5457
img = img.copy()
5558
img.info = {}
59+
5660
else:
57-
return image_file # Return as-is if it's not JPEG or PNG
61+
return image_file # return as-is if it's not JPEG or PNG
5862

59-
# Save the cleaned image into a buffer
63+
# Save the cleaned image into a buffer.
6064
output = BytesIO()
6165
img.save(
6266
output,
6367
format=output_format,
64-
quality=95 if output_format == "JPEG" else None, # Set JPEG quality
65-
optimize=True if output_format == "JPEG" else False, # Optimize JPEG
68+
quality=95 if output_format == "JPEG" else None, # set JPEG quality
69+
optimize=output_format == "JPEG", # optimize JPEG
6670
)
6771
output.seek(0)
6872

6973
# Return a new InMemoryUploadedFile
7074
return InMemoryUploadedFile(
7175
output,
72-
image_file.field_name, # Use original field name
76+
image_file.field_name, # use original field name
7377
image_file.name,
7478
f"image/{output_format.lower()}",
7579
output.getbuffer().nbytes,
76-
image_file.charset, # Preserve charset (if applicable)
80+
image_file.charset, # preserve charset (if applicable)
7781
)
7882

7983
except Exception as e:
8084
print(f"Error scrubbing EXIF: {e}")
81-
return image_file # Return original file in case of error
85+
return image_file # return original file in case of error
8286

8387

8488
class ImageSerializer(serializers.ModelSerializer[Image]):
@@ -92,8 +96,7 @@ def validate(self, data: Dict[str, UploadedFile]) -> Dict[str, UploadedFile]:
9296
raise serializers.ValidationError("No file was submitted.")
9397

9498
# DATA_UPLOAD_MAX_MEMORY_SIZE and IMAGE_UPLOAD_MAX_FILE_SIZE are set in core/settings.py.
95-
# For whatever reason, the file size limit is not being enforced. To get around this,
96-
# we're checking the file size here.
99+
# The file size limit is not being enforced. We're checking the file size here.
97100
if (
98101
data["file_object"].size is not None
99102
and data["file_object"].size > settings.IMAGE_UPLOAD_MAX_FILE_SIZE
@@ -111,10 +114,10 @@ def create(self, validated_data: Dict[str, Any]) -> Image:
111114
if file_obj := request.FILES.get("file_object"):
112115
validated_data["file_object"] = scrub_exif(file_obj)
113116

114-
# Create the image instance
117+
# Create the image instance.
115118
image = super().create(validated_data)
116119

117-
# Handle organization image indexing if applicable
120+
# Handle organization image indexing if applicable.
118121
if organization_id := request.data.get("organization_id"):
119122
next_index = OrganizationImage.objects.filter(
120123
org_id=organization_id

backend/content/tests/test_image_upload.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def test_image_create_view(client: APIClient, image_with_file: Image) -> None:
143143
try:
144144
uuid_obj = uuid.UUID(uuid_filename, version=4)
145145
assert str(uuid_obj) == uuid_filename
146+
146147
except ValueError:
147148
assert False, f"Filename is not a valid UUID: {uuid_filename}"
148149

@@ -183,9 +184,9 @@ def test_image_create_corrupted_file(client: APIClient) -> None:
183184
img = TestImage.new("RGB", (100, 100), color="red")
184185
img_file = io.BytesIO()
185186
img.save(img_file, format="JPEG")
186-
# Take the first 100 bytes
187+
# Take the first 100 bytes.
187188
corrupted_img = img_file.getvalue()[:100]
188-
# Add some corrupt data after
189+
# Add some corrupt data after.
189190
corrupted_img += b"corrupteddata"
190191
# Wrap the corrupted image data in a SimpleUploadedFile.
191192
file = SimpleUploadedFile(
@@ -231,8 +232,7 @@ def test_image_create_large_file(client: APIClient) -> None:
231232
assert response.status_code == 400
232233

233234
# DATA_UPLOAD_MAX_MEMORY_SIZE and IMAGE_UPLOAD_MAX_FILE_SIZE are set in core/settings.py.
234-
# For whatever reason, the file size limit is not being enforced. To get around this,
235-
# we're checking the file size in the serializer validation.
235+
# The file size limit is not being enforced. We're checking the file size in the serializer validation.
236236
assert (
237237
f"The file size ({file.size} bytes) is too large. The maximum file size is {settings.IMAGE_UPLOAD_MAX_FILE_SIZE} bytes."
238238
in response.json()["nonFieldErrors"]

docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ services:
4242
retries: 5
4343
volumes:
4444
- ./backend/media:/app/media
45+
4546
frontend:
4647
env_file:
4748
- .env.dev

frontend/nuxt.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ export default defineNuxtConfig({
137137
interval: "minute",
138138
whiteList: ["127.0.0.1"],
139139
},
140-
removeLoggers: false, // When true, turns off console.log output? Also lookk at unplugin-remove Vite Plugin by Talljack
140+
// When true, turns off console.log output? Also look at unplugin-remove Vite Plugin by Talljack.
141+
removeLoggers: false,
141142
requestSizeLimiter: {
142143
maxUploadFileRequestInBytes: 5000000,
143144
},

0 commit comments

Comments
 (0)