A private beta app for Django 1.10+ and Python 3.5+.
He who answers the five questions--three questions--may cross in safety.
Any "traveler" who "answers the questions" may pass BridgekeeperMiddleware
and "cross in safety" to the beta views.
Questions are pluggable via BRIDGEKEEPER_QUESTIONS
setting.
Unlike other private beta apps, immediate user sign up is not required. With
default BRIDGEKEEPER_QUESTIONS
an invited AnonymousUser
may browse the
beta views before--or without ever--signing up as long as their Invite
is
valid.
During soft release of django-bridgekeeper, install directly from git repo:
$ pip install git+https://github.com/brettstil/django-bridgekeeper.git#egg=django-bridgekeeper
Add to INSTALLED_APPS
:
INSTALLED_APPS = [
# ...
'bridgekeeper.apps.BridgekeeperConfig',
]
Add BridgekeeperMiddleware
to MIDDLEWARE
settings after Django's authentication middleware:
MIDDDLEWARE = [
# ...
'django.contrib.auth.middleware.AuthenticationMiddleware',
'bridgekeeper.middleware.BridgekeeperMiddleware',
]
For default valid_invite
question, add bridgekeeper urls to root urls:
urlpatterns = [
# ...
url(r'^bridgekeeper/', include(
'bridgekeeper.urls', namespace='bridgekeeper')),
]
Configure settings, especially redirect urls and allowed modules and views.
Just like the Monty Python sketch, BridgekeeperMiddleware
asks a list of
questions to determine whether the traveler may pass.
Questions are defined in BRIDGEKEEPER_QUESTIONS
setting.
Each question has three possible results:
return True
for explicit yes, traveler may pass.BridgekeeperMiddleware.process_view
returns immedateNone
and skips remaining questions inBRIDGEKEEPER_QUESTIONS
.For example, in default question
enable
explicit yes is returned ifBRIDGEKEEPER_ENABLE
setting isFalse
.return False
for explicit no, traveler may not pass and traveler cast into the gorge.BridgekeeperMiddleware.process_view
returns immediateHttpResponseRedirect
toBRIDGEKEEPER_URL_GORGE
and skips remaining questions inBRIDGEKEEPER_QUESTIONS
.For example, in default question
valid_invite
explicit no is returned if an existing invite code is expired. Remember, order ofBRIDGEKEEPER_QUESTIONS
is important!return None
, or justreturn
, for no opinion.BridgekeeperMiddleware
continues to the next question, if any, inBRIDGEKEEPER_QUESTIONS
.If all questions return
None
, thenBridgekeeperMiddleware.process_view
also simply returnsNone
and traveler may pass.
Available settings are:
BRIDGEKEEPER_INVITE_EXPIRED_SECONDS
Default:
None
With default
None
setting, created invite does not expire at predeterminedexpired
datetime.With integer setting, created invite
expired
set totimezone.now()
+ the setting number of seconds.Created invite with manually set
expired
ignores the setting.BRIDGEKEEPER_URL_GORGE
Default:
'/'
Redirect url after a middleware question explicitly casts traveler into gorge.
BRIDGEKEEPER_URL_INVITED_OK
Default:
'/'
Redirect url after traveler successfully visits
'invited'
url and has invite code cookie set.BRIDGEKEEPER_URL_INVITED_INVALID
Default:
'/'
Redirect url after traveler visits
'invited'
url with invalid or expired invite code.BRIDGEKEEPER_COOKIE_NAME
- Default:
'bridgekeeper_invite_code'
BRIDGEKEEPER_QUESTIONS
Default:
['bridgekeeper.middleware.authenticated', 'bridgekeeper.middleware.enable', 'bridgekeeper.middleware.allowed_module', 'bridgekeeper.middleware.allowed_view', 'bridgekeeper.middleware.valid_invite']
Order of questions is important!
BRIDGEKEEPER_ENABLE
Default:
True
Setting for
'bridgekeeper.middleware.enable'
question.Completely disable bridgekeeper with a single setting.
BRIDGEKEEPER_ALLOWED_MODULES
Default:
[]
Setting for
'bridgekeeper.middleware.allowed_module'
question.Always allow views from these modules, for example
'welcome.views'
.These modules are always allowed:
['django.contrib.admin.sites', 'django.contrib.auth.views', 'django.contrib.staticfiles.views', 'django.views.static']
.BRIDGEKEEPER_ALLOWED_VIEWS
Default:
[]
Setting for
'bridgekeeper.middleware.allowed_view'
question.Always allow these views, for example
'landing.views.hello'
.
Inspired by unmaintained https://github.com/pragmaticbadger/django-privatebeta and https://github.com/joshuakarjala/django-hunger