Skip to content

Commit

Permalink
Merge pull request #32 from cfpb/support-flag-sources
Browse files Browse the repository at this point in the history
Add support for django-flags source API changes
  • Loading branch information
willbarton committed Oct 26, 2018
2 parents 7cf2203 + 47834f5 commit 4e152c5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 91 deletions.
43 changes: 18 additions & 25 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,30 @@
language: python
cache: pip

matrix:
include:
- env: TOXENV=lint
python: 3.6
- env: TOXENV=py27-dj18-wag113
python: 2.7
- env: TOXENV=py27-dj111-wag113
python: 2.7
- env: TOXENV=py36-dj18-wag113
python: 3.6
- env: TOXENV=py36-dj111-wag113
python: 3.6
- env: TOXENV=py36-dj20-wag20
python: 3.6

install:
pip install tox coveralls

script:
tox

after_success:
coveralls

- env: TOXENV=lint
python: 3.6
- env: TOXENV=py27-dj111-wag113
python: 2.7
- env: TOXENV=py36-dj111-wag113
python: 3.6
- env: TOXENV=py36-dj111-wag22
python: 3.6
- env: TOXENV=py36-dj21-wag22
python: 3.6
- env: TOXENV=py36-dj21-wag23
python: 3.6
install: pip install tox coveralls
script: tox
after_success: coveralls
deploy:
matrix:
- provider: pypi
skip-cleanup: true
distributions: "sdist bdist_wheel --universal"
distributions: sdist bdist_wheel --universal
user: cfpb
password:
secure: "RQmVt7ulZ1qTr5xycobPguA6ctKfqdDaNEtjEdjgelk74g+N9lSMjGssEX0anqn3pQT0DTquby+Xb0C/MRhuWeNSTa61LESGKZ4nT02VAHsmEcmgxpcGbhtf/zvu4fztHNocF2ffSpsyq0n0YpJoT5N2znlw5sPX/aHNd+2m2tkiQu6yqUFR5PWcLDcz4KJNmyDk0miUTRHucS0yFanBsYjVCBzEWAWtnAxq5DCOW78dHOncfTCeAsMpjT/eVHOLldk9giEvBs/OJgWjFq8c/sVt3owCKhgkwbA1htXFGxofo9gl+m72cop3GEmUlOoTOMOs1AFTTMQQchyXqoLvDglRcBfOp+UhzCjEmckr7bKECa+Ok+8IeO7qyCR5Z1PsvMa5Vf12ZyEOsYs5QivQuA8tTKdB9Pni3rb/f0EqTLoWGb2Lg/WhP4GRSGxOC2SM4jJTEoi6bgzV3bvg1YIAPZIuK1whHPlo6EA1NzEOO/57iFw2G3R14Kw1B5QMXXLdKXulPc/FYRCcygqEkHl8nIe8FexeGEpJeC8URx+Gy9F0YxBL6Aqu3Jk09yhfyHTBbBaRCodfAUzt1/Ula3tOzYlIObxZhZnxNEETa3xY8lZWchXf4FEXleqsM1dGHprG1+dwBJwt1szTphd+kqc5I6/uuv1iVFOh4JAcCethG9s="
secure: "lxk9H3MNy6TWQX7loi0zu5DWRM2LZEaDwD8y3+PeJAidzwesv8axGheTAy/bBDq7uIi1CwIWd83m1ck4xY9e0hPTzfuG2T/SpNvQ+kP+65fYVXKyPROn0KemE5fh+gpskM7ilmar68luVGfG+ZhnCuYFm5KZpRa5U1V5qUbBQrhSo7IThUWMD/f3n7poip11jpXgTZSyy4YpCPo04bT9KUMigCpY3HLeg3E3wZ0EdrlJIYzqUQLAmwp/LjHWGwSIbJxdTevO7jPHLVEu/qychKpm5r09/PYkaBjvNfwk2cGTE22GCsqUx7Ox9mvcu9ASXrlVeSTG1DmmuaufeeyUjW5UHjRSSpC5gj45ftYnW0KIn0Qiji10d7A8gKVD2/26IkbV/JkuNn+7p0ARKx7k2y6elUS8RUC7zGiT5UoqxRCbkXkGSZv0BZjQ0JoKaLv6o6V8E+Wo9X9PYRBMMttAzQtuJ+m7jvw3V8ZVB6MeXZWUL5pclj1MgiA29cAZRBLRZKb1D7eYYL460zOECj28UeoBQn/RNocQfKCoU+0M08P4xo86P9n1w8DRMWVtHJf9wDK/SVEQAKV6UXTO+rswMquHPTyXcSr2ebRMmFygTxAjdSJ9l3/T/iPIYpV1HsfuPP95MKIBbKh8W2KGYOAvTilfEtEINo7fE0EeIV8TPHE="
on:
tags: true
condition: $TOXENV = "py36-dj111-wag113"
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

install_requires = [
'wagtail>=1.10,<2.3',
'django-flags>=3.0,<4.0'
'django-flags>=4.0,<5.0'
]

