Skip to content

Commit

Permalink
events, vendors, testimonials save copyright info now
Browse files Browse the repository at this point in the history
  • Loading branch information
frimpongopoku committed Oct 13, 2023
1 parent d5b06cb commit e7e7997
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 14 deletions.
7 changes: 7 additions & 0 deletions src/api/handlers/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ 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)
args, err = self.validator.verify(args)

if err:
Expand Down
7 changes: 7 additions & 0 deletions src/api/handlers/testimonial.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ 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)
args, err = self.validator.verify(args)

if err:
Expand Down
9 changes: 8 additions & 1 deletion src/api/handlers/vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,14 @@ def submit(self, request):
.expect("location", str, is_required=False)
.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)

args, err = self.validator.verify(args)
if err:
Expand Down
7 changes: 6 additions & 1 deletion src/api/store/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def create_action(self, context: Context, args, user_submitted) -> Tuple[dict, M
name = f'ImageFor {new_action.title} Action'
media = Media.objects.create(name=name, file=images)
# create user media upload here
makeUserUpload(media = media,info=image_info)
user_media_upload = makeUserUpload(media = media,info=image_info)

else:
media = Media.objects.filter(pk = images[0]).first()
Expand All @@ -110,6 +110,9 @@ def create_action(self, context: Context, args, user_submitted) -> Tuple[dict, M
user = UserProfile.objects.filter(email=user_email).first()
if user:
new_action.user = user
if user_media_upload:
user_media_upload.user = user
user_media_upload.save()

#save so you set an id
new_action.save()
Expand Down Expand Up @@ -198,6 +201,7 @@ def copy_action(self, context: Context, args) -> Tuple[Action, MassEnergizeAPIEr

def update_action(self, context: Context, args, user_submitted) -> Tuple[dict, MassEnergizeAPIError]:
try:
image_info = make_media_info(args)
action_id = args.pop('action_id', None)
actions = Action.objects.filter(id=action_id)
if not actions:
Expand Down Expand Up @@ -246,6 +250,7 @@ def update_action(self, context: Context, args, user_submitted) -> Tuple[dict, M
else:
image= Media.objects.create(file=image, name=f'ImageFor {action.title} Action')
action.image = image
makeUserUpload(media = media,info=image_info, user = action.user)
else:
if image[0] == RESET: #if image is reset, delete the existing image
action.image = None
Expand Down
4 changes: 2 additions & 2 deletions src/api/store/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ def make_media_info(args):
guardian_info = args.pop("guardian_info","")
copyright_att = args.pop("copyright_att","")
return {
"size": args.pop("size"),
"size_text": args.pop("size_text"),
"size": args.pop("size",""),
"size_text": args.pop("size_text",""),
"has_children": under_age,
"has_copyright_permission": copyright_permission,
"guardian_info": guardian_info,
Expand Down
16 changes: 14 additions & 2 deletions src/api/store/event.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from _main_.utils.footage.FootageConstants import FootageConstants
from _main_.utils.footage.spy import Spy
from _main_.utils.utils import is_url_valid
from api.tests.common import RESET
from _main_.utils.utils import Console, is_url_valid
from api.store.common import 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
from database.models import Event, RecurringEventException, UserProfile, EventAttendee, Media, Community
Expand Down Expand Up @@ -242,6 +243,7 @@ def create_event(self, context: Context, args, user_submitted) -> Tuple[dict, Ma
tags = args.pop('tags', [])
community = args.pop("community_id", None)
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)
Expand Down Expand Up @@ -306,12 +308,14 @@ def create_event(self, context: Context, args, user_submitted) -> Tuple[dict, Ma
if user_submitted:
name= f'ImageFor {new_event.name} Event'
media = Media.objects.create(name=name, file=image)
user_media_upload = makeUserUpload(media = media,info=image_info)
else:
media = Media.objects.filter(pk = image[0]).first()
new_event.image = media

if tags:
new_event.tags.set(tags)


user = None
if user_email:
Expand All @@ -323,6 +327,9 @@ def create_event(self, context: Context, args, user_submitted) -> Tuple[dict, Ma
user = UserProfile.objects.filter(email=user_email).first()
if user:
new_event.user = user
if user_media_upload:
user_media_upload.user = user
user_media_upload.save()

if publicity_selections:
new_event.communities_under_publicity.set(publicity_selections)
Expand Down Expand Up @@ -359,6 +366,10 @@ def update_event(self, context: Context, args, user_submitted) -> Tuple[dict, Ma
try:
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 @@ -484,6 +495,7 @@ def update_event(self, context: Context, args, user_submitted) -> Tuple[dict, Ma
else:
image= Media.objects.create(file=image, name=f'ImageFor {event.name} Event')
event.image = image
makeUserUpload(media = media,info=image_info, user = event.user)
else:
if image[0] == RESET: #if image is reset, delete the existing image
event.image = None
Expand Down
9 changes: 7 additions & 2 deletions src/api/store/testimonial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from _main_.utils.footage.FootageConstants import FootageConstants
from _main_.utils.footage.spy import Spy
from api.tests.common import RESET
from _main_.utils.utils import Console
from api.store.common import 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_testimonials_filter_params
from database.models import Testimonial, UserProfile, Media, Vendor, Action, Community, CommunityAdminGroup, Tag
Expand Down Expand Up @@ -69,6 +71,7 @@ def list_testimonials(self, context: Context, args) -> Tuple[list, MassEnergizeA

def create_testimonial(self, context: Context, args) -> Tuple[dict, MassEnergizeAPIError]:
try:
image_info = make_media_info(args)
images = args.pop("image", None)
tags = args.pop('tags', [])
action = args.pop('action', None)
Expand Down Expand Up @@ -101,9 +104,9 @@ def create_testimonial(self, context: Context, args) -> Tuple[dict, MassEnergize
else:
# from community portal, image upload
images.name = unique_media_filename(images)

image = Media.objects.create(file=images, name=f"ImageFor {args.get('title', '')} Testimonial")
new_testimonial.image = image
makeUserUpload(media = image,info=image_info, user = user)


if action:
Expand Down Expand Up @@ -142,6 +145,7 @@ def create_testimonial(self, context: Context, args) -> Tuple[dict, MassEnergize

def update_testimonial(self, context: Context, args) -> Tuple[dict, MassEnergizeAPIError]:
try:
image_info = make_media_info(args)
id = args.pop("id", None)
testimonials = Testimonial.objects.filter(id=id)
if not testimonials:
Expand Down Expand Up @@ -191,6 +195,7 @@ def update_testimonial(self, context: Context, args) -> Tuple[dict, MassEnergize
else:
image = Media.objects.create(file=images, name=f"ImageFor {testimonial.title} Testimonial")
testimonial.image = image
makeUserUpload(media = image,info=image_info, user = testimonial.user)

if action:
testimonial_action = Action.objects.filter(id=action).first()
Expand Down
11 changes: 10 additions & 1 deletion src/api/store/vendor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from _main_.utils.footage.FootageConstants import FootageConstants
from _main_.utils.footage.spy import Spy
from api.tests.common import RESET
from api.store.common import make_media_info
from api.tests.common import RESET, makeUserUpload
from api.utils.filter_functions import get_vendor_filter_params
from database.models import Vendor, UserProfile, Media, Community
from _main_.utils.massenergize_errors import MassEnergizeAPIError, NotAuthorizedError, InvalidResourceError, CustomMassenergizeError
Expand Down Expand Up @@ -63,6 +64,7 @@ def list_vendors(self, context: Context, args) -> Tuple[list, MassEnergizeAPIErr

def create_vendor(self, context: Context, args, user_submitted) -> Tuple[Vendor, MassEnergizeAPIError]:
try:
image_info = make_media_info(args)
tags = args.pop('tags', [])
communities = args.pop('communities', [])
images = args.pop('image', None)
Expand All @@ -85,6 +87,8 @@ def create_vendor(self, context: Context, args, user_submitted) -> Tuple[Vendor,
if user_submitted:
name=f"ImageFor {new_vendor.name} Vendor"
logo = Media.objects.create(name=name, file=images)
user_media_upload = makeUserUpload(media = logo,info=image_info)

else:
logo = Media.objects.filter(pk = images[0]).first()
new_vendor.logo = logo
Expand All @@ -104,6 +108,9 @@ def create_vendor(self, context: Context, args, user_submitted) -> Tuple[Vendor,
user = UserProfile.objects.filter(email=user_email).first()
if user:
new_vendor.user = user
if user_media_upload:
user_media_upload.user = user
user_media_upload.save()

if website:
new_vendor.more_info = {'website': website}
Expand All @@ -128,6 +135,7 @@ def create_vendor(self, context: Context, args, user_submitted) -> Tuple[Vendor,
def update_vendor(self, context: Context, args, user_submitted) -> Tuple[dict, MassEnergizeAPIError]:

try:
image_info = make_media_info(args)
vendor_id = args.pop('vendor_id', None)
vendors = Vendor.objects.filter(id=vendor_id)
if not vendors:
Expand Down Expand Up @@ -176,6 +184,7 @@ def update_vendor(self, context: Context, args, user_submitted) -> Tuple[dict, M
else:
image= Media.objects.create(file=images, name=f'ImageFor {vendor.name} Vendor')
vendor.logo = image
makeUserUpload(media = image,info=image_info, user=vendor.user)
else:
if images[0] == RESET: #if image is reset, delete the existing image
vendor.logo = None
Expand Down
13 changes: 8 additions & 5 deletions src/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ def simple_json(self):
obj = {
"id": self.id,
"name": self.name,
"url": self.file.url,
"url": self.file.url,
}

if hasattr(self, "user_upload"):
if hasattr(self, "user_upload"):
obj["created_at"] = self.user_upload.created_at
obj["info"] = self.user_upload.info

return obj

Expand Down Expand Up @@ -1230,8 +1230,11 @@ class UserMediaUpload(models.Model):
)

def __str__(self):
return f"{str(self.id)} - {self.media.name} from {self.user.preferred_name or self.user.full_name} "

if self.user:
return f"{str(self.id)} - {self.media.name} from {self.user.preferred_name or self.user.full_name} "

return f"{str(self.id)} - {self.media.name} from ..."

def simple_json(self):
res = model_to_dict(
self, ["settings", "media", "created_at", "id", "is_universal", "info", "publicity"]
Expand Down

0 comments on commit e7e7997

Please sign in to comment.