Store Optimizely datafile in a Django model
Project description
dj-optimizely
Store optimizely datafile in a Django model
WORK IN PROGRESS
This app is in the very early stages and I'll be fleshing it out over the coming weeks. Though it is currently in use.
Usage
Settings
INSTALLED_APPS = [
...
'djoptimizely',
...
]
MIDDLEWARE = [
...
'djoptimizely.middleware.optimizely_middleware',
...
]
OPTIMIZELY_ENVIRONMENT = 'staging'
OPTIMIZELY_WEBHOOK_SECRET = os.getenv('OPTIMIZELY_WEBHOOK_SECRET')
OPTIMIZELY_DATAFILE_URL = os.getenv('OPTIMIZELY_DATAFILE_URL')
OPTIMIZELY_USER_ID = 'myapp.module.get_user_id' # Specify a function to get user id (required)
OPTIMIZELY_USER_ATTRIBS = 'myapp.module.get_user_attribs' # Specify a function to get user attribs (optional)
Urls
urlpatterns = [
...
path('webhooks/', include('djoptimizely.urls')),
...
]
Check if a feature should be enabled:
from djoptimizely.services import get_feature_enabled
...
if get_feature_enabled(request, 'cool_stuff'):
print('Cool!')
With a template tag
{% load optimizely_tags %}
...
{% show_feature 'cool_stuff' as show_cool_stuff %}
{% if show_cool_stuff %}
<p>COOL Stuff!</p>
{% endif %}
View mixin: (serve if enabled else 404)
from djoptimizely.mixins import OptimizelyFeatureViewMixin
from django.views.generic.base import TemplateView
class CoolView(OptimizelyFeatureViewMixin, TemplateView):
feature_key = 'cool_stuff'
...
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
dj-optimizely-0.0.2.tar.gz
(6.0 kB
view hashes)
Built Distribution
Close
Hashes for dj_optimizely-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de937a763e58907f947a33a959b191dfe1eccacf38f9b9fa491bf142655091e3 |
|
MD5 | f06a7b7ee76f16ae490ef638cefc6c87 |
|
BLAKE2b-256 | 5207e34ba8cebbecf840b836887d831be92af7c6544d15c6a9aa42b59718bd02 |