Skip to content

Commit

Permalink
Merge pull request #496 from nephila/feature/fix_466
Browse files Browse the repository at this point in the history
Fix parameter warnings
  • Loading branch information
yakky committed Apr 5, 2015
2 parents 369e948 + 8ec1d56 commit 308958c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
15 changes: 10 additions & 5 deletions filer/fields/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,19 @@ class FilerFileField(models.ForeignKey):

def __init__(self, **kwargs):
# We hard-code the `to` argument for ForeignKey.__init__
if "to" in kwargs.keys():
if "to" in kwargs.keys(): # pragma: no cover
old_to = kwargs.pop("to")
msg = "%s can only be a ForeignKey to %s; %s passed" % (
self.__class__.__name__, self.default_model_class.__name__, old_to
dfl = "%s.%s" % (
self.default_model_class._meta.app_label,
self.default_model_class.__name__
)
warnings.warn(msg, SyntaxWarning)
if old_to != dfl:
msg = "%s can only be a ForeignKey to %s; %s passed" % (
self.__class__.__name__, self.default_model_class.__name__, old_to
)
warnings.warn(msg, SyntaxWarning)
kwargs['to'] = self.default_model_class
return super(FilerFileField, self).__init__(**kwargs)
super(FilerFileField, self).__init__(**kwargs)

def formfield(self, **kwargs):
# This is a fairly standard way to set up some defaults
Expand Down
15 changes: 10 additions & 5 deletions filer/fields/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,19 @@ class FilerFolderField(models.ForeignKey):

def __init__(self, **kwargs):
# We hard-code the `to` argument for ForeignKey.__init__
if "to" in kwargs.keys():
if "to" in kwargs.keys(): # pragma: no cover
old_to = kwargs.pop("to")
msg = "%s can only be a ForeignKey to %s; %s passed" % (
self.__class__.__name__, self.default_model_class.__name__, old_to
dfl = "%s.%s" % (
self.default_model_class._meta.app_label,
self.default_model_class.__name__
)
warnings.warn(msg, SyntaxWarning)
if old_to != dfl:
msg = "%s can only be a ForeignKey to %s; %s passed" % (
self.__class__.__name__, self.default_model_class.__name__, old_to
)
warnings.warn(msg, SyntaxWarning)
kwargs['to'] = self.default_model_class
return super(FilerFolderField, self).__init__(**kwargs)
super(FilerFolderField, self).__init__(**kwargs)

def formfield(self, **kwargs):
# This is a fairly standard way to set up some defaults
Expand Down
7 changes: 4 additions & 3 deletions filer/fields/multistorage_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,11 @@ class MultiStorageFileField(easy_thumbnails_fields.ThumbnailerField):

def __init__(self, verbose_name=None, name=None,
storages=None, thumbnail_storages=None, thumbnail_options=None, **kwargs):
if 'upload_to' in kwargs:
if 'upload_to' in kwargs: # pragma: no cover
upload_to = kwargs.pop("upload_to")
warnings.warn("MultiStorageFileField can handle only File objects;"
"%s passed" % upload_to, SyntaxWarning)
if upload_to != generate_filename_multistorage:
warnings.warn("MultiStorageFileField can handle only File objects;"
"%s passed" % upload_to, SyntaxWarning)
self.storages = storages or STORAGES
self.thumbnail_storages = thumbnail_storages or THUMBNAIL_STORAGES
self.thumbnail_options = thumbnail_options or THUMBNAIL_OPTIONS
Expand Down

0 comments on commit 308958c

Please sign in to comment.