Skip to content

Instantly share code, notes, and snippets.

@mcihad
Last active August 29, 2015 14:04
Show Gist options
  • Save mcihad/0f1dac3c95ca3753abd7 to your computer and use it in GitHub Desktop.
Save mcihad/0f1dac3c95ca3753abd7 to your computer and use it in GitHub Desktop.
Decorator Python
"""
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