Example #1
0
def add_level(name, parent_lid=""):
    if parent_lid == "":
        Level(name=name).save()
    else:
        plvl = Level.objects(id=ObjectId(parent_lid)).first()
        lvl = Level(name=name)
        lvl.insert_lvl(plvl.r)
Example #2
0
def get_parent_lvl(lid):
    res = Level.objects(id=ObjectId(lid))
    if res:
        v = res.first()
        res = Level.objects(r__lt=v.r).order_by('-r')
        if res:
            for lvl in res:
                if lvl.c == v.c - 1:
                    return lvl
Example #3
0
def get_parent_lvl(lid):
    res = Level.objects(id=ObjectId(lid))
    if res:
        v = res.first()
        res = Level.objects(r__lt=v.r).order_by("-r")
        if res:
            for lvl in res:
                if lvl.c == v.c - 1:
                    return lvl
Example #4
0
def get_next_lvls(parent_lid):
    if parent_lid:
        plvl = Level.objects(id=ObjectId(parent_lid)).first()
        if plvl:
            sub_lvls = get_sub_lvls(parent_lid)
            if sub_lvls:
                r = [v for v in sub_lvls if v.c - 1 == plvl.c]
                return r if r else []
    else:
        res = Level.objects(c=0).order_by("r")
        return res if res else []
    return []
Example #5
0
def get_next_lvls(parent_lid):
    if parent_lid:
        plvl = Level.objects(id=ObjectId(parent_lid)).first()
        if plvl:
            sub_lvls = get_sub_lvls(parent_lid)
            if sub_lvls:
                r = [v for v in sub_lvls if v.c -1 == plvl.c]
                return r if r else []
    else:
        res = Level.objects(c=0).order_by('r')
        return res if res else []
    return []
Example #6
0
def del_level(lid):
    res = Level.objects(id=ObjectId(lid))
    if res:
        lvl = res.first()
        r = lvl.r
        lvl.delete()
        lvl.move_before(r)
Example #7
0
def get_sub_lvls(lid):
    if lid == '':
        res = Level.objects(c=0).order_by('r')
        return res if res else []
    res = Level.objects(id=ObjectId(lid))
    if res:
        v = res.first()
        lvls = Level.objects(r__gt=v.r).order_by('r')
        sub_lvls = []
        for sub_lvl in lvls:
            if sub_lvl.c > v.c:
                sub_lvls.append(sub_lvl)
            else:
                break
        return sub_lvls if sub_lvls else []
    return []
Example #8
0
def get_sub_lvls(lid):
    if lid == "":
        res = Level.objects(c=0).order_by("r")
        return res if res else []
    res = Level.objects(id=ObjectId(lid))
    if res:
        v = res.first()
        lvls = Level.objects(r__gt=v.r).order_by("r")
        sub_lvls = []
        for sub_lvl in lvls:
            if sub_lvl.c > v.c:
                sub_lvls.append(sub_lvl)
            else:
                break
        return sub_lvls if sub_lvls else []
    return []
Example #9
0
def edit_level(name,lid):
    res = Level.objects(id=ObjectId(lid))
    if not res:
        return
    lvl = res.first()
    lvl.name = name
    lvl.save()
Example #10
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 #11
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 #12
0
def edit_level(name, lid):
    res = Level.objects(id=ObjectId(lid))
    if not res:
        return
    lvl = res.first()
    lvl.name = name
    lvl.save()
Example #13
0
def del_level(lid):
    res = Level.objects(id=ObjectId(lid))
    if res:
        lvl = res.first()
        r = lvl.r
        lvl.delete()
        lvl.move_before(r)
Example #14
0
def get_bread_nav(lid):
    if lid:
        res = Level.objects(id=ObjectId(lid))
        if res:
            lvl = res.first()
            ids = [(lid,lvl.name),]
            if lvl.c == 0:
                return ids
            res = Level.objects(r__lt=lvl.r).order_by('-r')
            cc = lvl.c
            for v in res:
                if v.c == cc - 1:
                    ids.append((str(v.id),v.name))
                    cc -= 1
                if cc <= 0:
                    break
            ids.reverse()
            return ids
    return []
Example #15
0
def get_next_lvls(parent_lid):
    if parent_lid:
        plvl = Level.objects(id=ObjectId(parent_lid)).first()
        if plvl:
            sub_lvls = get_sub_lvls(parent_lid)
            # son_lid = ''
            if sub_lvls:
                r = [v for v in sub_lvls if v.c -1 == plvl.c]
                return r if r else []
            #     for lvl in sub_lvls:
            #         if lvl.c - 1 == plvl.c:
            #             son_lid = str(lvl.id)
            #             break
            # if son_lid:
            #     return get_brother_lvls(son_lid)
    else:
        res = Level.objects(c=0).order_by('r')
        return res if res else []
    return []
Example #16
0
def get_bread_nav(lid):
    if lid:
        res = Level.objects(id=ObjectId(lid))
        if res:
            lvl = res.first()
            ids = [(lid, lvl.name)]
            if lvl.c == 0:
                return ids
            res = Level.objects(r__lt=lvl.r).order_by("-r")
            cc = lvl.c
            for v in res:
                if v.c == cc - 1:
                    ids.append((str(v.id), v.name))
                    cc -= 1
                if cc <= 0:
                    break
            ids.reverse()
            return ids
    return []
Example #17
0
def get_sub_lvls(lid):
    if lid == '':
        res = Level.objects(c=0).order_by('r')
        return res if res else []
    res = Level.objects(id=ObjectId(lid))
    if res:
        v = res.first()
        # rc = v.get_pos(v.r)
        # if rc:
        #     re,c = rc
        #     res = Level.objects(r__gt=v.r).filter(r__lt=re).order_by('r')
        #     return res
        lvls = Level.objects(r__gt=v.r).order_by('r')
        sub_lvls = []
        for sub_lvl in lvls:
            if sub_lvl.c > v.c:
                sub_lvls.append(sub_lvl)
            else:
                break
        return sub_lvls if sub_lvls else []
    return []
Example #18
0
def add_level(name,parent_lid=''):
    if parent_lid == '':
        Level(name=name).save()
    else:
        plvl = Level.objects(id=ObjectId(parent_lid)).first()
        lvl = Level(name=name)
        lvl.insert_lvl(plvl.r)
Example #19
0
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
Example #20
0
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
Example #21
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 #22
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 #23
0
def get_bread_nav(lid):
    if lid:
        res = Level.objects(id=ObjectId(lid))
        if res:
            lvl = res.first()
            ids = [(lid,lvl.name),]
            # print(lid)
            for i in range(lvl.c):
                # print(i,lvl.c)
                slvl = get_parent_lvl(lid)

                lid = str(slvl.id)
                ids.append((lid,slvl.name))
            ids.reverse()
            return ids if ids else []
    return []
Example #24
0
def lid_to_lvl(lid):
    if lid:
        res = Level.objects(id=ObjectId(lid))
        if res:
            return res.first()
Example #25
0
def lid_to_lvl(lid):
    if lid:
        res = Level.objects(id=ObjectId(lid))
        if res:
            return res.first()