def list(self, owner=None, channel=None, cid=None, key=None): """ 权限列表 """ kwargs = {} if owner: kwargs["owner"] = owner if channel: kwargs["channel"] = channel if cid: kwargs["cid"] = cid if key and (key in PERM_CLASS.keys()): kwargs["value"] = PERM_CLASS[key] r = self.find(**kwargs) if r[0]: return self._output(result=r[1]) else: return None
def query(self, owner=None, channel=None, cid=None, key=None, limit=None, order_by="added_id", order=-1): """ 显示别表 """ kwargs = {} if owner: kwargs["owner"] = owner if channel: kwargs["channel"] = channel if cid: kwargs["cid"] = cid if key and (key in PERM_CLASS.keys()): kwargs["value"] = PERM_CLASS[key] kwargs["limit"] = limit kwargs["order_by"] = order_by kwargs["order"] = order r = super(PermissionAPI, self).find(**kwargs) if r[0]: kw = {"result": r[1]} l = self._output(**kw) return (True, l) else: return (False, r[1])
def page(self, cuid=DEFAULT_CUR_UID, owner=None, perm=None, created=None, name=None, prop=None, maintype=None, subtype=None, live=None, agency=None, tags=[], grade=None, nexus=None, male=None, born_tuple=None, page=1, pglen=5, limit=20, order_by='added_id', order=-1): ''' 分页显示作品集 ''' kwargs = {} pmlist = [PERM_CLASS['SUPEROR'], PERM_CLASS['MANAGER']] if isinstance(perm, tuple):perm = [perm] if subtype: mtype_l = ['FASHION', 'ART', 'DESIGN', 'HUMAN', 'BRAND'] subkey = _get_mtype(subtype) pmlist.append(PERM_CLASS.get(subkey, '')) if perm and owner: for p in perm: if p in pmlist: owner=None break if owner:kwargs['owner']=owner if subtype in mtype_l: kwargs['maintype']=subtype elif subtype == 'PHOTOGRAPHER': kwargs['subtype']={'$in': [u'FPHOTOGRAPHER', u'HPHOTOGRAPHER']} elif subtype == 'INSTITUTIONS': kwargs['subtype']={'$in': [u'FINSTITUTIONS', u'AINSTITUTION', u'DINSTITUTION']} elif subtype == 'ASSOCIATION': kwargs['subtype']={'$in': [u'FASSOCIATION', u'AASSOCIATION', u'HASSOCIATION', u'DASSOCIATION']} elif subtype == 'MAGAZINE': kwargs['subtype']={'$in': [u'FMAGAZINE', u'HMAGAZINE']} elif subtype == 'MUSEUM': kwargs['subtype']={'$in': [u'FMUSEUM', u'AMUSEUM', u'DMUSEUM', u'HMUSEUM', u'BMUSEUM']} else: kwargs['subtype']=subtype elif perm is not None: flag = False mtypelist = [] for p in perm: pmlist.extend([PERM_CLASS['PROJECTOR'], PERM_CLASS['RELATION']]) if p not in pmlist: flag = True mtypelist.append(_get_perm_key(p)) if flag: kwargs['maintype'] = {'$in':mtypelist} if created:kwargs.update(self._deal_created(created)) if name:kwargs['name']=re.compile('.*'+name+'.*') if prop: prop_list = [u'PERSONAL', u'ORGANIZATION', u'SHOW'] if isinstance(prop, list) and set(prop).issubset(set(prop_list)): kwargs['prop']={'$all':prop} elif prop.upper() in prop_list: kwargs['prop']=prop if live and (live!='0x00'):kwargs['live']=re.compile('^'+live+'\w{0,2}$') if agency:kwargs['agency']=agency if grade and int(grade):kwargs['grade']=int(grade) if nexus and int(nexus):kwargs['nexus']=int(nexus) if male in ['male', 'female']: kwargs['prop']=u'PERSONAL' kwargs['male']=(male==u'male') if born_tuple: sd, ed = born_tuple sd = 1900+int(sd) ed = 1900+int(ed) start_d = datetime(year=sd, month=1, day=1) end_d = datetime(year=ed, month=1, day=1) if ed == 1900: kwargs['born']={'$gt': start_d} else: kwargs['born']={'$gt': start_d, '$lt': end_d} if not created and not subtype and not prop and not name and not live and not grade and not nexus and not male and not born_tuple: kwargs = {'$or':[{'owner':owner}, kwargs]} kwargs['page']=page kwargs['pglen']=pglen kwargs['limit']=limit kwargs['order_by']=order_by kwargs['order']=order r = super(VolumeAPI, self).page(**kwargs) if r[0]: kw = {'result':r[1]} if cuid:kw['cuid']=cuid l = self._output(**kw) return (True, l, r[2]) else: return (False, r[1])
def _get_perm_key(value): for k, v in PERM_CLASS.items(): if value == v: return k return None
def award(self, owner, channel, key, cid=None, **kwargs): """ 授权 """ if key not in PERM_CLASS.keys(): return (False, "beyond key") value = unicode(key) return super(PermissionAPI, self).create(owner=owner, channel=channel, cid=cid, value=value, **kwargs)