Last active
August 29, 2015 14:04
-
-
Save mcihad/0f1dac3c95ca3753abd7 to your computer and use it in GitHub Desktop.
Decorator Python
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
""" | |
django view içerisinde kullanmak için | |
f fonksiyonu ilk parametresi request | |
kullanıcının applikasyon yetkisi kontrol edilebilir | |
""" | |
from functools import wraps | |
def apps_required(appname): | |
def _decorator(f): | |
@wraps(f) | |
def wrapper(*args,**kwargs): | |
if appname=="blog": | |
print "Blog uygulamasi izinli" | |
return f(*args,**kwargs) | |
else: | |
print "Sadece Blog izinli" | |
return wrapper | |
return _decorator | |
@apps_required("blog") | |
def blog1(): | |
print "Selamlar blog1" | |
@apps_required("crm") | |
def blog2(): | |
print "Selamlar blog2" | |
if __name__=="__main__": | |
blog1() | |
blog2() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment