示例#1
0
 def __init__(self, cursor: Cursor, row: tuple):
     self._row = Row(cursor, row)
     self._connection: PokeApiConnection = cursor.connection
     self.id = self._row['id']
     self._name: Optional[str]
     if 'name' in self._row:
         self._name = self._row['name']
     else:
         self._name = None
示例#2
0
    def init_from_db_row(db_row: sqlite3.Row):
        stop_id = db_row['stop_id']
        stop_name = db_row['stop_name']
        stop_lon = db_row['stop_lon']
        stop_lat = db_row['stop_lat']

        location_type = db_row.get('location_type') or None
        parent_station = db_row.get('parent_station') or None

        entry = Stop(stop_id, stop_name, stop_lon, stop_lat, location_type,
                     parent_station)

        return entry
示例#3
0
    def __init__(self, data: sqlite3.Row):
        self._logger = logging.getLogger('ProjectAlice')
        self._name = data['name']
        self._parent = data['parent']

        self._state = data['state'] if 'state' in data.keys() else 0
        self._x = data['posx'] if 'posx' in data.keys() else 0
        self._y = data['posy'] if 'posy' in data.keys() else 0
        self._size = data['size'] if 'size' in data.keys() else self.SIZE
        options = data['options'] if 'options' in data.keys() else self.OPTIONS
        if options:
            self._options = json.loads(options)
        else:
            self._options = self.OPTIONS

        self._zindex = data['zindex'] if 'zindex' in data.keys() else 9999
示例#4
0
 def helper(self):
     helper = FormHelper(self)
     helper.layout = Layout(
         HTML(
             '<h4 class="partner-data mx-auto mt-4 text-center" style="font-family: Times, serif; font-style:italic; color: #D6580F;"><strong>Partnership Request</strong></h4>'
         ),
         HTML('<hr class="col-md-6 offset-md-3" style="border-top: 0px;">'),
     )
     for field in self.Meta.fields:
         helper.layout.append(
             Field(field, wrapper_class='row text-white m-1'), )
     helper.layout.append(
         Div(
             Row(
                 Column(css_class='col-md-4'),
                 Column(Submit(
                     'submit',
                     'Apply for Partnership',
                     style=
                     "font-family: Georgia, Times, serif; font-weight: bold;",
                     css_class=
                     'btn btn-primary rounded-pill col-md-8 offset-md-2 col-sm-4 offset-sm-4 mb-3'
                 ),
                        css_class='col-md-8'))))
     helper.field_class = 'col-md-8'
     helper.label_class = 'col-md-4'
     return helper
示例#5
0
class PokeapiResource:
    _namecol = None
    _suffix = None

    def __init__(self, cursor: Cursor, row: tuple):
        self._row = Row(cursor, row)
        self._connection: PokeApiConnection = cursor.connection
        self.id = self._row['id']
        self._name: Optional[str]
        if 'name' in self._row:
            self._name = self._row['name']
        else:
            self._name = None

    @property
    def name(self) -> Optional[str]:
        return self._name

    @name.setter
    def name(self, value: Optional[str]):
        self._name = value

    def __eq__(self, other):
        return isinstance(other, self.__class__) and other.id == self.id

    def __hash__(self):
        return hash((self.__class__, self.id))

    def __repr__(self):
        attrs = ', '.join(map('{0}={1!r}'.format, self._row.keys(), self._row))
        return '<{0.__class__.__name__} {1}>'.format(self, attrs)

    def get_submodel(self, model: 'ModelType',
                     field: str) -> Optional['Model']:
        return self._connection.get_model(model, self._row[field])
示例#6
0
    def dict_from_row(row: sqlite3.Row) -> dict:
        """Convert the sqlite.Row result to a dictionary

        :type row: sqlite3.Row
        :return:
        """
        if not row:
            return {}
        return dict(zip(row.keys(), row))
示例#7
0
    def __init__(self, data: sqlite3.Row):
        super().__init__()
        self._name = data['name']
        self._parent = data['parent']

        # sqlite3.Row does not support .get like dicts
        self._state = data['state'] if 'state' in data.keys() else 0
        self._x = data['posx'] if 'posx' in data.keys() else 0
        self._y = data['posy'] if 'posy' in data.keys() else 0
        self._size = data['size'] if 'size' in data.keys() else self.SIZE
        options = json.loads(
            data['options']) if 'options' in data.keys() else self.OPTIONS
        if options:
            self._options = {**self.OPTIONS, **options}
        else:
            self._options = self.OPTIONS

        self._zindex = data['zindex'] if 'zindex' in data.keys() else 9999
        self._language = self.loadLanguage()
示例#8
0
def key_from_row(row: sqlite3.Row,
                 secret_phrase: Optional[str] = None,
                 get_priv: bool = False) -> KeyEntry:
    '''
    Does what it says on the tin
    '''
    res = cast(KeyEntry, dict((k, row[k]) for k in row.keys()))
    if get_priv and secret_phrase:
        privkey = crypto.decode_aes(row['privkey'], secret_phrase)
        res['privkey'] = privkey
    else:
        res['privkey'] = b''
    return res
