def update(self, instance, validated_data): try: need_to_save = False if 'text' in validated_data: instance.text = validated_data.get('text', instance.text) need_to_save = True if 'text_rich_json' in validated_data: instance.text_rich_json = validated_data.get('text_rich_json', instance.text_rich_json) need_to_save = True if need_to_save: instance.save() if 'places' in validated_data: place_utilities.delete_removed_places_from(instance, validated_data['places']) place_utilities.add_places_to(instance, validated_data['places']) if 'tags' in validated_data: tag_utils.delete_removed_tags_from(instance, validated_data['tags']) tag_utils.add_tags_to(instance, validated_data['tags']) if 'categories' in validated_data: category_utilities.delete_removed_categories_from(instance, validated_data['categories']) category_utilities.add_categories_to(instance, validated_data['categories']) if 'photo_collections' in validated_data: image_utils.save_photo_collections(instance, validated_data['photo_collections'], instance.post.group, instance.owner) updated_instance = Comment.objects.get(pk=instance.id) return updated_instance except Exception as e: raise e
def create(self, validated_data): try: feedback = UserFeedback(validated_data) feedback.id = None feedback.owner = User.objects.get(pk=validated_data['owner_id']) feedback.text = validated_data['text'] feedback.group = Group.objects.get(pk=settings.ADMIN_LOOP) feedback.save() # The permissions in save_photo_collections are different here than usual # The owner of this feedback does not belong to our admin group image_utils.save_photo_collections( feedback, validated_data['photo_collections'], feedback.group, feedback.owner) self.send_email(feedback) return feedback except Exception as e: raise e
def create(self, validated_data): try: new_comment = Comment(validated_data) new_comment.text = validated_data['text'] new_comment.text_rich_json = validated_data['text_rich_json'] new_comment.owner = User.objects.get(pk=validated_data['owner_id']) new_comment.post = Post.objects.get(pk=validated_data['post_id']) new_comment.post_id = validated_data['post_id'] new_comment.id = None new_comment.save() place_utilities.add_places_to(new_comment, validated_data['places']) tag_utils.add_tags_to(new_comment, validated_data['tags']) category_utilities.add_categories_to(new_comment, validated_data['categories']) image_utils.save_photo_collections(new_comment, validated_data['photo_collections'], new_comment.post.group, new_comment.owner) return new_comment except Exception as e: raise e