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 []
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 []
def get_last_news(limit=3): r = News.objects(id__in=sub_ids).order_by("-release_date")[0:limit] return r if r else []
def get_lvl_news(lid): if lid: res = News.objects(category=ObjectId(lid)).order_by("-release_date") return res if res else [] return []
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()
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()
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
def get_news(nid): news = News.objects(id=ObjectId(nid)) return news.first() if news else None
def get_last_news(limit=3): r = News.objects(id__in=sub_ids).order_by('-release_date')[0:limit] return r if r else []
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()
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()
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
def get_lvl_news(lid): if lid: res = News.objects(category=ObjectId(lid)).order_by('-release_date') return res if res else [] return []