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

Drop Django 3.2, Add Django 5.0, use Ruff for linting and formatting #244

Merged
merged 20 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix upload_to methods' positions
  • Loading branch information
philgyford committed Dec 12, 2023
commit 6f821b2d9e02349cd5eb690c87ad9bc93e8f6332
40 changes: 21 additions & 19 deletions ditto/flickr/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Because at this stage, don't want to move the upload_to methods around:
# ruff: noqa: DJ012
from django.db import models
from django.templatetags.static import static
from django.urls import reverse
Expand Down Expand Up @@ -856,8 +858,26 @@ class User(TimeStampedModelMixin, DiffModelMixin, models.Model):
null=False, blank=False, max_length=50, help_text="eg, 'Europe/London'."
)

def avatar_upload_path(self, filename):
"Make path under MEDIA_ROOT where avatar file will be saved."
# If NSID is '35034346050@N01', get '35034346050'
nsid = self.nsid[: self.nsid.index("@")]

# If NSID is '35034346050@N01'
# then, 'flickr/60/50/35034346050/avatars/avatar_name.jpg'
return "/".join(
[
app_settings.FLICKR_DIR_BASE,
nsid[-4:-2],
nsid[-2:],
self.nsid.replace("@", ""),
"avatars",
filename,
]
)

avatar = models.ImageField(
upload_to="avatar_upload_path", null=False, blank=True, default=""
upload_to=avatar_upload_path, null=False, blank=True, default=""
)

objects = models.Manager()
Expand Down Expand Up @@ -899,21 +919,3 @@ def original_icon_url(self):
)
else:
return "https://www.flickr.com/images/buddyicon.gif"

def avatar_upload_path(self, filename):
"Make path under MEDIA_ROOT where avatar file will be saved."
# If NSID is '35034346050@N01', get '35034346050'
nsid = self.nsid[: self.nsid.index("@")]

# If NSID is '35034346050@N01'
# then, 'flickr/60/50/35034346050/avatars/avatar_name.jpg'
return "/".join(
[
app_settings.FLICKR_DIR_BASE,
nsid[-4:-2],
nsid[-2:],
self.nsid.replace("@", ""),
"avatars",
filename,
]
)
30 changes: 16 additions & 14 deletions ditto/twitter/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Because at this stage, don't want to move the upload_to methods around:
# ruff: noqa: DJ012
import contextlib
import json
import logging
Expand Down Expand Up @@ -209,11 +211,23 @@ class Media(TimeStampedModelMixin, models.Model):
)
# END VIDEO-ONLY PROPERTIES

def upload_path(self, filename):
"Make path under MEDIA_ROOT where original files will be saved."

# eg get '12345678' from '12345678.jpg':
name = os.path.splitext(filename)[0]

# If filename is '12345678.jpg':
# 'twitter/media/56/78/12345678.jpg'
return "/".join(
[app_settings.TWITTER_DIR_BASE, "media", name[-4:-2], name[-2:], filename]
)

image_file = models.ImageField(
upload_to="upload_path", null=False, blank=True, default=""
upload_to=upload_path, null=False, blank=True, default=""
)
mp4_file = models.FileField(
upload_to="upload_path",
upload_to=upload_path,
null=False,
blank=True,
default="",
Expand Down Expand Up @@ -318,18 +332,6 @@ def video_mime_type(self):

return mime_type

def upload_path(self, filename):
"Make path under MEDIA_ROOT where original files will be saved."

# eg get '12345678' from '12345678.jpg':
name = os.path.splitext(filename)[0]

# If filename is '12345678.jpg':
# 'twitter/media/56/78/12345678.jpg'
return "/".join(
[app_settings.TWITTER_DIR_BASE, "media", name[-4:-2], name[-2:], filename]
)

def _image_url(self, size):
"""
Helper for the self.*_url() property methods.
Expand Down