def assing_image_profile(self, user: accounts_models.User, id_image: int) -> accounts_models.User: """ Assigned a image for profile user, this image can see for all user in weedmtach, this method raise a exception if id of image not exist in database :param user: user weedmtach :type user: Model User :param id_image: id of image profile :type id_image: integer :return: Model User :raise: ValueError """ if user is None or user.is_active is False: raise ValueError('{"detail":"' + str( _("In order to perform this operation, your account must be active" )) + '"}') try: image = accounts_models.ImageProfile.objects.get(id=id_image, user_id=user.id) except accounts_models.ImageProfile.DoesNotExist: raise ValueError('{"detail":"' + str(_("There is no such image on your profile")) + '"}') user.assign_image_profile(str(image.image_profile)) return user
def upload_images(self, user: accounts_models.User, data: dict) -> accounts_models.User: """ the user can upload images for his profile, if he has not assigned a still the first image to upload he will be placed in profile, this method raises exception if the user try upload a seventh image :param user: user weedmatch. :type user: Model User. :param data: user data. :type data: dict :return: Model User :raises: ValueError """ if user is None or user.is_active is False: raise ValueError('{"detail":"' + str( _("In order to perform this operation, your account must be active" )) + '"}') if not data.get('image'): raise ValueError( '{"detail":"' + str(_("The profile image field can not be empty")) + '"}') if user.count_image < 6: images_profile = accounts_models.ImageProfile.objects.create( user_id=user.id, image_profile=data.get('image')) if not user.image: user.assign_image_profile(str(images_profile.image_profile)) user.count_increment() else: raise ValueError('{"detail":"' + str( _("You can not upload more than 6 images in your profile, you must delete some" )) + '"}') return user