Created
May 22, 2012 12:15
-
-
Save sneeu/2768694 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def beta_access(request): | |
if request.method == 'POST': | |
form = BetaCodeForm(request.POST) | |
# form validation handles checking for the beta code | |
if form.is_valid(): | |
request.session['has_beta_access'] = True | |
return redirect('register') | |
else: | |
form = BetaCodeForm(request.POST) | |
return TemplateResponse(request, 'beta_access.html', context={'form': form}) | |
def beta_access_required(view): | |
def f(request, *args, **kwargs): | |
if request.session.get('has_beta_access', None) != True: | |
return redirect('beta_access') | |
return view(request, *args, **kwargs) | |
return f |
Nice, thanks for the rundown. Hopefully I will find an excuse to write some Python in the near future.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@pyrat additionally, in Django if you wanted to do something before saving a model, you overwrite the
save
method, and eventually callsuper
, generally you’re not bothered about whatsave
is called with, so you’d use*args
, and**kwargs
in that instance too.An example: