Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
del sl[keys[1]]
else:
del self.slots[i]
def iteritems(self):
for sl in self.slots:
yield sl.name, sl
def get(self, key, default=None):
try:
return self[key].value
except KeyError:
return default
class Slot(DeclarativeBase):
__tablename__ = 'slots'
__table_args__ = (
Index('slots_guid_index', 'obj_guid'),
{'sqlite_autoincrement': True, }
)
# column definitions
id = Column('id', INTEGER(), primary_key=True, nullable=False, autoincrement=True)
obj_guid = Column('obj_guid', VARCHAR(length=32), nullable=False, index=True)
_name = Column('name', VARCHAR(length=4096), nullable=False)
@property
def name(self):
if self._name:
return self._name.split("/")[-1]
'lots': 2,
'orders': 1,
'prices': 3,
'recurrences': 2,
'schedxactions': 1,
'slots': 4,
'splits': 4,
'taxtable_entries': 3,
'taxtables': 2,
'transactions': 4,
'vendors': 1,
}
}
# this is not a declarative as it is used before binding the session to an engine.
gnclock = Table(u'gnclock', DeclarativeBase.metadata,
Column('Hostname', VARCHAR(length=255)),
Column('PID', INTEGER()),
)
class Version(DeclarativeBase):
"""The declarative class for the 'versions' table.
"""
__tablename__ = 'versions'
__table_args__ = {}
# column definitions
# : The name of the table
table_name = Column('table_name', VARCHAR(length=50), primary_key=True, nullable=False)
#: The version for the table
import uuid
from sqlalchemy import Column, VARCHAR, event
from sqlalchemy.ext.declarative import declared_attr
from sqlalchemy.orm import relation, foreign, object_session
from ._common import CallableList
from .kvp import DictWrapper, Slot
from .sa_extra import DeclarativeBase
class DeclarativeBaseGuid(DictWrapper, DeclarativeBase):
__abstract__ = True
#: the unique identifier of the object
guid = Column('guid', VARCHAR(length=32), primary_key=True, nullable=False, default=lambda: uuid.uuid4().hex)
@declared_attr
def slots(cls):
rel = relation('Slot',
primaryjoin=foreign(Slot.obj_guid) == cls.guid,
cascade='all, delete-orphan',
collection_class=CallableList,
)
return rel
# set the relation to the slots table (KVP)
'splits': 4,
'taxtable_entries': 3,
'taxtables': 2,
'transactions': 4,
'vendors': 1,
}
}
# this is not a declarative as it is used before binding the session to an engine.
gnclock = Table(u'gnclock', DeclarativeBase.metadata,
Column('Hostname', VARCHAR(length=255)),
Column('PID', INTEGER()),
)
class Version(DeclarativeBase):
"""The declarative class for the 'versions' table.
"""
__tablename__ = 'versions'
__table_args__ = {}
# column definitions
# : The name of the table
table_name = Column('table_name', VARCHAR(length=50), primary_key=True, nullable=False)
#: The version for the table
table_version = Column('table_version', INTEGER(), nullable=False)
def __init__(self, table_name, table_version):
self.table_name = table_name
self.table_version = table_version
pass
class GncValidationError(GnucashException):
pass
class GncImbalanceError(GncValidationError):
pass
class GncConversionError(GnucashException):
pass
class Recurrence(DeclarativeBase):
"""
Recurrence information for scheduled transactions
Attributes:
obj_guid (str): link to the parent ScheduledTransaction record.
recurrence_mult (int): Multiplier for the period type. Describes how many times
the period repeats for the next occurrence.
recurrence_period_type (str): type or recurrence (monthly, daily).
recurrence_period_start (date): the date the recurrence starts.
recurrence_weekend_adjust (str): adjustment to be made if the next occurrence
falls on weekend / non-working day.
"""
__tablename__ = 'recurrences'
__table_args__ = {'sqlite_autoincrement': True}
@event.listens_for(SlotFrame.slots, 'remove')
def remove_slot(target, value, initiator):
s = object_session(value)
if value in s.new:
s.expunge(value)
else:
s.delete(value)
class SlotGUID(SlotFrame):
__mapper_args__ = {
'polymorphic_identity': KVP_Type.KVP_TYPE_GUID
}
_python_type = (DeclarativeBase,)
# add
_mapping_name_class = {
'from-sched-xaction': 'piecash.core.transaction.ScheduledTransaction',
'account': 'piecash.core.account.Account',
'invoice-guid': 'piecash.business.invoice.Invoice',
'peer_guid': 'piecash.core.transaction.Split',
'gains-split': 'piecash.core.transaction.Split',
'gains-source': 'piecash.core.transaction.Split',
'default-currency': 'piecash.core.commodity.Commodity',
}
@property
def Class(self):
name, guid = self.name, self.guid_val
if name.startswith('CURRENCY::'):
from sqlalchemy import Column, INTEGER, VARCHAR, Table
from ..sa_extra import DeclarativeBase
gnclock = Table(u'gnclock', DeclarativeBase.metadata,
Column('hostname', VARCHAR(length=255)),
Column('pid', INTEGER()),
)
class Version(DeclarativeBase):
__tablename__ = 'versions'
__table_args__ = {}
# column definitions
table_name = Column('table_name', VARCHAR(length=50), primary_key=True, nullable=False)
table_version = Column('table_version', INTEGER(), nullable=False)
# relation definitions
# none
)
# create database (if DB is not a sqlite in memory)
if uri_conn != "sqlite:///:memory:":
if database_exists(uri_conn):
if overwrite:
drop_database(uri_conn)
else:
raise GnucashException("'{}' db already exists".format(uri_conn))
create_database(uri_conn)
engine = create_piecash_engine(uri_conn, **kwargs)
# drop constraints if we de not want to keep them (keep_foreign_keys=False), the default
if not keep_foreign_keys:
for n, tbl in DeclarativeBase.metadata.tables.items():
# drop index constraints
for idx in tbl.indexes:
if idx.name.startswith("ix_") or idx.name.startswith("_"):
event.listen(tbl,
"after_create",
DropIndex(idx),
once=True)
# drop FK constraints
for cstr in tbl.constraints:
if isinstance(cstr, PrimaryKeyConstraint):
continue
else:
event.listen(tbl,
"before_drop",
DropConstraint(cstr),
once=True)
from sqlalchemy import Column, INTEGER, VARCHAR, Table
from ..sa_extra import DeclarativeBase
gnclock = Table(u'gnclock', DeclarativeBase.metadata,
Column('hostname', VARCHAR(length=255)),
Column('pid', INTEGER()),
)
class Version(DeclarativeBase):
__tablename__ = 'versions'
__table_args__ = {}
# column definitions
table_name = Column('table_name', VARCHAR(length=50), primary_key=True, nullable=False)
table_version = Column('table_version', INTEGER(), nullable=False)
# relation definitions
# none
def __repr__(self):
return "Version<{}={}>".format(self.table_name, self.table_version)
cascade='all, delete-orphan',
uselist=False)
amounts = relation('BudgetAmount',
back_populates="budget",
cascade='all, delete-orphan',
collection_class=CallableList,
)
def __unirepr__(self):
return "Budget<{}({}) for {} periods following pattern '{}' >".format(self.name, self.description,
self.num_periods, self.recurrence)
class BudgetAmount(DeclarativeBase):
"""
A GnuCash BudgetAmount
Attributes:
amount (:class:`decimal.Decimal`): the budgeted amount
account (:class:`piecash.core.account.Account`): the budgeted account
budget (:class:`Budget`): the budget of the amount
"""
__tablename__ = 'budget_amounts'
__table_args__ = {'sqlite_autoincrement': True}
# column definitions
id = Column('id', INTEGER(), primary_key=True, autoincrement=True,nullable=False)
budget_guid = Column('budget_guid', VARCHAR(length=32),
ForeignKey('budgets.guid'), nullable=False)