-
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 #396 from con2/feat/create-dimension
Embetter survey dimensions
- Loading branch information
Showing
32 changed files
with
1,407 additions
and
158 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
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
38 changes: 38 additions & 0 deletions
38
backend/forms/graphql/mutations/create_survey_dimension.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,38 @@ | ||
import graphene | ||
from graphene.types.generic import GenericScalar | ||
|
||
from access.cbac import graphql_check_access | ||
|
||
from ...models.dimension import DimensionDTO | ||
from ...models.survey import Survey | ||
from ..dimension import SurveyDimensionType | ||
|
||
|
||
class CreateSurveyDimensionInput(graphene.InputObjectType): | ||
event_slug = graphene.String(required=True) | ||
survey_slug = graphene.String(required=True) | ||
form_data = GenericScalar(required=True) | ||
|
||
|
||
class CreateSurveyDimension(graphene.Mutation): | ||
class Arguments: | ||
input = CreateSurveyDimensionInput(required=True) | ||
|
||
dimension = graphene.Field(SurveyDimensionType) | ||
|
||
@staticmethod | ||
def mutate( | ||
root, | ||
info, | ||
input: CreateSurveyDimensionInput, | ||
): | ||
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") | ||
|
||
form_data: dict[str, str] = input.form_data # type: ignore | ||
print(form_data) | ||
dimension = DimensionDTO.from_form_data(form_data).save(survey) | ||
|
||
return CreateSurveyDimension(dimension=dimension) # 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
36 changes: 36 additions & 0 deletions
36
backend/forms/graphql/mutations/delete_survey_dimension.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,36 @@ | ||
import graphene | ||
|
||
from access.cbac import graphql_check_access | ||
|
||
from ...models.survey import Survey | ||
|
||
|
||
class DeleteSurveyDimensionInput(graphene.InputObjectType): | ||
event_slug = graphene.String(required=True) | ||
survey_slug = graphene.String(required=True) | ||
dimension_slug = graphene.String(required=True) | ||
|
||
|
||
class DeleteSurveyDimension(graphene.Mutation): | ||
class Arguments: | ||
input = DeleteSurveyDimensionInput(required=True) | ||
|
||
slug = graphene.Field(graphene.String) | ||
|
||
@staticmethod | ||
def mutate( | ||
root, | ||
info, | ||
input: DeleteSurveyDimensionInput, | ||
): | ||
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") | ||
|
||
# TODO can_delete | ||
|
||
dimension = survey.dimensions.get(slug=input.dimension_slug) | ||
dimension.delete() | ||
|
||
return DeleteSurveyDimension(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
20 changes: 20 additions & 0 deletions
20
backend/forms/migrations/0022_dimension_is_shown_to_respondent.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,20 @@ | ||
# Generated by Django 5.0.1 on 2024-01-27 16:03 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("forms", "0021_dimension_is_multi_value"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="dimension", | ||
name="is_shown_to_respondent", | ||
field=models.BooleanField( | ||
default=False, | ||
help_text="If set, the respondent will see the value of the dimension in the profile survey responses list.", | ||
), | ||
), | ||
] |
Oops, something went wrong.