-
Notifications
You must be signed in to change notification settings - Fork 15
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
Overhaul the admin and support for required condition #35
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6a8e82f
Drill down into conditions for flags
willbarton 3a76fd6
General improvements to new admin
willbarton af354d3
Update README, screenshots, and requirements
willbarton f81143a
Fix import linting errors
willbarton b873150
Replace deprecated feature flag format in tests
willbarton 24a881a
Use template tags from Django-Flags 4.2.0
willbarton c938a43
Add one big list of flags behind feature flag
willbarton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,65 @@ | ||
from django import forms | ||
|
||
from flags.conditions import get_conditions | ||
from flags.models import FlagState | ||
from flags.sources import get_flags | ||
|
||
|
||
class NewFlagForm(forms.ModelForm): | ||
name = forms.CharField( | ||
label='Name', | ||
required=True | ||
) | ||
|
||
def clean_name(self): | ||
name = self.cleaned_data['name'] | ||
if name in get_flags(): | ||
raise forms.ValidationError( | ||
"Flag named {} already exists".format(name) | ||
) | ||
return name | ||
|
||
def save(self, commit=True): | ||
obj = super(NewFlagForm, self).save(commit=False) | ||
obj.condition = 'boolean' | ||
obj.value = 'False' | ||
obj.required = False | ||
obj.save() | ||
return obj | ||
|
||
class Meta: | ||
model = FlagState | ||
fields = ('name', ) | ||
|
||
|
||
class FlagStateForm(forms.ModelForm): | ||
name = forms.CharField( | ||
label='Flag', | ||
required=True, | ||
disabled=True, | ||
) | ||
condition = forms.ChoiceField( | ||
label='Condition name', | ||
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 | ||
fields = ('name', 'condition', 'value', 'required') |
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,6 @@ | ||
.flags-breadcrumb { | ||
margin-left: 0; | ||
} | ||
section.flag { | ||
margin-top: 4em; | ||
} |
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,8 @@ | ||
{% extends "wagtailadmin/base.html" %} | ||
|
||
<ul class="breadcrumb"> | ||
<li class="home"><a href="#" class="icon icon-home text-replace">Home</a></li> | ||
<li><a href="#">Various</a></li> | ||
<li><a href="#">Subpages</a></li> | ||
<li><a href="#">There is a max length of this many</a></li> | ||
</ul> |
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
14 changes: 10 additions & 4 deletions
14
.../templates/wagtailflags/flags/delete.html → .../wagtailflags/flags/delete_condition.html
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 |
---|---|---|
@@ -1,16 +1,22 @@ | ||
{% extends "wagtailadmin/base.html" %} | ||
{% load i18n %} | ||
{% load i18n feature_flags %} | ||
{% block titletag %}{% trans "Delete" as delete_str %}: {{ flag_id }}{% endblock %} | ||
|
||
{% block content %} | ||
{% trans "Delete flag condition:" as delete_str %} | ||
{% include "wagtailadmin/shared/header.html" with title=delete_str subtitle=state_str %} | ||
{% include "wagtailadmin/shared/header.html" with title=delete_str subtitle=condition_str %} | ||
{% flag_enabled 'WAGTAILFLAGS_ADMIN_BIG_LIST' as big_list_flag %} | ||
|
||
<form class="nice-padding" method="POST" action="{% url 'wagtailflags:delete' state_id %}"> | ||
<form class="nice-padding" method="POST" action="{% url 'wagtailflags:delete_condition' flag.name condition_pk %}"> | ||
{% csrf_token %} | ||
|
||
<p>Are you sure you want to delete this flag condition?</p> | ||
<input type="submit" value="Yes, delete it" class="button serious"> | ||
<a href="{% url 'wagtailflags:list' %}" class="button button-secondary">No, don't delete it</a> | ||
|
||
{% if big_list_flag %} | ||
<a href="{% url 'wagtailflags:list' %}#{{ flag.name }}" class="button button-secondary">No, don't delete it</a> | ||
{% else %} | ||
<a href="{% url 'wagtailflags:flag_index' flag.name %}" class="button button-secondary">No, don't delete it</a> | ||
{% endif %} | ||
</form> | ||
{% endblock %} |
49 changes: 49 additions & 0 deletions
49
wagtailflags/templates/wagtailflags/flags/edit_condition.html
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,49 @@ | ||
{% extends "wagtailadmin/base.html" %} | ||
{% load i18n feature_flags %} | ||
{% block titletag %}{% if form.instance %}Edit {{ form.instance.condition }}{% else %}Create condition{% endif %}{% endblock %} | ||
|
||
{% block content %} | ||
{% include "wagtailadmin/shared/header.html" with title=flag.name icon="tag" %} | ||
{% flag_enabled 'WAGTAILFLAGS_ADMIN_BIG_LIST' as big_list_flag %} | ||
|
||
<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 %} | ||
<form class="nice-padding" method="POST" action="{% url 'wagtailflags:create_condition' flag.name %}"> | ||
{% endif %} | ||
{% csrf_token %} | ||
<ul class="fields"> | ||
<li class="actions"> | ||
{% for field in form %} | ||
{% if field.errors %} | ||
<div class="help-block help-critical" style="margin-top:0;"> | ||
{{ field.errors }} | ||
</div> | ||
{% endif %} | ||
<label>{{ field.label }}</label> | ||
<div class="field-content"> | ||
<div class="input"> | ||
{{ field }} | ||
<span></span> | ||
</div> | ||
<p class="help"></p> | ||
</div> | ||
{% endfor %} | ||
</li> | ||
<li class="actions"> | ||
<input class="button action-save button-longrunning" type="submit" value="Save condition" /> | ||
{% if big_list_flag %} | ||
<a class="button bicolor icon icon-cog" href="{% url 'wagtailflags:list' %}#{{ flag.name }}">Back to {{ flag.name }}</a> | ||
{% else %} | ||
<a class="button bicolor icon icon-cog" href="{% url 'wagtailflags:flag_index' flag.name %}">Back to {{ flag.name }}</a> | ||
{% endif %} | ||
</li> | ||
</ul> | ||
</form> | ||
{% endblock %} |
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,13 @@ | ||
{% extends "wagtailadmin/base.html" %} | ||
{% load i18n %} | ||
{% block titletag %}{% trans "Flags" %}: {{ flag.name }}{% endblock %} | ||
|
||
{% block content %} | ||
{% include "wagtailflags/includes/header.html" with title=flag.name icon="tag" %} | ||
|
||
<div class="nice-padding"> | ||
|
||
{% include "wagtailflags/includes/flag_index.html" with flag=flag %} | ||
|
||
</div> | ||
{% endblock %} |
63 changes: 63 additions & 0 deletions
63
wagtailflags/templates/wagtailflags/includes/flag_index.html
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,63 @@ | ||
{% load i18n %} | ||
{% load wagtailflags_admin %} | ||
{% load i18n feature_flags flags_debug wagtailflags_admin %} | ||
|
||
<section class="flag" id="{{ flag.name }}"> | ||
<div class="help-block help-info"> | ||
<p>{{ flag|state_str }}</p> | ||
</div> | ||
|
||
{% with flag|conditions_without_bool as conditions %} | ||
{% if conditions|length > 0 %} | ||
<table class="listing"> | ||
<thead> | ||
<tr> | ||
<th>Condition</th> | ||
<th>Value</th> | ||
<th></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{% for condition in conditions %} | ||
<tr> | ||
<td> | ||
<b>{{ condition.condition }}</b> | ||
</td> | ||
<td> | ||
{{ condition.value }} | ||
</td> | ||
<td> | ||
{% if condition.required %} | ||
Required | ||
{% else %} | ||
Optional | ||
{% endif %} | ||
</td> | ||
<td> | ||
{% if condition.obj %} | ||
<div class="button-group"> | ||
<a href="{% url 'wagtailflags:edit_condition' flag.name condition.obj.pk %}" class="button button-small button-secondary">Edit</a> | ||
<a href="{% url 'wagtailflags:delete_condition' flag.name condition.obj.pk %}" class="button button-small no">Delete</a> | ||
</div> | ||
{% endif %} | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% endif %} | ||
{% endwith %} | ||
|
||
{% if flag|enablable or flag|disablable %} | ||
<a href="{% url 'wagtailflags:flag_index' flag.name %}?{% if flag|bool_enabled %}disable{% else %}enable{% endif %}" | ||
class="button button-secondary{% if flag|bool_enabled %} no{% endif %}"> | ||
{% if flag|bool_enabled %}Disable{% else %}Enable{% endif %} {{ flag.name }} | ||
{% if flag|required_conditions_without_bool|length > 0 %} | ||
when required conditions are met | ||
{% else %} | ||
for all requests | ||
{% endif %} | ||
</a> | ||
{% endif %} | ||
<a href="{% url 'wagtailflags:create_condition' flag.name %}" class="button bicolor icon icon-plus">Add a condition</a> | ||
</section> |
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,9 @@ | ||
{% if flag %} | ||
<ul class="breadcrumb flags-breadcrumb"> | ||
<li><a href="{% url 'wagtailflags:list' %}">Flags</a></li> | ||
<li>{{ title }}</li> | ||
</ul> | ||
{% include "wagtailadmin/shared/header.html" with title=title icon=icon %} | ||
{% else %} | ||
{% include "wagtailadmin/shared/header.html" with title=title icon=icon add_text='Add flag' add_link='wagtailflags:create_flag' %} | ||
{% endif %} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this load wagtailflags_admin twice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed so.