Skip to content
This repository was archived by the owner on May 18, 2026. It is now read-only.
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
26 changes: 26 additions & 0 deletions molo/forms/migrations/0009_add_form_type_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 2.2.12 on 2020-05-04 14:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('forms', '0008_articlepageforms'),
]

operations = [
migrations.RemoveField(
model_name='moloformpage',
name='contact_form',
),
migrations.RemoveField(
model_name='moloformpage',
name='your_words_competition',
),
migrations.AddField(
model_name='moloformpage',
name='form_type',
field=models.IntegerField(choices=[(1, 'form'), (2, 'contact'), (3, 'competition'), (4, 'reaction')], default=1, help_text='How will this form be used?'),
),
]
41 changes: 21 additions & 20 deletions molo/forms/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import datetime
from enum import Enum

from django.conf import settings
from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -109,7 +110,19 @@ def create_form_index_pages(sender, instance, **kwargs):

class MoloFormPage(
TranslatablePageMixinNotRoutable,
forms_models.AbstractEmailForm):
forms_models.AbstractEmailForm
):

class FORM_TYPES(Enum):
form = 1
contact = 2
competition = 3
reaction = 4

@classmethod
def as_choice_list(cls):
return [(i.value, i.name) for i in cls]

parent_page_types = [
'forms.FormsIndexPage', 'core.SectionPage', 'core.ArticlePage']
subpage_types = []
Expand Down Expand Up @@ -182,16 +195,13 @@ class MoloFormPage(
'a link to another page to complete the form.'

)
your_words_competition = BooleanField(
default=False,
verbose_name='Is YourWords Competition',
help_text='This will display the correct template for yourwords'
)
contact_form = BooleanField(
default=False,
verbose_name='Is Contact Form',
help_text='This will display the correct template for contact forms'

form_type = models.IntegerField(
default=FORM_TYPES.form.value,
choices=FORM_TYPES.as_choice_list(),
help_text='How will this form be used?'
)

extra_style_hints = models.TextField(
default='',
null=True, blank=True,
Expand Down Expand Up @@ -225,8 +235,7 @@ class MoloFormPage(
FieldPanel('show_results_as_percentage'),
FieldPanel('multi_step'),
FieldPanel('display_form_directly'),
FieldPanel('your_words_competition'),
FieldPanel('contact_form'),
FieldPanel('form_type'),
], heading='Form Settings'),
MultiFieldPanel(
[FieldRowPanel(
Expand Down Expand Up @@ -486,14 +495,6 @@ def clean(self):
raise ValidationError({
'multi_step': error, 'display_form_directly': error})

if all([self.your_words_competition, self.contact_form]):
error = _(
'"{}" and "{}" can not be both selected at the same time'
.format('Is YourWords Competition', 'Is contact form'))

raise ValidationError({
'your_words_competition': error, 'contact_form': error})


class MoloFormPageView(models.Model):
visited_at = models.DateTimeField(auto_now_add=True)
Expand Down
28 changes: 17 additions & 11 deletions molo/forms/templatetags/molo_forms_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,38 @@ def get_form_list(
page = FormsIndexPage.objects.child_of(main).live().first()
if page:
forms = []
your_words = MoloFormPage.FORM_TYPES.competition.value
if only_linked_forms:
forms = (MoloFormPage.objects.descendant_of(page).filter(
language__is_main_language=True,
display_form_directly=False,
contact_form=False,
your_words_competition=False).exact_type(
MoloFormPage).specific())
form_type=MoloFormPage.FORM_TYPES.form.value,
).exact_type(MoloFormPage).specific())

elif only_direct_forms:
forms = (MoloFormPage.objects.descendant_of(page).filter(
language__is_main_language=True, display_form_directly=True,
your_words_competition=False).exact_type(
MoloFormPage).specific())
language__is_main_language=True,
display_form_directly=True
).exclude(
form_type=your_words
).exact_type(MoloFormPage).specific())

elif only_yourwords:
forms = (MoloFormPage.objects.descendant_of(page).filter(
language__is_main_language=True,
your_words_competition=True).exact_type(
MoloFormPage).specific())
language__is_main_language=True, form_type=your_words
).exact_type(MoloFormPage).specific())

elif personalisable_form:
forms = (PersonalisableForm.objects.descendant_of(page).filter(
language__is_main_language=True).exact_type(
PersonalisableForm).specific())

elif contact_form:
forms = (MoloFormPage.objects.descendant_of(page).filter(
language__is_main_language=True,
contact_form=True).exact_type(
MoloFormPage).specific())
form_type=MoloFormPage.FORM_TYPES.contact.value
).exact_type(MoloFormPage).specific())

else:
forms = (MoloFormPage.objects.descendant_of(page).filter(
language__is_main_language=True).exact_type(
Expand Down
14 changes: 0 additions & 14 deletions molo/forms/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,6 @@ def test_model_validation(self):
)
self.assertEqual(e, expected_error)

def test_your_words_competition_flag(self):
with self.assertRaises(ValidationError) as e:
error = '"{}" and "{}" can not be both selected at the same time'\
.format('Is YourWords Competition', 'Is contact form')

MoloFormPage.objects.create(
# parent=self.forms_index,
title="yourwords form title",
slug="yourwords_form_title",
contact_form=True,
your_words_competition=True,
)
self.assertEqual(e, error)


class TestSkipLogicMixin(TestCase, MoloTestCaseMixin):
def setUp(self):
Expand Down
5 changes: 3 additions & 2 deletions molo/forms/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,14 +191,15 @@ def setUp(self):
parent=self.forms_index,
title="test title",
slug="test_tittle",
contact_form=True,
form_type=MoloFormPage.FORM_TYPES
.contact.value,
))
self.yourwords_molo_form_page, yourwords_molo_form_field = (
self.create_molo_form_page(
parent=self.forms_index,
title="yourwords form title",
slug="yourwords_form_title",
your_words_competition=True,
form_type=MoloFormPage.FORM_TYPES.competition.value,
))
self.client.post(reverse(
'add_translation', args=[self.linked_molo_form_page.id, 'fr']))
Expand Down