Skip to content
This repository has been archived by the owner on Oct 18, 2022. It is now read-only.

Commit

Permalink
moved file_path to module base.fields.functions
Browse files Browse the repository at this point in the history
  • Loading branch information
agustin committed Dec 7, 2021
1 parent ee11a95 commit bb602bd
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
10 changes: 10 additions & 0 deletions base/fields/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# -*- coding: utf-8 -*-

from .base import BaseFileField
from .base import ChileanRUTField


__all__ = [
'BaseFileField',
'ChileanRUTField',
]
20 changes: 1 addition & 19 deletions base/fields.py → base/fields/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,12 @@

# utils
from base import utils
from .functions import file_path

# translations
from django.utils.translation import ugettext_lazy as _


# public methods
def file_path(self, name):
"""
Generic method to give to a FileField or ImageField in it's upload_to
parameter.
This returns the name of the class, concatenated with the id of the
object and the name of the file.
"""
base_path = "{}/{}/{}/{}"

return base_path.format(
self.__class__.__name__,
str(utils.today()),
utils.random_string(30),
name
)


class ChileanRUTField(CharField):
"""
A model field that stores a Chilean RUT in the format "XX.XXX.XXX-Y".
Expand Down
22 changes: 22 additions & 0 deletions base/fields/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-

from base import utils


# public methods
def file_path(self, name):
"""
Generic method to give to a FileField or ImageField in it's upload_to
parameter.
This returns the name of the class, concatenated with the id of the
object and the name of the file.
"""
base_path = "{}/{}/{}/{}"

return base_path.format(
self.__class__.__name__,
str(utils.today()),
utils.random_string(30),
name
)

0 comments on commit bb602bd

Please sign in to comment.