예제 #1
0
def edit_role2(post, permissions):
    #Обновлеяем запись
    obj = get_role2(post['id'])
    if not obj:
        return False
    obj.name = post['rolename']
    obj.rolesgroup = post['rolegroup']
    obj.description = post['description']
    obj.ordering = post['order']  
    
    #Удаляем роли
    DBSession.query(PermissionsRoles).filter(PermissionsRoles.role_id == post['id']).delete()
            
    #Добавляем роли
    for e in permissions:
        pr = PermissionsRoles(post['id'], e)
        DBSession.add(pr)  
    
    try:
        transaction.commit()
    except:
        transaction.rollback()
        return False
    else:
        return True
예제 #2
0
def get_posts(offset=None, limit=None):
    
    setallroute()
    
    if offset==None or limit==None:
        return DBSession.query(Blogs).all()
    else:
        return (DBSession.query(Blogs).all())[offset:limit]
예제 #3
0
def get_roles(offset=None, limit=None):
    
    #Добавить короткое описание
    setopt(Roles, 'shortdesc', Roles_shortdesc)
    
    if offset==None or limit==None:
        return DBSession.query(Roles).all()
    else:
        return DBSession.query(Roles).all()[offset:limit]
예제 #4
0
def get_users(offset=None, limit=None):

    # Форматирование даты и активности
    setallroute()

    if offset == None or limit == None:
        return DBSession.query(Users).all()
    else:
        return (DBSession.query(Users).all())[offset:limit]
def get_permissions2(offset=None, limit=None):
    
    #Добавить короткое описание
    setopt(Permissions, 'shortdesc', Permissions_shortdesc)
    
    if offset==None or limit==None:
        return DBSession.query(Permissions).all()
    else:
        return DBSession.query(Permissions).all()[offset:limit]
def delete_permissions(delitems):
    try:
        for e in delitems:
            DBSession.query(Permissions).filter(Permissions.id == e).delete()
        transaction.commit()
        result = 1
    except:
        transaction.rollback()
        result = 0
    return result
예제 #7
0
def new_accesslog(ip, e=1, u=0):
    
    l = AccessLog(ip, e, user_id=u)
    DBSession.add(l)
    
    try:
        transaction.commit()
    except:
        DBSession.rollback()
        return False
예제 #8
0
def delete_posts(delitems, thread='blog'):
    try:
        for e in delitems:
            DBSession.query(Blogs).filter(Blogs.id == e).delete()
            DBSession.query(Comments).filter(Comments.thread == thread).filter(Comments.threadid == e).delete()
        transaction.commit()
        result = 1
    except:
        transaction.rollback()
        result = 0
    return result
예제 #9
0
def put_userprofile(userid, post):
    p = DBSession.query(Profiles).filter(Profiles.userid == userid).one()
    
    p.fullname = post['fullname']
    
    try:
        transaction.commit()
    except:
        DBSession.rollback()
        return False
    else:
        return True
예제 #10
0
def delete_comment(itemid):

    DBSession.query(Comments).filter(Comments.id == itemid).delete()

    try:
        transaction.commit()
        result = 1
    except:
        DBSession.rollback()
        result = 0

    return result
예제 #11
0
def db_set_avatar(post):
    p = DBSession.query(Profiles).filter(Profiles.userid == post['id']).all()
    if not p[0]:
        return False
    p[0].avatar1 = post['avatarsource']
    p[0].avatar2 = post['avatarsize1']
    p[0].avatar3 = post['avatarsize2']
    
    try:
        transaction.commit()
    except:
        DBSession.rollback()
        return False
    else:
        return True
예제 #12
0
def set_userpassword(post):
    setopt(Users, 'check_password', Users_check_password)
    user = DBSession.query(Users).filter(Users.id == post['userid']).one()
    if user.check_password(post['oldpassword']):
        user.password = hash_password(post['password'])
        
        try:
            transaction.commit()
        except:
            DBSession.rollback()
            return False
        else:
            return 1
        
    else:
        return 2
예제 #13
0
def get_user(username):
    setopt(Users, 'check_password', Users_check_password)
    user = DBSession.query(Users).filter(Users.username == username).all()
    if user:
        return user[0]
    else:
        return None
예제 #14
0
def get_accesslog_badlogin(ip, e=1, t=180, attempt=3):
    
    ls = DBSession.query(AccessLog).filter(AccessLog.event_id == e).filter(AccessLog.ip == ip).filter(AccessLog.eventdate > int(time.time())-180).count()
    if ls < attempt:
        return True
    else:
        return False
