Skip to content

Commit

Permalink
events update with copyright info works
Browse files Browse the repository at this point in the history
  • Loading branch information
frimpongopoku committed Oct 13, 2023
1 parent e7e7997 commit f847995
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
29 changes: 17 additions & 12 deletions src/api/store/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,20 @@ def expect_media_fields(self):


def make_media_info(args):
copyright_permission = args.pop("copyright", "")
under_age = args.pop("underAge", "")
guardian_info = args.pop("guardian_info","")
copyright_att = args.pop("copyright_att","")
return {
"size": args.pop("size",""),
"size_text": args.pop("size_text",""),
"has_children": under_age,
"has_copyright_permission": copyright_permission,
"guardian_info": guardian_info,
"copyright_att": copyright_att,
}
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:
value = args.pop(name, None)
name = name_to_obj_name.get(name,name)
if value:
obj[name] = value
return obj

def get_media_info(media):
if not media:
return {}, False
if hasattr(media,"user_upload"):
if hasattr(media.user_upload, "info"):
return media.user_upload.info or {}, True
return {}, False
14 changes: 10 additions & 4 deletions src/api/store/event.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from _main_.utils.footage.FootageConstants import FootageConstants
from _main_.utils.footage.spy import Spy
from _main_.utils.utils import Console, is_url_valid
from api.store.common import make_media_info
from api.store.common import get_media_info, make_media_info
from api.tests.common import RESET, makeUserUpload
from api.utils.api_utils import is_admin_of_community
from api.utils.filter_functions import get_events_filter_params
Expand Down Expand Up @@ -245,6 +245,7 @@ def create_event(self, context: Context, args, user_submitted) -> Tuple[dict, Ma
user_email = args.pop('user_email', context.user_email)
image_info = make_media_info(args)


start_date_and_time = args.get('start_date_and_time', None)
end_date_and_time = args.get('end_date_and_time', None)
is_recurring = args.pop('is_recurring', False)
Expand Down Expand Up @@ -367,9 +368,6 @@ def update_event(self, context: Context, args, user_submitted) -> Tuple[dict, Ma
event_id = args.pop('event_id', None)
events = Event.objects.filter(id=event_id)
image_info = make_media_info(args)
# image_info = None
# Console.log("LE ARGS", args)
Console.log("SEE IMAGE_INFO",image_info)

publicity_selections = args.pop("publicity_selections", [])
shared_to = args.pop("shared_to", [])
Expand Down Expand Up @@ -502,6 +500,14 @@ def update_event(self, context: Context, args, user_submitted) -> Tuple[dict, Ma
else:
media = Media.objects.filter(id = image[0]).first()
event.image = media

if event.image:
old_image_info, can_save_info = get_media_info(event.image)
# There are media objects that do not have user upload references. (because we didnt have that model at the time of upload) thats why we need to check first
if can_save_info:
event.image.user_upload.info.update({**old_image_info,**image_info})
event.image.user_upload.save()


if community_id:
community = Community.objects.filter(pk=community_id).first()
Expand Down

0 comments on commit f847995

Please sign in to comment.