示例#9
0
def row_to_dataclass(row: Row,
                     dc: Type[T],
                     overwrite_fields: Optional[Dict[str, Any]] = None) -> T:
    overwrite_fields = overwrite_fields or {}
    row_args = {}
    for dc_field in fields(dc):
        if dc_field.name in overwrite_fields:
            row_args[dc_field.name] = overwrite_fields[dc_field.name]
        else:
            row_args[dc_field.name] = (row[dc_field.name] if dc_field.name
                                       in row.keys() else None)

    return dc(**row_args)
示例#10
0
 def update_by_record(self, rec: sqlite3.Row):
     for k in rec.keys():
         try:
             x = getattr(self, k)
             if isinstance(x, QtWidgets.QComboBox):
                 if x.isEditable():
                     x.setEditText(rec[k])
                 else:
                     x.setCurrentText(rec[k])
             elif isinstance(x, QtWidgets.QLineEdit):
                 x.setText(str(rec[k]))
             elif isinstance(x, QtWidgets.QDateEdit):
                 year, month, day = map(int, rec[k].split('-'))
                 date = QtCore.QDate(year, month, day)
                 x.setDate(date)
         except Exception as e:
             if k not in ('ID', 'old_ID', 'page', 'add_list_ID'):
                 print(e)
示例#11
0
    def init_from_db_row(db_row: sqlite3.Row):
        service_id = db_row['service_id']
        start_date_s = db_row['start_date']
        end_date_s = db_row['end_date']
        day_bits = db_row['day_bits']

        monday = db_row.get('monday') or None
        tuesday = db_row.get('tuesday') or None
        wednesday = db_row.get('wednesday') or None
        thursday = db_row.get('thursday') or None
        friday = db_row.get('friday') or None
        saturday = db_row.get('saturday') or None
        sunday = db_row.get('sunday') or None

        entry = Calendar(service_id, start_date_s, end_date_s, day_bits,
                         monday, tuesday, wednesday, thursday, friday,
                         saturday, sunday)

        return entry
示例#12
0
 def dictFromRow(row: sqlite3.Row) -> dict:
     return dict(zip(row.keys(), row))
示例#13
0
	def __init__(self, data: sqlite3.Row):
		super().__init__()
		self._name = data['name']
		self._parent = data['parent']
		self._skillInstance = None

		# sqlite3.Row does not support .get like dicts
		# Many checks here because of NOT NULL DB constraints
		updateWidget = False
		if 'state' in data.keys() and data['state']:
			self._state = int(data['state'])
		else:
			self._state = 0
			updateWidget = True

		if 'posx' in data.keys() and data['posx']:
			self._x = data['posx']
		else:
			self._x = 10
			updateWidget = True

		if 'posy' in data.keys() and data['posy']:
			self._y = data['posy']
		else:
			self._y = 10
			updateWidget = True

		if 'height' in data.keys() and data['height']:
			self._height = data['height']
		else:
			self._height = 0
			updateWidget = True

		if 'width' in data.keys() and data['width']:
			self._width = data['width']
		else:
			self._width = 0
			updateWidget = True

		self._size = self.DEFAULT_SIZE.value

		self._options = self.DEFAULT_OPTIONS
		if 'options' in data.keys():
			self._options.update(json.loads(data['options']))

		self._custStyle = self.CUSTOM_STYLE.copy()
		if 'custStyle' in data.keys() and data['custStyle']:
			self._custStyle.update(json.loads(data['custStyle']))
		else:
			updateWidget = True

		if 'zindex' in data.keys() and data['zindex'] is not None:
			self._zindex = data['zindex']
		else:
			self._zindex = 999
			updateWidget = True

		if updateWidget:
			self.saveToDB()

		self._language = self.loadLanguage()
示例#14
0
def header_from_row(row: sqlite3.Row) -> Header:
    '''
    Does what it says on the tin
    '''
    return cast(Header, dict((k, row[k]) for k in row.keys()))
示例#15
0
 def zipper(row: sqlite3.Row):
     return dict(zip(row.keys(), row))
示例#16
0
 def from_sqlite(self, row: sqlite3.Row, sqlite_field_mapping=None) -> None:
     for sql_key in row.keys():
         key = sqlite_field_mapping[sql_key]\
             if sqlite_field_mapping is not None and sql_key in sqlite_field_mapping\
             else sql_key
         self[key] = row[sql_key]
示例#17
0
 def __init__(self, cursor, row):
     Row.__init__(self, cursor, row)
     self._cursor = cursor
示例#18
0
 def __getattr__(self, attr):
     return Row.__getitem__(self, attr)
示例#19
0
 def dict_from_row(row: sqlite3.Row) -> dict:
     """Unpacks an sqlite3.Row object into a dictionary."""
     if row is None:
         return None
     else:
         return dict(zip(row.keys(), row))