Created
July 29, 2015 13:02
-
-
Save Drachenfels/29d28478df127ac0d06a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def _set_image(self, obj, kwargs): | |
'''Should not directly be used, but sets a relation on a model | |
if an image key appears in kwargs''' | |
# sanity check | |
if 'image' not in kwargs: | |
return obj, kwargs | |
# look for image, or set as none | |
if kwargs['image']: | |
try: | |
obj.image = image_manager.ImageManager().get_image_by_uid( | |
kwargs['image'].uid) | |
except exception.NoResultError: | |
raise exception.LogicError("Image passed to magazine is invalid") | |
else: | |
obj.image = None | |
# NOTE: if 'image' is not in kwargs, this does NOT | |
# raise any kind of exception, so this is safe code | |
del kwargs['image'] | |
return obj, kwargs | |
def create_magazine(self, **kwargs): | |
# (...) | |
obj, kwargs = self._set_image(obj, kwargs) | |
# ...) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment