示例#1
0
def find(rank_id=None,
         expand_number=False,
         sorted_by='rank',
         sort_ascending=True,
         only_one=False):
    """
    Returns a list of ranks or a single rank, if rank_id or only_one are specified.

    rank_id: a single rank identifier (a string or an ObjectId) or a list of them
    expand_number: add an extra field with the number of user for every rank returned
    sorted_by: the field to sort the result with; by default it's the rank field
    sort_ascending: if True, sorts the results from first to last, if False sorts them the other way
    only_one: if True, returns one rank at most

    """
    def denormalize(rank):
        if rank is None:
            return rank
        if expand_number:
            rank['number_user'] = len(model.users.find(rank=rank['rank']))
        return rank

    conditions = []
    return db_engine(item_id=rank_id,
                     collection=db.ranks,
                     conditions=conditions,
                     only_one=only_one,
                     sorted_by=sorted_by,
                     sort_ascending=sort_ascending,
                     denormalize=denormalize)
示例#2
0
def find(file_name=None, only_one=False):
    """
    """
    conditions = []
    if file_name:
        conditions.append({"file": file_name})
    return db_engine(collection=db.js, conditions=conditions, only_one=only_one)
示例#3
0
def find(rank_id=None,
         expand_number=False,
         sorted_by='rank',
         sort_ascending=True,
         only_one=False):
    """
    Returns a list of ranks or a single rank, if rank_id or only_one are specified.

    rank_id: a single rank identifier (a string or an ObjectId) or a list of them
    expand_number: add an extra field with the number of user for every rank returned
    sorted_by: the field to sort the result with; by default it's the rank field
    sort_ascending: if True, sorts the results from first to last, if False sorts them the other way
    only_one: if True, returns one rank at most

    """
    def denormalize(rank):
        if rank is None:
            return rank
        if expand_number:
            rank['number_user'] = len(model.users.find(rank=rank['rank']))
        return rank
    
    conditions = []
    return db_engine(item_id=rank_id,
                     collection=db.ranks, 
                     conditions=conditions,
                     only_one=only_one,
                     sorted_by=sorted_by,
                     sort_ascending=sort_ascending,
                     denormalize=denormalize)
示例#4
0
文件: js.py 项目: imfht/flaskapps
def find(file_name=None, only_one=False):
    """
    """
    conditions = []
    if file_name:
        conditions.append({'file': file_name})
    return db_engine(collection=db.js,
                     conditions=conditions,
                     only_one=only_one)
示例#5
0
def find(hash_table_id=None, name=None, count=None, only_one=False):
    """ """
    # First, builds the filter conditions list
    conditions = []

    if name:
        conditions.append({"name": name})

    return db_engine(
        collection=db.hash_table, item_id=hash_table_id, conditions=conditions, only_one=only_one, count=count
    )
示例#6
0
def find(name=None, code=None, check=None, only_one=False, sorted_by=None):
    """
    """
    conditions = []

    if code:
        conditions.append({"code": code})

    if check:
        conditions.append({"check": check})

    return db_engine(collection=db.languages, conditions=conditions, only_one=only_one, sorted_by=sorted_by)
示例#7
0
def find(hash_table_id=None, name=None, count=None, only_one=False):
    """ """
    # First, builds the filter conditions list
    conditions = []

    if name:
        conditions.append({'name': name})

    return db_engine(collection=db.hash_table,
                     item_id=hash_table_id,
                     conditions=conditions,
                     only_one=only_one,
                     count=count)
示例#8
0
def find(name=None, code=None, check=None, only_one=False, sorted_by=None):
    """
    """
    conditions = []

    if code:
        conditions.append({'code': code})

    if check:
        conditions.append({'check': check})

    return db_engine(collection=db.languages,
                     conditions=conditions,
                     only_one=only_one,
                     sorted_by=sorted_by)
示例#9
0
def find(page_id=None,
         url=None,
         sorted_by=None,
         sort_ascending=True,
         limit=None,
         only_one=False,
         skip=None,
         count=None):
    """ """
    conditions = []

    if url:
        conditions.append({'url': url})

    return db_engine(collection=db.pages,
                     item_id=page_id,
                     conditions=conditions,
                     only_one=only_one,
                     sorted_by=sorted_by,
                     sort_ascending=sort_ascending,
                     limit=limit,
                     skip=skip,
                     count=count)