testing_extras = [
Expand All @@ -21,7 +21,7 @@
long_description=long_description,
long_description_content_type='text/markdown',
license='CC0',
version='3.0.1',
version='4.0.0',
include_package_data=True,
packages=find_packages(),
install_requires=install_requires,
Expand Down
7 changes: 2 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
skipsdist=True
envlist=lint,py{27,36}-dj{18,111}-wag{113},py{36}-dj{20,21}-wag{20,21,22}
envlist=lint,py{27,36}-dj{111}-wag{113},py{36}-dj{111}-wag{22},py{36}-dj{21}-wag{22,23}

[testenv]
install_command=pip install -e ".[testing]" -U {opts} {packages}
Expand All @@ -16,14 +16,11 @@ basepython=
py36: python3.6

deps=
dj18: Django>=1.8,<1.9
dj111: Django>=1.11,<1.12
dj20: Django>=2.0,<2.1
dj21: Django>=2.1,<2.2
wag113: wagtail>=1.13,<1.14
wag20: wagtail>=2.0,<2.1
wag21: wagtail>=2.1,<2.2
wag22: wagtail>=2.2,<2.3
wag23: wagtail>=2.3,<2.4

[testenv:lint]
basepython=python3.6
Expand Down
55 changes: 7 additions & 48 deletions wagtailflags/templates/wagtailflags/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% if flags|length == 0 %}
<p>No flags have been defined.</p>
{% else %}
<h2>Available Flags</h2>
<h2>Flags</h2>

<table class="listing">
<thead>
Expand All @@ -25,8 +25,8 @@ <h2>Available Flags</h2>
</tr>
</thead>
<tbody>
{% for flag in flags.values %}
{% for condition, fn, value, state in flag.conditions %}
{% for name, flag in flags.items %}
{% for condition in flag.conditions %}
<tr>
{% if forloop.first %}
<td rowspan="{{ flag.conditions|length }}">
Expand All @@ -35,15 +35,15 @@ <h2>Available Flags</h2>
{% endif %}
<td>is enabled when</td>
<td>
<b>{{ condition }}</b>
<b>{{ condition.condition }}</b>
</td>
<td>is</td>
<td>
<b>{{ value }}</b>
<b>{{ condition.value }}</b>
</td>
<td>
{% if state %}
<a href="{% url 'wagtailflags:delete' state.pk %}" class="button icon text-replace hover-no icon-bin">Delete</a>
{% if condition.obj %}
<a href="{% url 'wagtailflags:delete' condition.obj.pk %}" class="button icon text-replace hover-no icon-bin">Delete</a>
{% endif %}
</td>
</tr>
Expand All @@ -61,47 +61,6 @@ <h2>Available Flags</h2>

<a href="{% url 'wagtailflags:create' %}" class="button bicolor icon icon-plus">Add a condition</a>


<h2>Unconfigured flags</h2>
<p>Conditions exist for these flags but they are not configured.</p>

<table class="listing">
<thead>
<tr>
<th>Name</th>
<th></th>
<th>Condition</th>
<th></th>
<th>Value</th>
<th></th>
</tr>
</thead>
<tbody>
{% for state in flag_states %}
{% if state.name not in flags.keys %}
<tr>
<td>
<b>{{ state.name }}</b>
<span title="flag not configured" style="color: #e9b04d; font-family: wagtail;">!</span>
</td>
<td>is enabled when</td>
<td>
<b>{{ state.condition }}</b>
</td>
<td>is</td>
<td>
<b>{{ state.value }}</b>
</td>
<td>
<a href="{% url 'wagtailflags:delete' state.pk %}" class="button icon text-replace hover-no icon-bin">Delete</a>
</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>


{% endif %}
</div>

Expand Down
10 changes: 3 additions & 7 deletions wagtailflags/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def setUp(self):
self.login()

def test_flags_index(self):
self.orphaned_flag = FlagState.objects.create(
name='ORPHANED_FLAG',
self.dbonly_flag = FlagState.objects.create(
name='DBONLY_FLAG',
condition='boolean',
value='True'
)
Expand All @@ -27,11 +27,7 @@ def test_flags_index(self):
self.assertContains(response, 'is never enabled')

self.assertIn(
self.orphaned_flag,
response.context['flag_states']
)
self.assertNotIn(
self.orphaned_flag.name,
self.dbonly_flag.name,
response.context['flags']
)

Expand Down
6 changes: 2 additions & 4 deletions wagtailflags/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

from flags.forms import FlagStateForm
from flags.models import FlagState
from flags.settings import get_flags
from flags.sources import get_flags


def index(request):
flags = OrderedDict(sorted(get_flags().items(), key=lambda x: x[0]))
context = {
'flag_states': FlagState.objects.order_by('name'),
'flags': flags,
'flags': OrderedDict(sorted(get_flags().items(), key=lambda x: x[0])),
}
return render(request, 'wagtailflags/index.html', context)

Expand Down

0 comments on commit 4e152c5

Please sign in to comment.