-
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 #155 from CentreForDigitalHumanities/feature/order…
…-episodes-in-source Feature/order episodes in source
- Loading branch information
Showing
24 changed files
with
462 additions
and
20 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
17 changes: 17 additions & 0 deletions
17
backend/event/migrations/0029_alter_episode_order_with_respect_to.py
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,17 @@ | ||
# Generated by Django 4.2.7 on 2024-10-30 13:39 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('event', '0028_alter_episode_source_mention_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterOrderWithRespectTo( | ||
name='episode', | ||
order_with_respect_to='source', | ||
), | ||
] |
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,56 @@ | ||
from graphene import Mutation, Boolean, List, NonNull, ID, ResolveInfo | ||
|
||
from event.models import Episode | ||
from graphql_app.types.LettercraftErrorType import LettercraftErrorType | ||
from source.models import Source | ||
|
||
|
||
class UpdateEpisodeOrderMutation(Mutation): | ||
ok = Boolean(required=True) | ||
errors = List(NonNull(LettercraftErrorType), required=True) | ||
|
||
class Arguments: | ||
episode_ids = List( | ||
NonNull(ID), required=True, description="Ordered list of episode IDs" | ||
) | ||
|
||
@classmethod | ||
def mutate(cls, root: None, info: ResolveInfo, episode_ids: list[str]): | ||
if len(episode_ids) == 0: | ||
error = LettercraftErrorType( | ||
field="episode_ids", messages=["No episode IDs provided."] | ||
) | ||
return cls(ok=False, errors=[error]) # type: ignore | ||
|
||
# Check if all episode IDs are valid. | ||
episodes = Episode.objects.filter(id__in=episode_ids).prefetch_related("source") | ||
if episodes.count() != len(episode_ids): | ||
error = LettercraftErrorType( | ||
field="episode_ids", | ||
messages=["Not every provided episode ID is valid."], | ||
) | ||
return cls(ok=False, errors=[error]) # type: ignore | ||
|
||
corresponding_sources: set[Source] = {episode.source for episode in episodes} | ||
|
||
# Check if there is at least one source for the provided episode IDs. | ||
# (There should always be.) | ||
if len(corresponding_sources) == 0: | ||
error = LettercraftErrorType( | ||
field="episode_ids", messages=["No source found for given episode IDs."] | ||
) | ||
return cls(ok=False, errors=[error]) # type: ignore | ||
|
||
# Check if all provided episode IDs belong to the same source. | ||
if len(corresponding_sources) > 1: | ||
error = LettercraftErrorType( | ||
field="episode_ids", | ||
messages=["The provided episode IDs belong to more than one source."], | ||
) | ||
return cls(ok=False, errors=[error]) # type: ignore | ||
|
||
source = corresponding_sources.pop() | ||
|
||
source.set_episode_order(episode_ids) # type: ignore | ||
|
||
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,29 @@ | ||
from django.db.models.query import QuerySet | ||
|
||
|
||
def test_episode_order_mutation(graphql_client, episode, episode_2): | ||
result = graphql_client.execute( | ||
f""" | ||
mutation TestMutation {{ | ||
updateEpisodeOrder( | ||
episodeIds: [ | ||
{episode_2.pk}, {episode.pk} | ||
] | ||
) {{ | ||
ok | ||
errors {{ | ||
field | ||
messages | ||
}} | ||
}} | ||
}} | ||
""" | ||
) | ||
|
||
assert result["data"]["updateEpisodeOrder"]["ok"] == True | ||
assert result["data"]["updateEpisodeOrder"]["errors"] == [] | ||
|
||
order_queryset = episode.source.get_episode_order() # type: QuerySet | ||
ids_list = list(order_queryset.values_list("id", flat=True)) | ||
|
||
assert ids_list == [episode_2.pk, episode.pk] |
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
21 changes: 21 additions & 0 deletions
21
backend/letter/migrations/0022_alter_giftdescription_order_with_respect_to_and_more.py
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,21 @@ | ||
# Generated by Django 4.2.7 on 2024-10-30 13:39 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('letter', '0021_alter_giftdescription_source_mention_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterOrderWithRespectTo( | ||
name='giftdescription', | ||
order_with_respect_to='source', | ||
), | ||
migrations.AlterOrderWithRespectTo( | ||
name='letterdescription', | ||
order_with_respect_to='source', | ||
), | ||
] |
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
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,5 @@ | ||
.button-group-wrapper { | ||
display: flex; | ||
align-items: center; | ||
gap: 1rem; | ||
} |
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
Oops, something went wrong.