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()
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()
def get_power(uid): res = User.objects(id=ObjectId(uid)) if res: u = res.first() if u.user_type == 100: return get_sub_lvls("") else: return u.power if u.power else [] return []
def edit_user(uid, name, password): res = User.objects(id=ObjectId(uid)) if res: u = res.first() if name: u.name = name if password: u.password = make_pw(name, password) u.save()
def edit_user(uid,name,password): res = User.objects(id=ObjectId(uid)) if res: u = res.first() if name: u.name = name if password: u.password = make_pw(name,password) u.save()
def get_power(uid): res = User.objects(id=ObjectId(uid)) if res: u = res.first() if u.user_type == 100: return get_sub_lvls('') else: return u.power if u.power else [] return []
def ch_pw(uid,opw,npw,name): opw = make_pw(name,opw) res = User.objects(id=ObjectId(uid)).filter(password=opw) if not res: return False u = res.first() npw = make_pw(u.name,npw) u.password = npw u.save() return u
def ch_pw(uid, opw, npw, name): opw = make_pw(name, opw) res = User.objects(id=ObjectId(uid)).filter(password=opw) if not res: return False u = res.first() npw = make_pw(u.name, npw) u.password = npw u.save() return u
def add_power(uids,powerids): uids = [ObjectId(i) for i in uids] users = User.objects(id__in=uids) powerids = [ObjectId(i) for i in powerids] powers = Level.objects(id__in=powerids) # print(uids,powerids) if not users or not powers: return for user in users: user.power.clear() for power in powers: user.power.append(power) user.save() return True
def add_power(uids, powerids): uids = [ObjectId(i) for i in uids] users = User.objects(id__in=uids) powerids = [ObjectId(i) for i in powerids] powers = Level.objects(id__in=powerids) # print(uids,powerids) if not users or not powers: return for user in users: user.power.clear() for power in powers: user.power.append(power) user.save() return True
def del_user(uid): User.objects(id=ObjectId(uid)).delete()
def login(name, pw): pw = make_pw(name, pw) res = User.objects(name=name).filter(password=pw) if not res: return False return res.first()
def get_users(): users = User.objects(user_type__ne=100) return users if users else []
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 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 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 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 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 login(name,pw): pw = make_pw(name,pw) res = User.objects(name=name).filter(password=pw) if not res: return False return res.first()
def add_admin_user(name, password): admin_users = User.objects(user_type=100) if not admin_users: u = add_user(name, password) u.user_type = 100 u.save()
def add_admin_user(name,password): admin_users = User.objects(user_type=100) if not admin_users: u = add_user(name,password) u.user_type = 100 u.save()