diff --git a/src/api/handlers/action.py b/src/api/handlers/action.py index fe4c78261..7c5a0e196 100644 --- a/src/api/handlers/action.py +++ b/src/api/handlers/action.py @@ -6,6 +6,7 @@ #from types import FunctionType as function from _main_.utils.context import Context from api.decorators import admins_only, super_admins_only, login_required +from api.store.common import expect_media_fields class ActionHandler(RouteHandler): @@ -90,20 +91,8 @@ def submit(self, request): .expect("image", "file", is_required=False, options={"is_logo": True}) .expect("vendors", list, is_required=False) .expect("action_id", str, is_required=False) - .expect( - "underAge", bool, - ).expect( - "copyright", bool, - ).expect( - "copyright_att", str, - ).expect( - "guardian_info", str, - ).expect( - "size", str - ).expect( - "size_text", str - ) ) + self = expect_media_fields(self) args, err = self.validator.verify(args) if err: @@ -164,6 +153,8 @@ def update(self, request): .expect("vendors", list, is_required=False) ) + self = expect_media_fields(self) + args, err = self.validator.verify(args) if err: return err diff --git a/src/api/handlers/event.py b/src/api/handlers/event.py index 52cf0dac6..4a94543ea 100644 --- a/src/api/handlers/event.py +++ b/src/api/handlers/event.py @@ -7,6 +7,7 @@ from types import FunctionType as function from _main_.utils.context import Context from api.decorators import admins_only, super_admins_only, login_required +from api.store.common import expect_media_fields class EventHandler(RouteHandler): @@ -221,13 +222,7 @@ def submit(self, request): self.validator.expect('rsvp_enabled', bool) self.validator.expect('rsvp_email', bool) self.validator.expect('event_id', str) - self.validator.expect("size", str) - self.validator.expect("size_text", str) - self.validator.expect("description") - self.validator.expect("underAge", bool) - self.validator.expect("copyright", bool) - self.validator.expect("copyright_att", str) - self.validator.expect("guardian_info", str) + self = expect_media_fields(self) args, err = self.validator.verify(args) if err: diff --git a/src/api/handlers/testimonial.py b/src/api/handlers/testimonial.py index 6a417942b..ed768bb77 100644 --- a/src/api/handlers/testimonial.py +++ b/src/api/handlers/testimonial.py @@ -8,6 +8,7 @@ from _main_.utils.context import Context from _main_.utils.validator import Validator from api.decorators import admins_only, super_admins_only, login_required +from api.store.common import expect_media_fields class TestimonialHandler(RouteHandler): @@ -94,13 +95,7 @@ def submit(self, request): self.validator.rename('preferredName', 'preferred_name') self.validator.expect('testimonial_id', str) self.validator.expect("image", "file", is_required=False) - self.validator.expect("size", str) - self.validator.expect("size_text", str) - self.validator.expect("description") - self.validator.expect("underAge", bool) - self.validator.expect("copyright", bool) - self.validator.expect("copyright_att", str) - self.validator.expect("guardian_info", str) + self = expect_media_fields(self) args, err = self.validator.verify(args) if err: diff --git a/src/api/handlers/vendor.py b/src/api/handlers/vendor.py index ddcda623c..8a0cebb09 100644 --- a/src/api/handlers/vendor.py +++ b/src/api/handlers/vendor.py @@ -10,6 +10,7 @@ from _main_.utils.context import Context from _main_.utils.validator import Validator from api.decorators import admins_only, super_admins_only, login_required +from api.store.common import expect_media_fields @@ -108,13 +109,15 @@ def submit(self, request): .expect("vendor_id", str) ) - self.validator.expect("size", str) - self.validator.expect("size_text", str) - self.validator.expect("description") - self.validator.expect("underAge", bool) - self.validator.expect("copyright", bool) - self.validator.expect("copyright_att", str) - self.validator.expect("guardian_info", str) + # self.validator.expect("size", str) + # self.validator.expect("size_text", str) + # self.validator.expect("description") + # self.validator.expect("underAge", bool) + # self.validator.expect("copyright", bool) + # self.validator.expect("copyright_att", str) + # self.validator.expect("guardian_info", str) + + self = expect_media_fields(self) args, err = self.validator.verify(args) if err: diff --git a/src/api/store/common.py b/src/api/store/common.py index a0db8ed7c..5cd4abd71 100644 --- a/src/api/store/common.py +++ b/src/api/store/common.py @@ -147,7 +147,6 @@ def sign_mou(mou_rich_text, user=None, date=None): ) - def expect_media_fields(self): self.validator.expect("size", str).expect("size_text", str).expect( "description" @@ -161,24 +160,38 @@ def expect_media_fields(self): "permission_notes", str ) return self - -def make_media_info(args): - fields = ["copyright","copyright_att", "underAge","size", "size_text", "guardian_info"] - name_to_obj_name = {"underAge":"has_children", "copyright": "has_copyright_permission"} - obj = {} - for name in fields: +def make_media_info(args): + """Request arg names are different from how they are stored on the media object, so this function corrects the naming and makes sure it matches the structure that is actually saved on the media object""" + fields = [ + "copyright", + "copyright_att", + "underAge", + "size", + "size_text", + "guardian_info", + "permission_key", + "permission_notes" + ] + name_to_obj_name = { + "underAge": "has_children", + "copyright": "has_copyright_permission", + } + obj = {} + for name in fields: value = args.pop(name, None) - name = name_to_obj_name.get(name,name) - if value: - obj[name] = value - return obj + name = name_to_obj_name.get(name, name) + if value: + obj[name] = value + return obj + -def get_media_info(media): - if not media: +def get_media_info(media): + """Retrieves media info from media object""" + if not media: return {}, False - if hasattr(media,"user_upload"): - if hasattr(media.user_upload, "info"): + if hasattr(media, "user_upload"): + if hasattr(media.user_upload, "info"): return media.user_upload.info or {}, True return {}, False