Skip to content

Commit

Permalink
Merge pull request #8 from edx/dcs/add-flag
Browse files Browse the repository at this point in the history
Added waffle flag(s) to selectively enable edx-when
  • Loading branch information
Dave St.Germain authored Apr 24, 2019
2 parents 7bcb609 + df589c9 commit b9303e4
Show file tree
Hide file tree
Showing 16 changed files with 115 additions and 72 deletions.
7 changes: 7 additions & 0 deletions .annotation_safe_list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ auth.User:
".. pii_retirement:" : consumer_api
contenttypes.ContentType:
".. no_pii:": "This model has no PII"
# Via waffle
waffle.Flag:
".. no_pii:": "No PII"
waffle.Sample:
".. no_pii:": "No PII"
waffle.Switch:
".. no_pii:": "No PII"
2 changes: 1 addition & 1 deletion edx_when/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

from __future__ import absolute_import, unicode_literals

__version__ = '0.1.1'
__version__ = '0.1.2'

default_app_config = 'edx_when.apps.EdxWhenConfig' # pylint: disable=invalid-name
20 changes: 20 additions & 0 deletions edx_when/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import logging

import crum
import six
import waffle
from django.core.exceptions import ValidationError
from django.utils.dateparse import parse_datetime
from edx_django_utils.cache.utils import DEFAULT_REQUEST_CACHE
Expand All @@ -24,6 +26,24 @@ def _ensure_key(key_class, key_obj):
return key_obj


def is_enabled_for_course(course_key, request=None):
"""
Return whether edx-when is enabled for this course.
"""
request = request or crum.get_current_request()
if not waffle.flag_is_active(request, 'edx-when-enabled'):
return waffle.flag_is_active(request, 'edx-when:{}'.format(course_key))
return True


def override_enabled():
"""
Return decorator that enables edx-when.
"""
from waffle.testutils import override_flag
return override_flag('edx-when-enabled', active=True)