예제 #15
0
def db_count_comments(thread, threadid):
    return (
        DBSession.query(Comments)
        .filter(Comments.thread == thread)
        .filter(Comments.published == 1)
        .filter(Comments.threadid == threadid)
        .count()
    )
예제 #16
0
def edit_comment(itemid, title, content):

    ts = int(time.time())

    obj = get_comment(itemid)
    obj.title = title
    obj.content = content
    obj.last_edited = ts

    try:
        transaction.commit()
        result = 1
    except:
        DBSession.rollback()
        result = 0

    return result
예제 #17
0
def count_comments(component, componentid):
    return (
        DBSession.query(Comments)
        .filter(Comments.thread == component)
        .filter(Comments.threadid == componentid)
        .filter(Comments.published == 1)
        .count()
    )
예제 #18
0
def get_comment2(id, ordering="id", component="blog", componentid=1):
    # Вывод с форматированием даты
    setopt(Comments, "datefromtimestamp", Comments_datefromtimestamp)
    return (
        DBSession.query(Comments)
        .filter(Comments.id == id)
        .filter(Comments.thread == component)
        .filter(Comments.threadid == componentid)
        .one()
    )
예제 #19
0
def get_posts2(post, orderbytable, offset, limit):
    
    for key in orderbytable.keys():
        if post['col'] == key:
            order_by=orderbytable[key]
    
    if post['asc'] == '1':
        ordering = asc(order_by)
    if post['asc'] == '0':
        ordering = desc(order_by)
    
    if 'phr' in post:
        if post['phr'] != '':
            phr = '%'+ post['phr'] +'%'
            filter = (dict(Blogs.__dict__))[post['lke']].like(phr)
            blogs = (DBSession.query(Blogs).filter(filter).order_by(ordering).all())[offset:limit]
    else:
        blogs = (DBSession.query(Blogs).order_by(ordering).all())[offset:limit]
    return blogs
예제 #20
0
def db_put_comment(itemid, post):

    p = get_bbparser()

    content = p.format(post["content"])

    obj = get_comment(itemid)
    obj.title = post["title"]
    obj.content = content
    obj.last_edited = post["last_edited"]

    try:
        transaction.commit()
        result = 1
    except:
        DBSession.rollback()
        result = 0

    return (result, content)
예제 #21
0
def get_comments(ordering, component, componentid, offset, limit):
    # Вывод с форматированием даты
    setopt(Comments, "datefromtimestamp", Comments_datefromtimestamp)
    order_by = asc(ordering)
    return (
        DBSession.query(Comments)
        .filter(Comments.thread == component)
        .filter(Comments.threadid == componentid)
        .order_by(order_by)
        .all()
    )[offset:limit]
예제 #22
0
def edit_post2(post, tags):
    
    ts = time.time()
    
    obj = get_post2(post['id'])
    if not obj:
        return False
    obj.title = post['title']
    obj.slug = post['alias']
    obj.userid = post['userid']
    obj.intro = post['into']
    obj.content = post['content']
    obj.published = post['published']
    obj.comments = post['comments']
    obj.comments_premoderation = post['comments_premoderation']
    obj.last_edited = ts
    
    #Удаляем тэги
    DBSession.query(TagsPosts).filter(TagsPosts.post_id == post['id']).delete()
    
    #Добавляем тэги
    for e in tags:
        pt = TagsPosts(post['id'], e)
        DBSession.add(pt)
    
    try:
        transaction.commit()
    except:
        DBSession.rollback()
        return False
    else:
        return True
예제 #23
0
def edit_user2(post, roles, useavatars):
    # Обновлеяем запись
    obj = get_user2(post["id"])
    if not obj:
        return False
    obj.username = post["username"]
    obj.email = post["email"]
    obj.profiles.fullname = post["fullname"]
    if useavatars == 1 and "avatarsource" in post:
        obj.profiles.avatar1 = post["avatarsource"]
        obj.profiles.avatar2 = post["avatarsize1"]
        obj.profiles.avatar3 = post["avatarsize2"]
    if post["password"] != "":
        obj.password = hash_password(post["password"])

    # Удаляем роли
    DBSession.query(RolesUsers).filter(RolesUsers.user_id == post["id"]).delete()

    # Добавляем роли
    for e in roles:
        ru = RolesUsers(post["id"], e)
        DBSession.add(ru)

    try:
        transaction.commit()
    except:
        DBSession.rollback()
        return False
    else:
        return True
