Exemplo n.º 1
0
def get_news(lid="", limit=10, page=0):
    if not lid:
        return []
    if lid:
        sub_lvls = get_sub_lvls(lid)
    else:
        sub_lvls = Level.objects(c=0)
    if sub_lvls:
        sub_ids = [ObjectId(lid)]
        sub_ids.extend([i.id for i in sub_lvls])
        start = page * limit
        res = News.objects(category__in=sub_ids).order_by("-release_date")
        if res:
            return res[start : limit + 1]
    return []
Exemplo n.º 2
0
def get_news(lid='',limit=10,page=0):
    if not lid:
        return []
    if lid:
        sub_lvls = get_sub_lvls(lid)
    else:
        sub_lvls = Level.objects(c=0)
    if sub_lvls:
        sub_ids = [ObjectId(lid),]
        sub_ids.extend([i.id for i in sub_lvls])
        start = page * limit
        res = News.objects(category__in=sub_ids).order_by('-release_date')
        if res:
            return res[start:limit + 1]
    return []
Exemplo n.º 3
0
def get_last_news(limit=3):
    r = News.objects(id__in=sub_ids).order_by("-release_date")[0:limit]
    return r if r else []
Exemplo n.º 4
0
def get_lvl_news(lid):
    if lid:
        res = News.objects(category=ObjectId(lid)).order_by("-release_date")
        return res if res else []
    return []
Exemplo n.º 5
0
def check_news(nid, uid, user_type):
    news = News.objects(id=ObjectId(nid)).first()
    u = User.objects(id=ObjectId(uid)).first()
    if news and u and has_power(news, u.power) or user_type == 100:
        news.is_released = True
        news.save()
Exemplo n.º 6
0
def del_news(nid, uid):
    news = News.objects(id=ObjectId(nid))
    u = User.objects(id=ObjectId(uid)).first()
    if news.category in u.power:
        u.delete()
Exemplo n.º 7
0
def get_one_news(nid, uid, user_type):
    news = News.objects(id=ObjectId(nid)).first()
    u = User.objects(id=ObjectId(uid)).first()
    if news.author == u or has_power(news, u.power) or user_type == 100:
        return news
Exemplo n.º 8
0
def get_news(nid):
    news = News.objects(id=ObjectId(nid))
    return news.first() if news else None
Exemplo n.º 9
0
def get_last_news(limit=3):
    r = News.objects(id__in=sub_ids).order_by('-release_date')[0:limit]
    return r if r else []
Exemplo n.º 10
0
def check_news(nid,uid,user_type):
    news = News.objects(id=ObjectId(nid)).first()
    u = User.objects(id=ObjectId(uid)).first()
    if news and u and has_power(news,u.power) or user_type==100:
        news.is_released = True
        news.save()
Exemplo n.º 11
0
def del_news(nid,uid):
    news = News.objects(id=ObjectId(nid))
    u = User.objects(id=ObjectId(uid)).first()
    if news.category in u.power:
        u.delete()
Exemplo n.º 12
0
def get_one_news(nid,uid,user_type):
    news = News.objects(id=ObjectId(nid)).first()
    u = User.objects(id=ObjectId(uid)).first()
    if news.author == u or has_power(news,u.power) or user_type==100:
        return news
Exemplo n.º 13
0
def get_lvl_news(lid):
    if lid:
        res = News.objects(category=ObjectId(lid)).order_by('-release_date')
        return res if res else []
    return []
Exemplo n.º 14
0
def get_news(nid):
    news = News.objects(id=ObjectId(nid))
    return news.first() if news else None