示例#10
0
def find(page_id=None,
		 url=None,
         sorted_by=None,
         sort_ascending=True,
         limit=None,
         only_one=False,
         skip=None,
         count=None):
    """ """
    conditions = []

    if url:
        conditions.append({'url': url})

    return db_engine(collection=db.pages, 
                     item_id=page_id,
                     conditions=conditions,
                     only_one=only_one,
                     sorted_by=sorted_by,
                     sort_ascending=sort_ascending,
                     limit=limit,
                     skip=skip,
                     count=count)
示例#11
0
文件: pages.py 项目: imfht/flaskapps
def find(page_id=None,
         name=None,
         url=None,
         field=None,
         field_value=None,
         page_id_ne=None,
         sorted_by=None,
         sort_ascending=True,
         limit=None,
         only_one=False,
         skip=None,
         count=None):
    """ """
    conditions = []

    if url:
        conditions.append({'url': url})

    if name:
        conditions.append({'name': name})

    if field:
        conditions.append({field: field_value})

    if page_id_ne:
        conditions.append({'_id': {"$ne": ensure_objectid(page_id_ne)}})

    return db_engine(collection=db.pages,
                     item_id=page_id,
                     conditions=conditions,
                     only_one=only_one,
                     sorted_by=sorted_by,
                     sort_ascending=sort_ascending,
                     limit=limit,
                     skip=skip,
                     count=count)
示例#12
0
def find(page_id=None,
         name=None,
		 url=None,
         field=None,
         field_value=None,
         page_id_ne=None,
         sorted_by=None,
         sort_ascending=True,
         limit=None,
         only_one=False,
         skip=None,
         count=None):
    """ """
    conditions = []

    if url:
        conditions.append({'url': url})

    if name:
        conditions.append({'name': name})

    if field:
        conditions.append({field: field_value})

    if page_id_ne:
        conditions.append({'_id': { "$ne": ensure_objectid(page_id_ne) }})

    return db_engine(collection=db.pages, 
                     item_id=page_id,
                     conditions=conditions,
                     only_one=only_one,
                     sorted_by=sorted_by,
                     sort_ascending=sort_ascending,
                     limit=limit,
                     skip=skip,
                     count=count)
示例#13
0
def find(user_id=None,
         username=None,
         email=None,
         rank=None,
         lan=None,
         expand_rank=False,
         sorted_by='username',
         sort_ascending=True,
         only_one=False,
         my_rank=None,
         my_id=None):
    """
    Returns a list of users or a single user, if user_id or only_one are specified.

    user_id: a single user identifier (a string or an ObjectId) or a list of them
    username: the unique user's name
    sort_ascending: if True, sorts the results from first to last, if False sorts them the other way
    only_one: if True, returns one tag at most
    
    """
    def denormalize(user):
        if user is None:
            return user

        if expand_rank:
            user['rank_name'] = { x['rank'] : x['name'] for x in model.ranks.find() }[user['rank']]

        # Data we want to show to our Soft Eng or the private user
        if isinstance(my_rank, int) and my_rank <= 70:
            return user

        # Data we want to show to our private user
        if str(my_id) == str(user["_id"]):
            return user

        # Data we want to show after sign in, to all
        user_to_show = {
            "_id" : user.get("_id", None),
            "rank": user.get("rank", None),
            "description": user.get("description", ""),
            "image": user.get("image", ""),
            "location": user.get("location", ""),
            "name": user.get("name", ""),
            "username": user.get("username", ""),
            "web": user.get("web", "")
        }
        return user_to_show

    if username:
        if is_iterable(username):
            list_users = list(db.users.find({"username" : {"$in": list(username)}}))
            return [ denormalize(u) for u in list_users ]
        else:
            regex = re.compile('^'+username+'$', re.IGNORECASE)
            return denormalize(db.users.find_one({"username" : regex}))


    # First, builds the filter conditions list
    conditions = []

    if email:
        email = email.lower()
        conditions.append({'email': email})

    if rank:
        conditions.append({'rank': rank})

    if lan:
        conditions.append({'lan': lan})

    return db_engine(collection=db.users, 
                     item_id=user_id,
                     only_one=only_one, 
                     conditions=conditions,
                     sorted_by=sorted_by,
                     sort_ascending=sort_ascending,
                     denormalize=denormalize)