예제 #24
0
def add_comment(userid, thread, threadid, threadtitle, title, content):

    p = Parser()
    p.add_simple_formatter(
        "video",
        '<object width="480" height="360"><embed src="http://www.youtube.com/v/%(value)s" type="application/x-shockwave-flash" width="480" height="360"></embed></object>',
    )
    p.add_simple_formatter(
        "img", '<img style="max-width:480px; max-height:400px;" src="%(value)s" alt="" />', replace_links=False
    )

    ts = int(time.time())

    DBSession.autoflush = False
    c = Comments(userid, thread, threadid, threadtitle, title, p.format(content), created=ts)
    DBSession.add(c)
    DBSession.flush()

    try:
        transaction.commit()
        result = 1
    except:
        DBSession.rollback()
        result = 0

    return result
예제 #25
0
def get_users2(post, orderbytable, offset, limit):

    # Форматирование даты и активности
    setallroute()

    for key in orderbytable.keys():
        if post["col"] == key:
            order_by = orderbytable[key]

    if post["asc"] == "1":
        ordering = asc(order_by)
    if post["asc"] == "0":
        ordering = desc(order_by)

    if "phr" in post:
        if post["phr"] != "":
            phr = "%" + post["phr"] + "%"
            filter = (dict(Users.__dict__))[post["lke"]].like(phr)
            users = (DBSession.query(Users).filter(filter).order_by(ordering).all())[offset:limit]
    else:
        users = (DBSession.query(Users).order_by(ordering).all())[offset:limit]
    return users
def new_permission2(post):
    #Добавляем запись
    DBSession.autoflush = False
    r = Permissions(post['permname'], description=post['description'], ordering=post['order'])   
    DBSession.add(r)
    DBSession.flush()
    DBSession.refresh(r)
            
    try:
        transaction.commit()
    except:
        DBSession.rollback()
        return False
    else:
        return r
예제 #27
0
def get_roles2(post, orderbytable, offset, limit):
    
    #Добавить короткое описание
    setopt(Roles, 'shortdesc', Roles_shortdesc)
    
    for key in orderbytable.keys():
        if post['col'] == key:
            order_by=orderbytable[key]
    
    if post['asc'] == '1':
        ordering = asc(order_by)
    if post['asc'] == '0':
        ordering = desc(order_by)
    
    if 'phr' in post:
        if post['phr'] != '':
            phr = '%'+ post['phr'] +'%'
            filter = (dict(Roles.__dict__))[post['lke']].like(phr)
            roles = (DBSession.query(Roles).filter(filter).order_by(ordering).all())[offset:limit]
    else:
        roles = (DBSession.query(Roles).order_by(ordering).all())[offset:limit]
    
    return roles
예제 #28
0
def get_comments2(get, ordering="id", thread="blog", threadid=1, offset=0, limit=100):
    # Вывод с форматированием даты
    setopt(Comments, "datefromtimestamp", Comments_datefromtimestamp)
    # order_by = asc(ordering)
    if get["sortorder"] == "asc":
        order_by = asc(ordering)
    if get["sortorder"] == "desc":
        order_by = desc(ordering)
    return (
        DBSession.query(Comments)
        .filter(Comments.thread == thread)
        .filter(Comments.threadid == threadid)
        .filter(Comments.published == 1)
        .order_by(order_by)
        .all()
    )[offset:limit]
예제 #29
0
def db_add_comment(post):

    p = get_bbparser()

    content = p.format(post["content"])

    DBSession.autoflush = False
    c = Comments(
        post["userid"], post["thread"], post["threadid"], post["threadtitle"], post["title"], content, post["created"]
    )
    DBSession.add(c)
    DBSession.flush()
    DBSession.refresh(c)

    try:
        transaction.commit()
        result = 1
    except:
        DBSession.rollback()
        result = 0

    u = DBSession.query(Users).filter(Users.id == post["userid"]).one()

    return (result, content, c.id, u.profiles.avatar3)
예제 #30
0
def db_get_useractivation(post, roles):
    ua = DBSession.query(UsersActivation).filter(UsersActivation.code == post['ticket']).all()
    if ua:
        DBSession.query(RolesUsers).filter(RolesUsers.user_id == ua[0].userid).delete()
        for e in roles:
            ru = RolesUsers(ua[0].userid, e)
            DBSession.add(ru)
        
        try:
            transaction.commit()
        except:
            DBSession.rollback()
            return False
        else:
            return True
        
        return ua[0]
    else:
        return None