def __init__(self, db, table, id, primary_key='id'): '''Create a Record Object given a vlib.db Object, a table name, and a record Id id column can also be an sql where clause, like 'order_no="TC-100903401"' Meant to be subclassed, as follows: from datarecord import DataRecord class User(DataRecord): def __init__(self, id): DataRecord.__init__(db.getInstance(), 'user', id) u = User(1) print u.name u2 = User("name='Fernandez'") print u2.phone ''' self.db = db self.table = table self.id = id self.primary_key = primary_key DataTable.__init__(self, db, table) self.debug_sql = DEBUG self._loadData()
def __init__ (self, db, tablename, id_field=None): '''Given a db connection, and a table name, that conforms to the Attributes Model load data. ''' DataTable.__init__(self, db, tablename) self.id_field = id_field if id_field \ else plural2singular(tablename) + '_id' self._loadTable() self._setConstants()
def __init__(self, db, tablename, id_field=None): '''Given a db connection, and a table name, that conforms to the Attributes Model load data. ''' DataTable.__init__(self, db, tablename) self.id_field = id_field if id_field \ else plural2singular(tablename) + '_id' self._loadTable() self._setConstants()
def process(self): HtmlPage.process(self) if 'phonenumber' in self.form: phonenumber = self.form['phonenumber'].value if not re.match(PHONE_NUMBER_REGEX, phonenumber): self.user_error_msg = 'Invalid Phone Number: %s ' % phonenumber else: folks = DataTable(db.getInstance(), 'folks') folks.insertRow({'phonenumber': phonenumber, 'active': 1}) self.user_msg = "Okay - congrats - you've been added (%s)" \ % phonenumber
def __init__(self, db, table, id): '''Create a Record Object given a vlib.db Object, a table name, and a record Id Meant to be subclassed, as follows: class user(Record): def __init__(self, id): Record.__init__(db.getInstance(), 'user', id) ''' self.db = db self.table = table self.id = id DataTable.__init__(self, db, table) self.debug_sql = DEBUG self._loadData()
def __init__(self, db, table, id, primary_key='id'): '''Create a Record Object given a vlib.db Object, a table name, and a record Id Meant to be subclassed, as follows: from datarecord import DataRecord class user(DataRecord): def __init__(self, id): DataRecord.__init__(db.getInstance(), 'user', id) u = User(1) print u.name ''' self.db = db self.table = table self.id = id self.primary_key = primary_key DataTable.__init__(self, db, table) self.debug_sql = DEBUG self._loadData()
def __init__(self): DataTable.__init__(self, db.getInstance(), 'schools') self.conf = conf.getInstance()
def genYaml(self, tablename, alias): '''Given a tablename and an given alias Read table schema info from the database Return vreports Column yaml file ''' # Todo add count column to output: """ - name : count select : '*' aliases : c mode : aggregate aggregate_func: count type : integer default : true """ # Read columns info from database dt = DataTable(self.db, tablename) columns = [] for row in dt.describe(): name = row['Field'] db_type = row['Type'] # Convert DB types to vreports Types: # remove numbers from db_type db_type = re.sub(r'[0-9]', r'', db_type) # care not about unsigned: db_type = db_type.replace(' unsigned', '') if db_type in ('int()', 'tinyint()', 'smallint()', 'bigint()'): type = 'integer' elif db_type in ('char()', 'varchar()','text') or 'enum' in db_type: type = 'string' elif db_type in ('datetime', 'timestamp'): type = 'datetime' elif db_type in ('date',): type = 'date' elif db_type in ('decimal(,)'): type = 'money' else: raise GeneratorError('Unrecognized db_type: %s' % db_type) columns.append({'name': name, 'type': type}) # Create Yaml by hand # not using yaml.dump for more control o = 'columns:\n\n' for i, c in enumerate(columns): o += ' - name : %s\n' % c['name'] o += ' select : %s.%s\n' % (alias, c['name']) o += ' type : %s\n' % c['type'] if c['type'] == 'money': o += ' aggregate_func: sum\n' o += ' default: true\n' o += '\n' o += ''' # count - name : count select : '*' aliases : %s mode : aggregate aggregate_func: count type : integer default : true''' % alias return o
def __init__(self): self.db = db.getInstance() DataTable.__init__(self, self.db, 'page_pics')
def __init__(self): self.db = db.getInstance() DataTable.__init__(self, self.db, 'follows')
def url_previewsDt(self): from vlib.datatable import DataTable return DataTable(self.db, 'url_previews')
def __init__(self): self.db = db.getInstance() self.conf = conf.getInstance() self.activity_notifications = ActivityNotifications() DataTable.__init__(self, db.getInstance(), 'messages')