-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from CentreForDigitalHumanities/feature/item-…
…gift-form Feature/item gift form
- Loading branch information
Showing
58 changed files
with
1,940 additions
and
176 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from graphene import Enum, InputObjectType | ||
from core.models import SourceMention | ||
from core.types.input.FieldInputType import FieldInputType | ||
|
||
|
||
class DescriptionFieldInputType(FieldInputType, InputObjectType): | ||
source_mention = Enum.from_enum(SourceMention)() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from graphene import ID, InputObjectType, List, NonNull, String | ||
|
||
from core.types.input.NamedInputType import NamedInputType | ||
|
||
|
||
class EntityDescriptionInputType(NamedInputType, InputObjectType): | ||
book = String() | ||
chapter = String() | ||
page = String() | ||
designators = List(NonNull(String)) | ||
categories = List(NonNull(ID)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from graphene import InputObjectType, Int, String | ||
|
||
|
||
class FieldInputType(InputObjectType): | ||
certainty = String() | ||
note = String() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from graphene import InputObjectType, String | ||
|
||
|
||
class NamedInputType(InputObjectType): | ||
name = String() | ||
description = String() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from graphene import ( | ||
ID, | ||
Field, | ||
InputObjectType, | ||
List, | ||
NonNull, | ||
ResolveInfo, | ||
String, | ||
) | ||
|
||
from letter.models import GiftDescription | ||
from letter.types.GiftDescriptionType import GiftDescriptionType | ||
from graphql_app.LettercraftMutation import LettercraftMutation | ||
from graphql_app.types.LettercraftErrorType import LettercraftErrorType | ||
from source.models import Source | ||
|
||
|
||
class CreateGiftInput(InputObjectType): | ||
name = String(required=True) | ||
source = ID(required=True) | ||
|
||
|
||
class CreateGiftMutation(LettercraftMutation): | ||
gift = Field(GiftDescriptionType) | ||
errors = List(NonNull(LettercraftErrorType), required=True) | ||
|
||
django_model = GiftDescription | ||
|
||
class Arguments: | ||
gift_data = CreateGiftInput(required=True) | ||
|
||
@classmethod | ||
def mutate(cls, root: None, info: ResolveInfo, gift_data: CreateGiftInput): | ||
try: | ||
source = Source.objects.get(id=getattr(gift_data, "source")) | ||
except Source.DoesNotExist: | ||
error = LettercraftErrorType(field="source", messages=["Source not found."]) | ||
return cls(errors=[error]) # type: ignore | ||
|
||
letter = GiftDescription.objects.create( | ||
name=getattr(gift_data, "name"), | ||
source=source, | ||
) | ||
|
||
return cls(Letter=letter, errors=[]) # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from graphene import ( | ||
ID, | ||
Field, | ||
InputObjectType, | ||
List, | ||
NonNull, | ||
ResolveInfo, | ||
String, | ||
) | ||
|
||
from letter.models import LetterDescription | ||
from letter.types.LetterDescriptionType import LetterDescriptionType | ||
from graphql_app.LettercraftMutation import LettercraftMutation | ||
from graphql_app.types.LettercraftErrorType import LettercraftErrorType | ||
from source.models import Source | ||
|
||
|
||
class CreateLetterInput(InputObjectType): | ||
name = String(required=True) | ||
source = ID(required=True) | ||
|
||
|
||
class CreateLetterMutation(LettercraftMutation): | ||
letter = Field(LetterDescriptionType) | ||
errors = List(NonNull(LettercraftErrorType), required=True) | ||
|
||
django_model = LetterDescription | ||
|
||
class Arguments: | ||
letter_data = CreateLetterInput(required=True) | ||
|
||
@classmethod | ||
def mutate(cls, root: None, info: ResolveInfo, letter_data: CreateLetterInput): | ||
try: | ||
source = Source.objects.get(id=getattr(letter_data, "source")) | ||
except Source.DoesNotExist: | ||
error = LettercraftErrorType(field="source", messages=["Source not found."]) | ||
return cls(errors=[error]) # type: ignore | ||
|
||
letter = LetterDescription.objects.create( | ||
name=getattr(letter_data, "name"), | ||
source=source, | ||
) | ||
|
||
return cls(Letter=letter, errors=[]) # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from graphene import ID, Boolean, List, Mutation, NonNull, ResolveInfo | ||
|
||
from letter.models import GiftDescription | ||
from letter.types.GiftDescriptionType import GiftDescriptionType | ||
from graphql_app.types.LettercraftErrorType import LettercraftErrorType | ||
|
||
|
||
class DeleteGiftMutation(Mutation): | ||
ok = Boolean(required=True) | ||
errors = List(NonNull(LettercraftErrorType), required=True) | ||
|
||
class Arguments: | ||
id = ID(required=True) | ||
|
||
@classmethod | ||
def mutate(cls, root: None, info: ResolveInfo, id: str): | ||
try: | ||
gift = GiftDescriptionType.get_queryset( | ||
GiftDescription.objects, info | ||
).get(id=id) | ||
except GiftDescription.DoesNotExist: | ||
error = LettercraftErrorType(field="id", messages=["Gift not found."]) | ||
return cls(ok=False, errors=[error]) # type: ignore | ||
|
||
gift.delete() | ||
return cls(ok=True, errors=[]) # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from graphene import ID, Boolean, List, Mutation, NonNull, ResolveInfo | ||
|
||
from letter.models import LetterDescription | ||
from letter.types.LetterDescriptionType import LetterDescriptionType | ||
from graphql_app.types.LettercraftErrorType import LettercraftErrorType | ||
|
||
|
||
class DeleteLetterMutation(Mutation): | ||
ok = Boolean(required=True) | ||
errors = List(NonNull(LettercraftErrorType), required=True) | ||
|
||
class Arguments: | ||
id = ID(required=True) | ||
|
||
@classmethod | ||
def mutate(cls, root: None, info: ResolveInfo, id: str): | ||
try: | ||
letter = LetterDescriptionType.get_queryset( | ||
LetterDescription.objects, info | ||
).get(id=id) | ||
except LetterDescription.DoesNotExist: | ||
error = LettercraftErrorType(field="id", messages=["Letter not found."]) | ||
return cls(ok=False, errors=[error]) # type: ignore | ||
|
||
letter.delete() | ||
return cls(ok=True, errors=[]) # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from graphene import ID, Boolean, InputObjectType, List, NonNull, ResolveInfo | ||
from django.core.exceptions import ObjectDoesNotExist | ||
from core.types.input.DescriptionFieldInputType import DescriptionFieldInputType | ||
from core.types.input.EntityDescriptionInputType import EntityDescriptionInputType | ||
from letter.models import GiftDescription | ||
from graphql_app.LettercraftMutation import LettercraftMutation | ||
|
||
from graphql_app.types.LettercraftErrorType import LettercraftErrorType | ||
|
||
|
||
class GiftCategorisationInput(DescriptionFieldInputType, InputObjectType): | ||
id = ID() | ||
category = ID(required=True) | ||
|
||
|
||
class UpdateGiftInput(EntityDescriptionInputType, InputObjectType): | ||
id = ID(required=True) | ||
categorisations = List(NonNull(GiftCategorisationInput)) | ||
|
||
|
||
class UpdateGiftMutation(LettercraftMutation): | ||
ok = Boolean(required=True) | ||
errors = List(NonNull(LettercraftErrorType), required=True) | ||
|
||
django_model = GiftDescription | ||
|
||
class Arguments: | ||
gift_data = UpdateGiftInput(required=True) | ||
|
||
@classmethod | ||
def mutate(cls, root: None, info: ResolveInfo, gift_data: UpdateGiftInput): | ||
try: | ||
retrieved_object = cls.get_or_create_object(info, gift_data) | ||
except ObjectDoesNotExist as e: | ||
error = LettercraftErrorType(field="id", messages=[str(e)]) | ||
return cls(ok=False, errors=[error]) # type: ignore | ||
|
||
gift: GiftDescription = retrieved_object.object # type: ignore | ||
|
||
try: | ||
cls.mutate_object(gift_data, gift, info, ["categorisations"]) | ||
except ObjectDoesNotExist as field: | ||
error = LettercraftErrorType( | ||
field=str(field), messages=["Related object cannot be found."] | ||
) | ||
return cls(ok=False, errors=[error]) # type: ignore | ||
|
||
# TODO: resolve categorisations | ||
|
||
user = info.context.user | ||
gift.contributors.add(user) | ||
|
||
gift.save() | ||
|
||
return cls(ok=True, errors=[]) # type: ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
from graphene import ID, Boolean, InputObjectType, List, NonNull, ResolveInfo | ||
from django.core.exceptions import ObjectDoesNotExist | ||
from core.types.input.DescriptionFieldInputType import DescriptionFieldInputType | ||
from core.types.input.EntityDescriptionInputType import EntityDescriptionInputType | ||
from letter.models import LetterDescription | ||
from graphql_app.LettercraftMutation import LettercraftMutation | ||
|
||
from graphql_app.types.LettercraftErrorType import LettercraftErrorType | ||
|
||
|
||
class LetterCategorisationInput(DescriptionFieldInputType, InputObjectType): | ||
id = ID() | ||
category = ID(required=True) | ||
|
||
|
||
class UpdateLetterInput(EntityDescriptionInputType, InputObjectType): | ||
id = ID(required=True) | ||
categorisations = List(NonNull(LetterCategorisationInput)) | ||
|
||
|
||
class UpdateLetterMutation(LettercraftMutation): | ||
ok = Boolean(required=True) | ||
errors = List(NonNull(LettercraftErrorType), required=True) | ||
|
||
django_model = LetterDescription | ||
|
||
class Arguments: | ||
letter_data = UpdateLetterInput(required=True) | ||
|
||
@classmethod | ||
def mutate(cls, root: None, info: ResolveInfo, letter_data: UpdateLetterInput): | ||
try: | ||
retrieved_object = cls.get_or_create_object(info, letter_data) | ||
except ObjectDoesNotExist as e: | ||
error = LettercraftErrorType(field="id", messages=[str(e)]) | ||
return cls(ok=False, errors=[error]) # type: ignore | ||
|
||
letter: LetterDescription = retrieved_object.object # type: ignore | ||
|
||
try: | ||
cls.mutate_object(letter_data, letter, info, ["categorisations"]) | ||
except ObjectDoesNotExist as field: | ||
error = LettercraftErrorType( | ||
field=str(field), messages=["Related object cannot be found."] | ||
) | ||
return cls(ok=False, errors=[error]) # type: ignore | ||
|
||
# TODO: resolve categorisations | ||
|
||
user = info.context.user | ||
letter.contributors.add(user) | ||
|
||
letter.save() | ||
|
||
return cls(ok=True, errors=[]) # type: ignore |
Oops, something went wrong.