Ejemplo n.º 1
0
    def remove_table_row(self, table, pk_id):
        _table = table['title']
        pk = self.get_table_primary_key(_table)
        query = 'DELETE FROM %s WHERE %s = ?' %(_table, pk)
        cur = self.get_cursor()
        cur.execute(query, (pk_id,))

        self.connection.commit()

        message = 'Removed row from table "%s" where "%s" is "%s"' %(_table, pk, pk_id)
        Store.show_message_in_status_bar(message)
Ejemplo n.º 2
0
    def get_data_to_add(self):
        current_tab = Store.get_current_tab()

        last_row = current_tab['last_row_loaded']
        last_row_loaded = last_row + Database.ROWS_PER_LOAD

        data = self.db.get_table_data(current_tab['title'], last_row)

        Store.set_last_row(Store.get_current_tab(), last_row_loaded)

        return data['rows']
Ejemplo n.º 3
0
    def add_tabs(self, tabs):
        for i, _tab in enumerate(tabs):
            name = _tab['title']

            table_foreign_keys = self.db.get_foreign_keys(name)
            Store.add_foreign_keys(i, table_foreign_keys)

            _table = Table(name, table_foreign_keys)
            table = _table.generate_table(
                list(map(lambda t: str(t), _tab['content']['headers'])),
                _tab['content']['rows'])

            Store.add_table(i, _table)

            self.addTab(_table, name)
Ejemplo n.º 4
0
    def cell_cnanged(self, row, col):
        table = Store.get_current_tab()
        pk_id = self.get_value_in_cell(row, 0)
        value = self.get_value_in_cell(row, col)
        col_name = self.get_col_name(col)

        self.db.update_table_column(table, pk_id, col_name, value)
Ejemplo n.º 5
0
    def remove_row(self):
        row = self.currentRow()

        table = Store.get_current_tab()
        pk_id = self.get_value_in_cell(row, 0)
        self.db.remove_table_row(table, pk_id)

        for tab in Store.get_all_tabs():
            if 'foreign_keys' in tab.keys():
                for key in tab['foreign_keys']:
                    _info = tab['foreign_keys'][key]
                    if _info['table'] == self.name:
                        _connected_table_name = tab['title']
                        self.db.update_table_column(tab, 'NULL', key, pk_id, key)

        self.removeRow(row)
Ejemplo n.º 6
0
    def insert_row_to_table(self, values):
        _table = Store.get_current_tab()['title']
        placeholder = ','.join(['?' for v in values])
        query = 'INSERT INTO %s VALUES (%s)' %(_table, placeholder)
        cur = self.get_cursor()
        cur.execute(query, values)

        self.connection.commit()

        self.insert_row(values)
Ejemplo n.º 7
0
    def make_tabs(self):
        tabs = []

        for table in self.db.get_all_tables():
            data = self.db.get_table_data(table, 0)

            _tab = {
                'title': table,
                'content': data,
            }
            tabs.append(_tab)

            Store.add_tab({
                'title': table,
                'last_row_loaded': Database.ROWS_PER_LOAD,
            })

        self.init_tabs()
        self.add_tabs(tabs)
Ejemplo n.º 8
0
    def create_form_froup_box():
        form_group_box = QGroupBox("Insert a new row")
        layout = QFormLayout()

        current_table = Store.get_current_tab()['title']
        Form.make_custom_fields(layout, current_table)

        form_group_box.setLayout(layout)

        Form.form_layout = form_group_box

        return form_group_box
Ejemplo n.º 9
0
    def insert_row(self, row):
        cur_tab = Store.get_current_tab()
        _table = cur_tab['table']

        _table.add_row_to_table(row)
Ejemplo n.º 10
0
from hashlib import sha256
from app.models.Store import Store

store = Store()
KIND = 'User'
h = sha256()

SCHEMA = {'id': 'str', 'name': 'str', 'password': '******'}


class User(object):
    _users = []

    def __init__(self, id=None, name=None, password=None):
        if not name:
            raise Exception('Name not defined.')
        if not password:
            raise Exception('Password not defined.')
        if id:
            self.id = name

        self.name = name
        self.password = User.hash_password(password)

    def __str__(self):
        return 'User(id={},name={},password={})'.format(
            self.id, self.name, self.password)

    def check_password(self, password):
        return (User.hash_password(password) == self.password)
Ejemplo n.º 11
0
    def combobox_changed(self, item):
        table = Store.get_current_tab()
        new_val = self.currentData()

        self.db.update_table_column(table, self.pk_id, self.column, new_val)
Ejemplo n.º 12
0
 def tab_click(self):
     current_tab = self.currentIndex()
     Store.set_current_tab(current_tab)