def mutate_and_get_payload(cls, root, info, cashier_id): cashier = Node.get_node_from_global_id(info, cashier_id) assert cashier is not None, 'Cashier not Exists' cashier.delete() return DeleteCashierMutation(success=bool(cashier))
def get_node_from_global_id(node, info, global_id): try: for interface in node._meta.interfaces: if issubclass(interface, Node): return interface.get_node_from_global_id(info, global_id) except AttributeError: return Node.get_node_from_global_id(info, global_id)
def mutate_and_get_payload(cls, root, info, clasification_id): clasification = Node.get_node_from_global_id(info, clasification_id) assert clasification is not None, 'Clasification not Exists' clasification.delete() return DeleteClasificationMutation(success=bool(clasification))
def mutate_and_get_payload(cls, root, info, account_id): account = Node.get_node_from_global_id(info, account_id) assert account is not None, 'Account not exists' account.delete() return DeleteAccountMutation(success=bool(account))
def mutate_and_get_payload(cls, root, info, content_id): user = info.context.user content = Node.get_node_from_global_id(info, content_id, only_type=ContentType) user.bookmarks.remove(content) return RemoveBookmark(removed=True)
def test_get_node_from_global_id_queryset(): item_1 = Item.objects.create() item_2 = Item.objects.create() user = User.objects.create() item_3 = Item.objects.create(user=user) item_4 = Item.objects.create(user=user) info = create_resolve_info( schema, ''' query { items(id: $id) { id foo children { id foo } } } ''', user=user, ) assert not Node.get_node_from_global_id( info, to_global_id("ItemNode", item_1.id)) assert not Node.get_node_from_global_id( info, to_global_id("ItemNode", item_2.id)) assert Node.get_node_from_global_id(info, to_global_id("ItemNode", item_3.id)) == item_3 assert Node.get_node_from_global_id(info, to_global_id("ItemNode", item_4.id)) == item_4
def mutate_and_get_payload(cls, root, info, rating_id): user = info.context.user rating = Node.get_node_from_global_id(info, rating_id, only_type=RatingType) if rating in user.downvotes.all(): user.downvotes.remove(rating) if rating in user.upvotes.all(): user.upvotes.remove(rating) else: user.upvotes.add(rating) user.save() return UpvoteRating(rating=rating)
def mutate_and_get_payload(cls, root, info, account_id, name, client_mutation_id=None): account = Node.get_node_from_global_id(info, account_id) name = name cashier = Cashier.objects.filter(account=account, name=name).first() assert cashier is None, 'Cashier exists: {0}'.format( Node.to_global_id('CashierNode', cashier.id)) cashier = Cashier.objects.create(account=account, name=name) success = True return CreateCashierMutation(cashier=cashier, success=success)
def mutate_and_get_payload(cls, root, info, user_id, name, client_mutation_id=None): user = Node.get_node_from_global_id(info, user_id) name = name account = Account.objects.filter(user=user, name=name).first() assert account is None, 'Account exists: {0}'.format( Node.to_global_id('AccountNode', account.id)) account = Account.objects.create(user=user, name=name) success = True return CreateAccountMutation(account=account, success=success)
def mutate_and_get_payload(cls, root, info, account_id, name, client_mutation_id=None): account = Node.get_node_from_global_id(info, account_id) name = name clasification = Clasification.objects.filter(account=account, name=name).first() assert clasification is None, 'Clasification exists: {0}'.format( Node.to_global_id('ClasificationNode', clasification.id)) clasification = Clasification.objects.create(account=account, name=name) success = True return CreateClasificationMutation(clasification=clasification, success=success)
def mutate_and_get_payload(cls, root, info, content_id, score1, score2, score3, recaptcha_token, justification=None): validate_recaptcha_v3(recaptcha_token, 'submit_rating') user = info.context.user content = Node.get_node_from_global_id(info, content_id, only_type=ContentType) qs = Rating.objects.filter(user=user, content=content) if qs: rating = qs[0] rating.score1 = score1 rating.score2 = score2 rating.score3 = score3 rating.justification = justification rating.upvote_count = 0 rating.downvote_count = 0 else: rating = Rating(content=content, user=user, justification=justification, country=user.country, score1=score1, score2=score2, score3=score3) rating.save() return RateContent(rating=rating)