From 3f920b77adb3440149d9c9cbc6c3eb31763915ef Mon Sep 17 00:00:00 2001 From: agustin Date: Tue, 7 Dec 2021 18:55:02 +0100 Subject: [PATCH] moved file_path to module base.fields.functions --- base/fields/__init__.py | 10 ++++++++++ base/{fields.py => fields/base.py} | 20 +------------------- base/fields/functions.py | 22 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 base/fields/__init__.py rename base/{fields.py => fields/base.py} (85%) create mode 100644 base/fields/functions.py diff --git a/base/fields/__init__.py b/base/fields/__init__.py new file mode 100644 index 00000000..2ec23a43 --- /dev/null +++ b/base/fields/__init__.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- + +from .base import BaseFileField +from .base import ChileanRUTField + + +__all__ = [ + 'BaseFileField', + 'ChileanRUTField', +] diff --git a/base/fields.py b/base/fields/base.py similarity index 85% rename from base/fields.py rename to base/fields/base.py index 084b4801..189a217a 100644 --- a/base/fields.py +++ b/base/fields/base.py @@ -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". diff --git a/base/fields/functions.py b/base/fields/functions.py new file mode 100644 index 00000000..4c20557a --- /dev/null +++ b/base/fields/functions.py @@ -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 + )