Skip to content

Commit

Permalink
Inherit the FlagStateForm from Django Flags
Browse files Browse the repository at this point in the history
This change will use the FlagStateForm from Django-Flags as the superclass for the Wagtail-Flags FlagStateForm. This way, Wagtail-Flags will use the Django-Flags condition validators introduced in Django-Flags 5.0.
  • Loading branch information
willbarton committed Aug 18, 2020
1 parent be981f6 commit 020ea71
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
21 changes: 2 additions & 19 deletions wagtailflags/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django import forms

from flags.conditions import get_conditions
from flags.forms import FlagStateForm
from flags.models import FlagState
from flags.sources import get_flags

Expand Down Expand Up @@ -29,27 +29,10 @@ class Meta:
fields = ("name",)


class FlagStateForm(forms.ModelForm):
class FlagStateForm(FlagStateForm):
name = forms.CharField(
label="Flag", required=True, disabled=True, widget=forms.HiddenInput(),
)
condition = forms.ChoiceField(label="Condition", required=True)
value = forms.CharField(label="Expected value", required=True)
required = forms.BooleanField(
label="Required",
required=False,
help_text=(
'All conditions marked "required" must be met to enable '
"the flag"
),
)

def __init__(self, *args, **kwargs):
super(FlagStateForm, self).__init__(*args, **kwargs)

self.fields["condition"].choices = [
(c, c) for c in sorted(get_conditions()) if c != "boolean"
]

class Meta:
model = FlagState
Expand Down
2 changes: 0 additions & 2 deletions wagtailflags/templates/wagtailflags/flags/edit_condition.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ <h2 class="nice-padding">
{% if form.instance %}Edit {{ form.instance.condition }}{% else %}Create condition{% endif %}
</h2>

{{ form.errors }}

{% if condition_pk %}
<form class="nice-padding" method="POST" action="{% url 'wagtailflags:edit_condition' flag.name condition_pk %}">
{% else %}
Expand Down

0 comments on commit 020ea71

Please sign in to comment.