def set_dates_for_course(course_key, items):
"""
Extract dates from blocks.
Expand Down
8 changes: 6 additions & 2 deletions edx_when/field_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@ def __init__(self, defaults, course_id=None, user=None, use_cached=True):
self._load_dates(course_id, user, use_cached=use_cached)

def _load_dates(self, course_id, user, use_cached=True):
"""
Load the dates from the database.
"""
dates = {}
for (location, field), date in api.get_dates_for_course(course_id, user, use_cached=use_cached).items():
dates[text_type(location), field] = date
if api.is_enabled_for_course(course_id):
for (location, field), date in api.get_dates_for_course(course_id, user, use_cached=use_cached).items():
dates[text_type(location), field] = date
self._course_dates = dates

def has(self, block, name):
Expand Down
2 changes: 2 additions & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ django-model-utils # Provides TimeStampedModel abstract base class
edx-opaque-keys
edx-drf-extensions
xblock
django-waffle
django-crum
11 changes: 6 additions & 5 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ appdirs==1.4.3 # via fs
backports.os==0.1.1 # via fs
certifi==2019.3.9 # via requests
chardet==3.0.4 # via requests
django-crum==0.7.3
django-model-utils==3.1.2
django-waffle==0.16.0 # via edx-django-utils, edx-drf-extensions
django-waffle==0.16.0
django==1.11.20
djangorestframework-jwt==1.11.0 # via edx-drf-extensions
djangorestframework==3.9.2 # via edx-drf-extensions, rest-condition
Expand All @@ -22,23 +23,23 @@ future==0.17.1 # via backports.os, pyjwkest
idna==2.8 # via requests
lxml==4.3.3 # via xblock
markupsafe==1.1.1 # via xblock
newrelic==4.16.1.117 # via edx-django-utils
newrelic==4.18.0.118 # via edx-django-utils
pbr==5.1.3 # via stevedore
psutil==1.2.1 # via edx-django-utils, edx-drf-extensions
pycryptodomex==3.8.1 # via pyjwkest
pyjwkest==1.3.2 # via edx-drf-extensions
pyjwt==1.7.1 # via djangorestframework-jwt
pymongo==3.7.2 # via edx-opaque-keys
pymongo==3.8.0 # via edx-opaque-keys
python-dateutil==2.8.0 # via edx-drf-extensions, xblock
pytz==2018.9 # via django, fs, xblock
pytz==2019.1 # via django, fs, xblock
pyyaml==5.1 # via xblock
requests==2.21.0 # via edx-drf-extensions, pyjwkest
rest-condition==1.0.3 # via edx-drf-extensions
semantic-version==2.6.0 # via edx-drf-extensions
six==1.12.0 # via edx-drf-extensions, edx-opaque-keys, fs, pyjwkest, python-dateutil, stevedore, xblock
stevedore==1.30.1 # via edx-opaque-keys
typing==3.6.6 # via fs
urllib3==1.24.1 # via requests
urllib3==1.24.2 # via requests
web-fragments==0.3.0 # via xblock
webob==1.8.5 # via xblock
xblock==1.2.2
1 change: 1 addition & 0 deletions requirements/dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

diff-cover # Changeset diff test coverage
edx-i18n-tools # For i18n_tool dummy
path.py==11.5.0
50 changes: 26 additions & 24 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,56 @@ backports.os==0.1.1
caniusepython3==7.0.0
certifi==2019.3.9
chardet==3.0.4
click-log==0.1.8
click-log==0.3.2
click==7.0
code-annotations==0.3
code-annotations==0.3.1
codecov==2.0.15
configparser==3.7.3
configparser==3.7.4
contextlib2==0.5.5 # via importlib-metadata
coverage==4.5.3
diff-cover==1.0.7
diff-cover==2.0.0
distlib==0.2.8
django-crum==0.7.3
django-model-utils==3.1.2
django-waffle==0.15.1
django-waffle==0.16.0
django==1.11.20
djangorestframework-jwt==1.11.0
djangorestframework==3.9.2
edx-django-utils==1.0.3
edx-drf-extensions==2.1.0
edx-drf-extensions==2.2.0
edx-i18n-tools==0.4.8
edx-lint==1.1.1
edx-lint==1.1.2
edx-opaque-keys==0.4.4
enum34==1.1.6
filelock==3.0.10
fs==2.4.4
funcsigs==1.0.2
future==0.17.1
futures==3.2.0
futures==3.2.0 ; python_version <= "3"
idna==2.8
importlib-metadata==0.8 # via path.py
importlib-metadata==0.9 # via path.py
inflect==2.1.0 # via jinja2-pluralize
isort==4.3.15
isort==4.3.17
jinja2-pluralize==0.3.0 # via diff-cover
jinja2==2.10
jinja2==2.10.1
lazy-object-proxy==1.3.1
lxml==4.3.2
lxml==4.3.3
markupsafe==1.1.1
mccabe==0.6.1
mock==2.0.0
more-itertools==5.0.0
newrelic==4.14.0.115
newrelic==4.18.0.118
packaging==19.0
path.py==11.5.0 # via edx-i18n-tools
path.py==11.5.0
pathlib2==2.3.3
pbr==5.1.3
pip-tools==3.5.0
pip-tools==3.6.1
pluggy==0.9.0
polib==1.1.0 # via edx-i18n-tools
psutil==1.2.1
py==1.8.0
pycodestyle==2.5.0
pycryptodomex==3.7.3
pycryptodomex==3.8.1
pydocstyle==3.0.0
pygments==2.3.1 # via diff-cover
pyjwkest==1.3.2
Expand All @@ -70,14 +72,14 @@ pylint-celery==0.3
pylint-django==0.7.2
pylint-plugin-utils==0.5
pylint==1.7.6
pymongo==3.7.2
pyparsing==2.3.1
pymongo==3.8.0
pyparsing==2.4.0
pytest-cov==2.6.1
pytest-django==3.4.8
pytest==4.3.1
pytest==4.4.1
python-dateutil==2.8.0
python-slugify==3.0.0
pytz==2018.9
python-slugify==3.0.2
pytz==2019.1
pyyaml==5.1
requests==2.21.0
rest-condition==1.0.3
Expand All @@ -90,10 +92,10 @@ stevedore==1.30.1
text-unidecode==1.2
toml==0.10.0
tox-battery==0.5.1
tox==3.7.0
tox==3.9.0
typing==3.6.6
urllib3==1.24.1
virtualenv==16.4.3
urllib3==1.24.2
virtualenv==16.5.0
web-fragments==0.3.0
webob==1.8.5
wrapt==1.11.1
Expand Down
2 changes: 1 addition & 1 deletion requirements/doc.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
doc8 # reStructuredText style checker
edx_sphinx_theme # edX theme for Sphinx output
readme_renderer # Validates README.rst for usage on PyPI
Sphinx # Documentation builder
sphinx==1.8.5 # Documentation builder
30 changes: 16 additions & 14 deletions requirements/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ bleach==3.1.0 # via readme-renderer
certifi==2019.3.9
chardet==3.0.4
click==7.0
code-annotations==0.3
code-annotations==0.3.1
coverage==4.5.3
django-crum==0.7.3
django-model-utils==3.1.2
django-waffle==0.15.1
django-waffle==0.16.0
django==1.11.20
djangorestframework-jwt==1.11.0
djangorestframework==3.9.2
doc8==0.8.0
docutils==0.14 # via doc8, readme-renderer, restructuredtext-lint, sphinx
edx-django-utils==1.0.3
edx-drf-extensions==2.1.0
edx-drf-extensions==2.2.0
edx-opaque-keys==0.4.4
edx-sphinx-theme==1.4.0
enum34==1.1.6
Expand All @@ -33,34 +34,35 @@ funcsigs==1.0.2
future==0.17.1
idna==2.8
imagesize==1.1.0 # via sphinx
jinja2==2.10
lxml==4.3.2
jinja2==2.10.1
lxml==4.3.3
markupsafe==1.1.1
mock==2.0.0
more-itertools==5.0.0
newrelic==4.14.0.115
newrelic==4.18.0.118
packaging==19.0 # via sphinx
pathlib2==2.3.3
pbr==5.1.3
pluggy==0.9.0
psutil==1.2.1
py==1.8.0
pycryptodomex==3.7.3
pycryptodomex==3.8.1
pygments==2.3.1 # via readme-renderer, sphinx
pyjwkest==1.3.2
pyjwt==1.7.1
pymongo==3.7.2
pyparsing==2.3.1 # via packaging
pymongo==3.8.0
pyparsing==2.4.0 # via packaging
pytest-cov==2.6.1
pytest-django==3.4.8
pytest==4.3.1
pytest==4.4.1
python-dateutil==2.8.0
python-slugify==3.0.0
pytz==2018.9
python-slugify==3.0.2
pytz==2019.1
pyyaml==5.1
readme-renderer==24.0
requests==2.21.0
rest-condition==1.0.3
restructuredtext-lint==1.2.2 # via doc8
restructuredtext-lint==1.3.0 # via doc8
scandir==1.10.0
semantic-version==2.6.0
six==1.12.0
Expand All @@ -70,7 +72,7 @@ sphinxcontrib-websupport==1.1.0 # via sphinx
stevedore==1.30.1
text-unidecode==1.2
typing==3.6.6
urllib3==1.24.1
urllib3==1.24.2
web-fragments==0.3.0
webencodings==0.5.1 # via bleach
webob==1.8.5
Expand Down
2 changes: 1 addition & 1 deletion requirements/pip-tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
# make upgrade
#
click==7.0 # via pip-tools
pip-tools==3.6.0
pip-tools==3.6.1
six==1.12.0 # via pip-tools
Loading

0 comments on commit b9303e4

Please sign in to comment.