Finish permissin detail asset list and user list

This commit is contained in:
ibuler
2016-09-14 23:29:39 +08:00
parent 5bca783e12
commit a4dc27f073
6 changed files with 119 additions and 48 deletions

View File

@@ -1,3 +1,18 @@
# Common app
Common app provide common view, function or others.
Common app shouldn't rely on other apps, because It may lead to cycle
import.
If your want to implement some function or class, you should think
whether other app use or not. If yes, You should make in common.
If the ability more relate to your app tightness, It's mean your app
provide this ability, not common, You should write it on your app utils.
## Celery usage

View File

@@ -2,6 +2,7 @@
#
from __future__ import unicode_literals
from six import string_types
from itertools import chain
import string
@@ -52,30 +53,43 @@ def combine_seq(s1, s2, callback=None):
seq = chain(s1, s2)
if callback:
seq = map(callback, seq)
return seq
def search_object_attr(obj, value='', attr_list=None, ignore_case=False):
"""It's provide a method to search a object attribute equal some value
If object some attribute equal :param: value, return True else return False
class A():
name = 'admin'
age = 7
:param obj: A object
:param value: A string match object attribute
:param attr_list: Only match attribute in attr_list
:param ignore_case: Ignore case
:return: Boolean
"""
if value == '':
return True
try:
object_attr = obj.__dict__
except AttributeError:
return False
if not isinstance(value, str):
return False
if value == '':
return True
if attr_list is not None:
new_object_attr = {}
for attr in attr_list:
object_attr.pop(attr)
new_object_attr[attr] = object_attr.pop(attr)
object_attr = new_object_attr
print(value)
print(object_attr)
if ignore_case:
if value.lower() in map(string.lower, filter(lambda x: isinstance(x, (str, unicode)), object_attr.values())):
if not isinstance(value, string_types):
return False
if value.lower() in map(string.lower, map(str, object_attr.values())):
return True
else:
if value in object_attr.values():