def mutate(root, info, id): try: instance = Entry.objects.get(id=id) except Entry.DoesNotExist: return DeleteEntry(errors=[ CustomErrorType(field='non_field_errors', messages=gettext('Entry does not exist.')) ]) if not instance.can_be_updated_by(info.context.user): return DeleteEntry(errors=[ CustomErrorType(field='non_field_errors', messages=gettext( 'You cannot delete this entry.')) ]) instance.delete() instance.id = id return DeleteEntry(entry=instance, errors=None, ok=True)
def mutate(root, info, id): try: instance = Event.objects.get(id=id) except Event.DoesNotExist: return DeleteEvent(errors=[ CustomErrorType(field='non_field_errors', messages=gettext('Event does not exist.')) ]) instance.delete() instance.id = id return DeleteEvent(event=instance, errors=None, ok=True)
def mutate(root, info, member, group): try: instance = GroupMember.objects.get(member=member, group=group) except GroupMember.DoesNotExist: return DeleteGroupMember(errors=[ CustomErrorType(field='non_field_errors', messages=gettext('Member does not exist.')) ]) instance.delete() instance.id = id return DeleteGroupMember(groupmember=instance, errors=None, ok=True)
def mutate(root, info, figure): serializer = FigureSerializer(data=figure, context={'request': info.context}) try: entry = Entry.objects.get(id=figure['entry']) except Entry.DoesNotExist: return CreateFigure(errors=[ CustomErrorType(field='non_field_errors', messages=gettext('Entry does not exist.')) ]) if not Figure.can_be_created_by(info.context.user, entry=entry): return CreateFigure(errors=[ CustomErrorType( field='non_field_errors', messages=gettext( 'You cannot create a figure into this entry.')) ]) if errors := mutation_is_not_valid(serializer): return CreateFigure(errors=errors, ok=False)
def mutate(root, info, event): try: instance = Event.objects.get(id=event['id']) except Event.DoesNotExist: return UpdateEvent(errors=[ CustomErrorType(field='non_field_errors', messages=gettext('Event does not exist.')) ]) serializer = EventSerializer(instance=instance, data=event, partial=True) if errors := mutation_is_not_valid(serializer): return UpdateEvent(errors=errors, ok=False)
def mutate(root, info, id): try: instance = ResourceGroup.objects.get(id=id, created_by=info.context.user) except ResourceGroup.DoesNotExist: return DeleteResourceGroup(errors=[ CustomErrorType(field='non_field_errors', messages=gettext( 'ResourceGroup does not exist.')) ]) can_delete, msg = instance.can_delete() if not can_delete: return DeleteResourceGroup(errors=[ CustomErrorType(field='non_field_errors', messages=msg) ]) instance.delete() instance.id = id return DeleteResourceGroup(resource_group=instance, errors=None, ok=True)
def mutate(root, info, entry): try: instance = Entry.objects.get(id=entry['id']) except Entry.DoesNotExist: return UpdateEntry(errors=[ CustomErrorType(field='non_field_errors', messages=gettext('Entry does not exist.')) ]) if not instance.can_be_updated_by(info.context.user): return UpdateEntry(errors=[ CustomErrorType(field='non_field_errors', messages=gettext( 'You cannot update this entry.')) ]) serializer = EntrySerializer(instance=instance, data=entry, context={'request': info.context}, partial=True) if errors := mutation_is_not_valid(serializer): return UpdateEntry(errors=errors, ok=False)
def mutate(root, info, data): try: instance = Task.objects.get(id=data['id']) except Task.DoesNotExist: return UpdateTask(errors=[ CustomErrorType(field='nonFieldErrors', messages=[gettext('Task does not exist.')]) ]) serializer = TaskSerializer(instance=instance, data=data, partial=True) if errors := mutation_is_not_valid(serializer): return UpdateTask(errors=errors, ok=False)
def mutate(root, info, figure): try: instance = Figure.objects.get(id=figure['id']) except Figure.DoesNotExist: return UpdateFigure(errors=[ CustomErrorType(field='non_field_errors', messages=gettext('Figure does not exist.')) ]) if not instance.can_be_updated_by(info.context.user): return UpdateFigure(errors=[ CustomErrorType(field='non_field_errors', messages=gettext( 'You cannot update this figure.')) ]) serializer = FigureSerializer(instance=instance, data=figure, context={'request': info.context}, partial=True) if errors := mutation_is_not_valid(serializer): return UpdateFigure(errors=errors, ok=False)
def mutate(root, info, id): try: instance = Crisis.objects.get(id=id) except Crisis.DoesNotExist: return DeleteCrisis(errors=[ CustomErrorType(field='non_field_errors', messages=gettext('Crisis does not exist.')) ]) instance.delete() instance.id = id return DeleteCrisis(crisis=instance, errors=None, ok=True)
def mutate(root, info, id): try: instance = TimeEntry.objects.get(id=id) except TimeEntry.DoesNotExist: return DeleteTimeEntry(errors=[ CustomErrorType(field='nonFieldErrors', messages=gettext('Task does not exist')) ]) instance.delete() instance.id = id return DeleteTimeEntry(result=instance, errors=None, ok=True)
def mutate(root, info, id): try: instance = Organization.objects.get(id=id) except Organization.DoesNotExist: return UpdateOrganization(errors=[ CustomErrorType(field='non_field_errors', messages=gettext( 'Organization does not exist.')) ]) instance.delete() instance.id = id return DeleteOrganization(organization=instance, errors=None, ok=True)
def mutate(root, info, id): try: instance = Resource.objects.get(id=id, created_by=info.context.user) except Resource.DoesNotExist: return UpdateResource(errors=[ CustomErrorType(field='non_field_errors', messages=gettext('Resource does not exist.')) ]) instance.delete() instance.id = id return DeleteResource(resource=instance, errors=None, ok=True)
def mutate(root, info, id): # TODO add can delete or not try: instance = Tag.objects.get(id=id) except Tag.DoesNotExist: return DeleteTag(errors=[ CustomErrorType(field='nonFieldErrors', messages=gettext('Tag does not Exist')) ]) instance.delete() instance.id = id return DeleteTag(result=instance, errors=None, ok=True)
def mutate(root, info, crisis): try: instance = Crisis.objects.get(id=crisis['id']) except Crisis.DoesNotExist: return UpdateCrisis(errors=[ CustomErrorType(field='non_field_errors', messages=gettext('Crisis does not exist.')) ]) serializer = CrisisSerializer(instance=instance, data=crisis, partial=True) if errors := mutation_is_not_valid(serializer): return UpdateCrisis(errors=errors, ok=False)
def mutate(root, info, group): try: instance = UserGroup.objects.get(id=group['id']) except UserGroup.DoesNotExist: return UpdateUserGroup(errors=[ CustomErrorType(field='non_field_errors', messages=[gettext('UserGroup does not exist.')]) ]) serializer = UserGroupSerializer(instance=instance, data=group, partial=True) if errors:= mutation_is_not_valid(serializer): return UpdateUserGroup(errors=errors, ok=False)
def mutate(root, info, organization_kind): try: instance = OrganizationKind.objects.get(id=organization_kind['id']) except OrganizationKind.DoesNotExist: return UpdateOrganizationKind(errors=[ CustomErrorType(field='non_field_errors', messages=gettext( 'Organization type does not exist.')) ]) serializer = OrganizationKindSerializer(instance=instance, data=organization_kind, partial=True) if errors := mutation_is_not_valid(serializer): return UpdateOrganizationKind(errors=errors, ok=False)
def mutate(root, info, data): try: instance = Tag.objects.get(id=data['id']) except Tag.DoesNotExist: return UpdateTag(errors=[ CustomErrorType(field='nonFieldErrors', messages=gettext('Tag does not exist')) ]) serializer = TagSerializer(instance=instance, data=data, context={'request': info.context}, partial=True) if errors := mutation_is_not_valid(serializer): return UpdateTag(errors=errors, ok=False)
def mutate(root, info, data): # TODO : Add can update or not try: instance = Project.objects.get(id=data['id']) except Project.DoesNotExist: return UpdateClient(errors=[ CustomErrorType(field='nonFieldErrors', messages=gettext('Project Does not exist')) ]) serializer = ProjectSerializer(instance=instance, data=data, context={'request': info.context}, partial=True) if errors := mutation_is_not_valid(serializer): return UpdateProject(errors=errors, ok=False)
def mutate(root, info, resource): try: instance = Resource.objects.get(id=resource['id'], created_by=info.context.user) except Resource.DoesNotExist: return UpdateResource(errors=[ CustomErrorType(field='non_field_errors', messages=gettext('Resource does not exist.')) ]) serializer = ResourceSerializer(instance=instance, data=resource, context={'request': info.context}, partial=True) if errors := mutation_is_not_valid(serializer): return UpdateResource(errors=errors, ok=False)
def mutate(root, info, preview): if preview.get('id'): try: instance = SourcePreview.objects.get(id=preview['id']) serializer = SourcePreviewSerializer( data=preview, instance=instance, context={'request': info.context}) except SourcePreview.DoesNotExist: return CreateSourcePreview(errors=[ CustomErrorType(field='non_field_errors', messages=gettext( 'Preview does not exist.')) ]) else: serializer = SourcePreviewSerializer( data=preview, context={'request': info.context}) if errors := mutation_is_not_valid(serializer): return CreateSourcePreview(errors=errors, ok=False)