-
Notifications
You must be signed in to change notification settings - Fork 26
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 #400 from con2/feat/dimension-editor-contd
Finish dimension editor
- Loading branch information
Showing
19 changed files
with
656 additions
and
153 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
39 changes: 39 additions & 0 deletions
39
backend/forms/graphql/mutations/delete_survey_dimension_value.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,39 @@ | ||
import graphene | ||
|
||
from access.cbac import graphql_check_access | ||
|
||
from ...models.dimension import DimensionValue | ||
from ...models.survey import Survey | ||
|
||
|
||
class DeleteSurveyDimensionValueInput(graphene.InputObjectType): | ||
event_slug = graphene.String(required=True) | ||
survey_slug = graphene.String(required=True) | ||
dimension_slug = graphene.String(required=True) | ||
value_slug = graphene.String(required=True) | ||
|
||
|
||
class DeleteSurveyDimensionValue(graphene.Mutation): | ||
class Arguments: | ||
input = DeleteSurveyDimensionValueInput(required=True) | ||
|
||
slug = graphene.Field(graphene.String) | ||
|
||
@staticmethod | ||
def mutate( | ||
root, | ||
info, | ||
input: DeleteSurveyDimensionValueInput, | ||
): | ||
survey = Survey.objects.get(event__slug=input.event_slug, slug=input.survey_slug) | ||
|
||
# TODO bastardization of graphql_check_access, rethink | ||
graphql_check_access(survey, info, "dimensions", "mutation") | ||
|
||
value = DimensionValue.objects.get(dimension__slug=input.dimension_slug, slug=input.value_slug) | ||
if not value.can_remove: | ||
raise Exception("Cannot remove dimension value that is in use") | ||
|
||
value.delete() | ||
|
||
return DeleteSurveyDimensionValue(slug=input.survey_slug) # 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
47 changes: 47 additions & 0 deletions
47
backend/forms/graphql/mutations/put_survey_dimension_value.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,47 @@ | ||
import graphene | ||
from graphene.types.generic import GenericScalar | ||
|
||
from access.cbac import graphql_check_access | ||
|
||
from ...models.dimension import DimensionValueDTO | ||
from ...models.survey import Survey | ||
from ..dimension import SurveyDimensionValueType | ||
|
||
|
||
class PutSurveyDimensionValueInput(graphene.InputObjectType): | ||
event_slug = graphene.String(required=True) | ||
survey_slug = graphene.String(required=True) | ||
dimension_slug = graphene.String(required=True) | ||
value_slug = graphene.String(description="If set, update existing; otherwise, create new") | ||
form_data = GenericScalar(required=True) | ||
|
||
|
||
class PutSurveyDimensionValue(graphene.Mutation): | ||
class Arguments: | ||
input = PutSurveyDimensionValueInput(required=True) | ||
|
||
value = graphene.Field(SurveyDimensionValueType) | ||
|
||
@staticmethod | ||
def mutate( | ||
root, | ||
info, | ||
input: PutSurveyDimensionValueInput, | ||
): | ||
survey = Survey.objects.get(event__slug=input.event_slug, slug=input.survey_slug) | ||
form_data: dict[str, str] = input.form_data # type: ignore | ||
|
||
# TODO bastardization of graphql_check_access, rethink | ||
graphql_check_access(survey, info, "dimensions", "mutation") | ||
|
||
dimension = survey.dimensions.get(slug=input.dimension_slug) | ||
|
||
if input.value_slug is None: | ||
if survey.dimensions.filter(slug=form_data["slug"]).exists(): | ||
raise ValueError("Dimension value with this slug already exists") | ||
else: | ||
form_data["slug"] = input.value_slug # type: ignore | ||
|
||
value = DimensionValueDTO.from_form_data(form_data).save(dimension) | ||
|
||
return PutSurveyDimensionValue(value=value) # 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
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
Oops, something went wrong.