Example #1
0
class UserHelper:
    def __init__(self):
        self.db = OracleDb()

    def User_Name(self, user_id=None):
        if user_id:
            user_id = "'{0}'".format(user_id)
        else:
            user_id = 'null'

        query = "select user_id from ORM_USER_USE_NETWORK({0}))".format(
            user_id)

        result = self.db.execute(query)
        return result

    def Network_Name(self, network_id=None):

        if network_id:
            network_id = "'{0}'".format(network_id)
        else:
            network_id = 'null'

        query = "select network_id from ORM_USER_USE_NETWORK({0}))".format(
            network_id)

        result = self.db.execute(query)
        return result
Example #2
0
def user_use_network():
    db = OracleDb()

    result = db.sqlalchemy_session.query(orm_User_Name).join(
        orm_user_use_network).join(orm_network).all()

    return render_template('user_network.html', users=result)
Example #3
0
def new_user():
    form = User_Form()

    if request.method == 'POST':
        if form.validate() == False:
            return render_template('user_form.html',
                                   form=form,
                                   form_name="New user",
                                   action="new_user")
        else:
            new_user = orm_User_Name(
                user_name=form.user_name.data,
                user_email=form.user_email.data,
                user_birthday=form.user_birthday.data.strftime("%d-%b-%y"),
                credit_card=form.credit_card.data)
            db = OracleDb()
            db.sqlalchemy_session.add(new_user)
            db.sqlalchemy_session.commit()

            return redirect(url_for('user'))

    return render_template('user_form.html',
                           form=form,
                           form_name="New user",
                           action="new_user")
Example #4
0
def edit_user():
    form = User_Form()

    if request.method == 'GET':

        user_id = request.args.get('user_id')
        db = OracleDb()
        user = db.sqlalchemy_session.query(orm_User_Name).filter(
            orm_User_Name.user_id == user_id).one()

        # fill form and send to user
        form.user_id.data = user.user_id
        form.user_name.data = user.user_name
        form.user_email.data = user.user_email
        form.user_birthday.data = user.user_birthday
        form.credit_card.data = user.credit_card

        return render_template('user_form.html',
                               form=form,
                               form_name="Edit user",
                               action="edit_user")

    else:

        if form.validate() == False:
            return render_template('user_form.html',
                                   form=form,
                                   form_name="Edit user",
                                   action="edit_user")
        else:
            db = OracleDb()
            # find user
            user = db.sqlalchemy_session.query(orm_User_Name).filter(
                orm_User_Name.user_id == form.user_id.data).one()

            # update fields from form data
            user.user_name = form.user_name.data
            user.user_email = form.user_email.data
            user.user_birthday = form.user_birthday.data.strftime("%d-%b-%y")
            user.credit_card = form.credit_card.data

            db.sqlalchemy_session.commit()

            return redirect(url_for('user'))
Example #5
0
def delete_user():
    user_id = request.form['user_id']

    db = OracleDb()

    result = db.sqlalchemy_session.query(orm_User_Name).filter(
        orm_User_Name.user_id == user_id).one()

    db.sqlalchemy_session.delete(result)
    db.sqlalchemy_session.commit()

    return user_id
Example #6
0
def dashboard():
    db = OracleDb()
Example #7
0
def network():
    db = OracleDb()

    result = db.sqlalchemy_session.query(orm_network).all()

    return render_template('network.html', networks=result)
Example #8
0
def user():
    db = OracleDb()

    result = db.sqlalchemy_session.query(orm_User_Name).all()

    return render_template('user.html', users=result)
Example #9
0
from WorkShop3.dao.orm.model import *
from WorkShop3.dao.db import OracleDb

db = OracleDb()

Base.metadata.create_all(db.sqlalchemy_engine)

session = db.sqlalchemy_session

User1 = orm_User_Name(user_name="User1",
                      user_email='*****@*****.**',
                      user_birthday='11-OCT-2001',
                      credit_card='1111222233334444')

User2 = orm_User_Name(user_name="User2",
                      user_email='*****@*****.**',
                      user_birthday='12-OCT-2002',
                      credit_card='2222333344445555')

User3 = orm_User_Name(user_name="User3",
                      user_email='*****@*****.**',
                      user_birthday='13-OCT-2003',
                      credit_card='3333444455556666')

Facebook = orm_network(network_name='Facebook')
VKontakte = orm_network(network_name='VKontakte')
Instagram = orm_network(network_name='Instagram')

# create relations
User1.orm_network.append(Facebook)
User1.orm_network.append(VKontakte)
Example #10
0
 def __init__(self):
     self.db = OracleDb()