Skip to content

Commit

Permalink
Convert custom_storages.py to a python module (#2289)
Browse files Browse the repository at this point in the history
* Convert custom_storages.py to a python module

* Do not use a mutable object as the default value of the function argument

* Install production dependencies on GitHub action to running the tests

* Avoid upgrading Django by defining versions to production deps

Whitenoise > 6.0.0 and django-storages > 1.12.3 requires Django 3.2 or higher

* Remove imports on custom_storages __init__ file to avoid error when execute the tests
  • Loading branch information
luzfcb authored Jul 20, 2023
1 parent 66af2ac commit 3508c99
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
Empty file added custom_storages/__init__.py
Empty file.
7 changes: 5 additions & 2 deletions custom_storages.py → custom_storages/storages.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ def get_comment_blocks(self, content):
"""
return [
(match.start(), match.end())
for match in re.finditer(r"\/\*.*?\*\/", content, flags=re.DOTALL)
for match in re.finditer(r'\/\*.*?\*\/', content, flags=re.DOTALL)
]

def url_converter(self, name, hashed_files, template=None, comment_blocks=[]):
def url_converter(self, name, hashed_files, template=None, comment_blocks=None):
"""
Return the custom URL converter for the given file name.
"""
if comment_blocks is None:
comment_blocks = []

if template is None:
template = self.default_template

Expand Down
6 changes: 3 additions & 3 deletions prod-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ gunicorn==19.9.0
raven==6.10.0

# Heroku
Whitenoise
django-storages
boto3
Whitenoise==6.0.0 # 6.0.0 is latest version that supports Django 2.2
django-storages==1.12.3 # 1.12.3 is latest version that supports Django 2.2
boto3==1.26.165
1 change: 1 addition & 0 deletions pydotorg/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

MEDIA_ROOT = os.path.join(BASE, 'media')
MEDIA_URL = '/media/'
MEDIAFILES_LOCATION = 'media'

# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
Expand Down
4 changes: 2 additions & 2 deletions pydotorg/settings/heroku.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
] + MIDDLEWARE

MEDIAFILES_LOCATION = 'media'
DEFAULT_FILE_STORAGE = 'custom_storages.MediaStorage'
STATICFILES_STORAGE = 'custom_storages.PipelineManifestStorage'
DEFAULT_FILE_STORAGE = 'custom_storages.storages.MediaStorage'
STATICFILES_STORAGE = 'custom_storages.storages.PipelineManifestStorage'

EMAIL_HOST = config('EMAIL_HOST')
EMAIL_HOST_USER = config('EMAIL_HOST_USER')
Expand Down

0 comments on commit 3508c99

Please sign in to comment.