Example #1
0
def add_news(title, txt, lid, uid):
    v = Level.objects(id=ObjectId(lid)).first()
    u = User.objects(id=ObjectId(uid)).first()
    if v in u.power or u.user_type == 100:
        news = News(title=title, txt=txt, author=u.name)
        news.category = v
        news.save()
Example #2
0
def add_news(title,txt,lid,uid):
    v = Level.objects(id=ObjectId(lid)).first()
    u = User.objects(id=ObjectId(uid)).first()
    if v in u.power or u.user_type == 100:
        news = News(title=title,txt=txt,author=u.name)
        news.category = v
        news.save()
Example #3
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 []
Example #4
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 []
Example #5
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 []
Example #6
0
def get_lvl_news(lid):
    if lid:
        res = News.objects(category=ObjectId(lid)).order_by("-release_date")
        return res if res else []
    return []
Example #7
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()
Example #8
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()
Example #9
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
Example #10
0
def get_news(nid):
    news = News.objects(id=ObjectId(nid))
    return news.first() if news else None
Example #11
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 []
Example #12
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()
Example #13
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()
Example #14
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
Example #15
0
def get_lvl_news(lid):
    if lid:
        res = News.objects(category=ObjectId(lid)).order_by('-release_date')
        return res if res else []
    return []
Example #16
0
def get_news(nid):
    news = News.objects(id=ObjectId(nid))
    return news.first() if news else None