Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement template boolean to allow unlimited templates #3723

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions lego/apps/surveys/migrations/0013_survey_is_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.db import migrations, models

def set_is_template(apps, schema_editor):
Survey = apps.get_model("surveys", "Survey")
Survey.objects.filter(template_type__isnull=False).update(is_template=True)

class Migration(migrations.Migration):

dependencies = [
("surveys", "0012_alter_survey_template_type"),
]

operations = [
migrations.AddField(
model_name="survey",
name="is_template",
field=models.BooleanField(default=False),
),
migrations.RunPython(set_is_template),
]
1 change: 1 addition & 0 deletions lego/apps/surveys/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Survey(BasisModel):
template_type = models.CharField(
max_length=30, choices=EVENT_TYPES, null=True, blank=True, unique=True
)
is_template = models.BooleanField(default=False, null=False)
event = models.OneToOneField("events.Event", on_delete=models.CASCADE)
sent = models.BooleanField(default=False)
token = models.CharField(
Expand Down
8 changes: 4 additions & 4 deletions lego/apps/surveys/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class SurveyReadSerializer(BasisModelSerializer):

class Meta:
model = Survey
fields = ("id", "title", "active_from", "event", "template_type")
fields = ("id", "title", "active_from", "event", "template_type", "is_template")


class SubmissionReadSerializer(BasisModelSerializer):
Expand Down Expand Up @@ -144,7 +144,7 @@ class SurveyReadDetailedSerializer(BasisModelSerializer):

class Meta:
model = Survey
fields = ("id", "title", "active_from", "questions", "event", "template_type")
fields = ("id", "title", "active_from", "questions", "event", "template_type","is_template")


class SurveyReadDetailedAdminSerializer(SurveyReadDetailedSerializer):
Expand All @@ -160,7 +160,7 @@ class SurveyCreateSerializer(BasisModelSerializer):

class Meta:
model = Survey
fields = ("id", "title", "active_from", "template_type", "event", "questions")
fields = ("id", "title", "active_from", "template_type","is_template", "event", "questions")

@atomic
def create(self, validated_data):
Expand All @@ -183,7 +183,7 @@ class SurveyUpdateSerializer(BasisModelSerializer):

class Meta:
model = Survey
fields = ("id", "title", "active_from", "template_type", "event", "questions")
fields = ("id", "title", "active_from", "template_type","is_template", "event", "questions")

@atomic
def update(self, instance, validated_data):
Expand Down
4 changes: 2 additions & 2 deletions lego/apps/surveys/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ class SurveyTemplateViewSet(
queryset = (
Survey.objects.all()
.prefetch_related("questions")
.filter(template_type__isnull=False)
.filter(is_template__isnull=False)
)
lookup_field = "template_type"
lookup_field = "is_template"
filter_backends = (DjangoFilterBackend,)

def get_serializer_class(self):
Expand Down