Exemple #1
0
def register_user_old(product_name, user_name, priority=None, session=None):
    '''
    Create and register the user_name to the product_name
    '''
    try:
        #check that the product exists - must be created by the admin
        product_name = product_name.upper()
        prod = session.query(Product).filter(Product.id==product_name).one()
        
        user_products = session.query(UserProduct).join(User).filter(User.id==user_name).all()
        if len(user_products):
            #check if the user is already subscribed to this product
            if product_name in [p.product.id for p in user_products]:
                return com.error(com.WARN_ALREADY_REGISTERED)
            #the user exists but is not registered to this category
            user = user_products[0].user
        else:
            #the user does not exist - create it
            user = User(id=user_name, password="")
        up = UserProduct(user=user, product=prod, priority=priority)
        user.user_products.append(up)
        session.add(user)
        session.commit()
        return com.success()
    except NoResultFound:
        return com.error(com.ERR_INVALID_PRODUCT)
Exemple #2
0
def register_user_old(product_name, user_name, priority=None, session=None):
    '''
    Create and register the user_name to the product_name
    '''
    try:
        #check that the product exists - must be created by the admin
        product_name = product_name.upper()
        prod = session.query(Product).filter(Product.id == product_name).one()

        user_products = session.query(UserProduct).join(User).filter(
            User.id == user_name).all()
        if len(user_products):
            #check if the user is already subscribed to this product
            if product_name in [p.product.id for p in user_products]:
                return com.error(com.WARN_ALREADY_REGISTERED)
            #the user exists but is not registered to this category
            user = user_products[0].user
        else:
            #the user does not exist - create it
            user = User(id=user_name, password="")
        up = UserProduct(user=user, product=prod, priority=priority)
        user.user_products.append(up)
        session.add(user)
        session.commit()
        return com.success()
    except NoResultFound:
        return com.error(com.ERR_INVALID_PRODUCT)
Exemple #3
0
def create_product(product_name, session=None):
    product_name = product_name.upper()
    products = session.query(Product).filter(Product.id==product_name).all()
    if len(products):
        return com.error(com.WARN_EXISTING_CATEGORY)
    else:
        p = Product(id = product_name)
        session.add(p)
        session.commit()
    return com.success()
Exemple #4
0
def create_product(product_name, session=None):
    product_name = product_name.upper()
    products = session.query(Product).filter(Product.id == product_name).all()
    if len(products):
        return com.error(com.WARN_EXISTING_CATEGORY)
    else:
        p = Product(id=product_name)
        session.add(p)
        session.commit()
    return com.success()
Exemple #5
0
def register_user(product_name, user_name, priority=None, session=None):
    '''
    Create and register the user_name to the product_name
    '''
    try:
        #check that the product exists - must be created by the admin
        product_name = product_name.upper()
        prod = session.query(Product).filter(Product.id==product_name).one()
        users = prod.users
        if user_name in [u.id for u in users]:
            return com.error(com.WARN_ALREADY_REGISTERED)
        users = session.query(User).filter(User.id==user_name).all()
        if len(users):
            user = users[0]
        else:
            user = User(id=user_name, password="")
        user.products.append(prod)
        session.add(user)
        session.commit()
        return com.success()
    except NoResultFound:
        return com.error(com.ERR_INVALID_PRODUCT)
Exemple #6
0
def register_user(product_name, user_name, priority=None, session=None):
    '''
    Create and register the user_name to the product_name
    '''
    try:
        #check that the product exists - must be created by the admin
        product_name = product_name.upper()
        prod = session.query(Product).filter(Product.id == product_name).one()
        users = prod.users
        if user_name in [u.id for u in users]:
            return com.error(com.WARN_ALREADY_REGISTERED)
        users = session.query(User).filter(User.id == user_name).all()
        if len(users):
            user = users[0]
        else:
            user = User(id=user_name, password="")
        user.products.append(prod)
        session.add(user)
        session.commit()
        return com.success()
    except NoResultFound:
        return com.error(com.ERR_INVALID_PRODUCT)