def mutate_and_get_payload(cls, input, context, info): # check user check_superuser(context) category_field_id = input.get('id') category_field = get_node( category_field_id, context, info, CategoryField) if not category_field: raise ResponseError( "Invalid Category Field", code='invalid_category_field') category_id = input.get('category_id') category = get_node(category_id, context, info, Category) if not category: raise ResponseError( "Invalid Category", code='invalid_category') # update category field form = CategoryFieldForm(input, instance=category_field) if form.is_valid(): form.save() category_field.category = category category_field.save() else: raise FormError(form.errors) return UpdateCategoryFieldMutation(category_field=category_field)
def mutate_and_get_payload(cls, input, context, info): # check user check_superuser(context) category_id = input.get('id', None) category = get_node(category_id, context, info, Category) if not category: raise ResponseError("Invalid Category", code='invalid_category') # delete category category.delete() return DeleteCategoryMutation(deleted_id=category_id)
def mutate_and_get_payload(cls, input, context, info): # check user check_superuser(context) parent_id = input.get('parent_id') parent = get_node(parent_id, context, info, Category) # create category form = CategoryForm(input) if form.is_valid(): new_category = form.save(commit=False) new_category.parent = parent new_category.save() else: raise FormError(form.errors) return CreateCategoryMutation(category=new_category)
def mutate_and_get_payload(cls, input, context, info): # check user check_superuser(context) category_id = input.get('category_id') category = get_node(category_id, context, info, Category) if not category: raise ResponseError( "Invalid Category", code='invalid_category') # create category field form = CategoryFieldForm(input) if form.is_valid(): new_category_field = form.save(commit=False) new_category_field.category = category new_category_field.save() else: raise FormError(form.errors) return CreateCategoryFieldMutation(category_field=new_category_field)
def mutate_and_get_payload(cls, input, context, info): # check user check_superuser(context) category_id = input.get('id', None) category = get_node(category_id, context, info, Category) if not category: raise ResponseError("Invalid Category", code='invalid_category') parent_id = input.get('parent_id') parent = get_node(parent_id, context, info, Category) # update category form = CategoryForm(input, instance=category) if form.is_valid(): form.save() category.parent = parent category.save() else: raise FormError(form.errors) return UpdateCategoryMutation(category=category)