本文整理汇总了Python中trytond.backend.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __register__
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
sql_table = cls.__table__()
pool = Pool()
Work = pool.get('timesheet.work')
work = Work.__table__()
created_company = not table.column_exist('company')
super(Line, cls).__register__(module_name)
table = TableHandler(cursor, cls, module_name)
# Migration from 3.4: new company field
if created_company:
# Don't use FROM because SQLite nor MySQL support it.
cursor.execute(*sql_table.update(
[sql_table.company], [work.select(work.company,
where=work.id == sql_table.work)]))
# Migration from 3.4: change hours into timedelta duration
if table.column_exist('hours'):
table.drop_constraint('check_move_hours_pos')
cursor.execute(*sql_table.select(
sql_table.id, sql_table.hours))
for id_, hours in cursor.fetchall():
duration = datetime.timedelta(hours=hours)
cursor.execute(*sql_table.update(
[sql_table.duration],
[duration],
where=sql_table.id == id_))
table.drop_column('hours')
开发者ID:kret0s,项目名称:tryton3_8,代码行数:33,代码来源:line.py
示例2: __register__
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
super(Location, cls).__register__(module_name)
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
table.index_action(['left', 'right'], 'add')
开发者ID:aleibrecht,项目名称:tryton-modules-ar,代码行数:7,代码来源:location.py
示例3: get_userinfo
def get_userinfo(self, user, password, command=''):
path = urlparse.urlparse(self.path).path
dbname = urllib.unquote_plus(path.split('/', 2)[1])
database = backend.get('Database')().connect()
cursor = database.cursor()
databases = database.list(cursor)
cursor.close()
if not dbname or dbname not in databases:
return True
if user:
user = int(login(dbname, user, password, cache=False))
if not user:
return None
else:
url = urlparse.urlparse(self.path)
query = urlparse.parse_qs(url.query)
path = url.path[len(dbname) + 2:]
if 'key' in query:
key, = query['key']
with Transaction().start(dbname, 0) as transaction:
database_list = Pool.database_list()
pool = Pool(dbname)
if dbname not in database_list:
pool.init()
Share = pool.get('webdav.share')
user = Share.get_login(key, command, path)
transaction.cursor.commit()
if not user:
return None
Transaction().start(dbname, user, context={
'_check_access': True,
}, autocommit=True)
Cache.clean(dbname)
return user
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:35,代码来源:webdav.py
示例4: __register__
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().connection.cursor()
pool = Pool()
Line = pool.get('account.invoice.payment_term.line')
sql_table = cls.__table__()
line = Line.__table__()
# Migration from 4.0: rename long table
old_model_name = 'account.invoice.payment_term.line.relativedelta'
old_table = config.get(
'table', old_model_name, default=old_model_name.replace('.', '_'))
if TableHandler.table_exist(old_table):
TableHandler.table_rename(old_table, cls._table)
super(PaymentTermLineRelativeDelta, cls).__register__(module_name)
line_table = Line.__table_handler__(module_name)
# Migration from 3.4
fields = ['day', 'month', 'weekday', 'months', 'weeks', 'days']
if any(line_table.column_exist(f) for f in fields):
columns = ([line.id.as_('line')]
+ [Column(line, f) for f in fields])
cursor.execute(*sql_table.insert(
columns=[sql_table.line]
+ [Column(sql_table, f) for f in fields],
values=line.select(*columns)))
for field in fields:
line_table.drop_column(field)
开发者ID:coopengo,项目名称:account_invoice,代码行数:30,代码来源:payment_term.py
示例5: get_childs
def get_childs(self, uri, filter=None):
res = []
dbname, dburi = self._get_dburi(uri)
if not dbname:
database = backend.get('Database')().connect()
cursor = database.cursor()
try:
lists = database.list(cursor)
except Exception:
lists = []
finally:
cursor.close()
for dbname in lists:
res.append(urlparse.urljoin(uri, dbname))
return res
pool = Pool(Transaction().cursor.database_name)
try:
Collection = pool.get('webdav.collection')
scheme, netloc, path, params, query, fragment = \
urlparse.urlparse(uri)
if path[-1:] != '/':
path += '/'
for child in Collection.get_childs(dburi, filter=filter,
cache=CACHE):
res.append(urlparse.urlunparse((scheme, netloc,
path + child.encode('utf-8'), params, query,
fragment)))
except KeyError:
return res
except (DAV_Error, DAV_NotFound, DAV_Secret, DAV_Forbidden), exception:
self._log_exception(exception)
raise
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:32,代码来源:webdav.py
示例6: start
def start(self, database_name, user, readonly=False, context=None,
close=False, autocommit=False):
'''
Start transaction
'''
Database = backend.get('Database')
assert self.user is None
assert self.database is None
assert self.close is None
assert self.context is None
if not database_name:
database = Database().connect()
else:
database = Database(database_name).connect()
Flavor.set(Database.flavor)
self.user = user
self.database = database
self.readonly = readonly
self.connection = database.get_connection(readonly=readonly,
autocommit=autocommit)
self.close = close
self.context = context or {}
self.create_records = {}
self.delete_records = {}
self.delete = {}
self.timestamp = {}
self.counter = 0
self._datamanagers = []
return self
开发者ID:coopengo,项目名称:trytond,代码行数:29,代码来源:transaction.py
示例7: __register__
def __register__(cls, module_name):
pool = Pool()
ProductCostPrice = pool.get('product.cost_price')
TableHandler = backend.get('TableHandler')
sql_table = cls.__table__()
cost_price = ProductCostPrice.__table__()
cursor = Transaction().connection.cursor()
exist = TableHandler.table_exist(cls._table)
cost_price_exist = TableHandler.table_exist(ProductCostPrice._table)
super(ProductCostPriceMethod, cls).__register__(module_name)
# Migrate from 4.4: move cost_price_method from ProductCostPrice
if not exist and not cost_price_exist:
cls._migrate_property([], [], [])
elif not exist and cost_price_exist:
cost_price_table = TableHandler(ProductCostPrice, module_name)
if cost_price_table.column_exist('template'):
columns = ['create_uid', 'create_date',
'write_uid', 'write_date',
'template', 'cost_price_method']
cursor.execute(*sql_table.insert(
columns=[Column(sql_table, c) for c in columns],
values=cost_price.select(
*[Column(cost_price, c) for c in columns])))
开发者ID:coopengo,项目名称:product,代码行数:26,代码来源:product.py
示例8: __register__
def __register__(cls, module_name):
pool = Pool()
Party = pool.get('party.party')
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
party = Party.__table__()
super(PartyIdentifier, cls).__register__(module_name)
party_h = TableHandler(cursor, Party, module_name)
if (party_h.column_exist('vat_number')
and party_h.column_exist('vat_country')):
identifiers = []
cursor.execute(*party.select(
party.id, party.vat_number, party.vat_country,
where=(party.vat_number != Null)
| (party.vat_country != Null)))
for party_id, number, country in cursor.fetchall():
code = (country or '') + (number or '')
if not code:
continue
type = None
if vat.is_valid(code):
type = 'eu_vat'
identifiers.append(
cls(party=party_id, code=code, type=type))
cls.save(identifiers)
party_h.drop_column('vat_number')
party_h.drop_column('vat_country')
开发者ID:kret0s,项目名称:tryton3_8,代码行数:29,代码来源:party.py
示例9: db_exist
def db_exist(request, database_name):
Database = backend.get('Database')
try:
Database(database_name).connect()
return True
except Exception:
return False
开发者ID:coopengo,项目名称:trytond,代码行数:7,代码来源:dispatcher.py
示例10: __register__
def __register__(cls, module_name):
pool = Pool()
Account = pool.get('analytic_account.account')
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
# Migration from 3.4: use origin as the key for One2Many
migration_3_4 = False
old_table = 'analytic_account_account_selection_rel'
if TableHandler.table_exist(cursor, old_table):
TableHandler.table_rename(cursor, old_table, cls._table)
migration_3_4 = True
# Don't create table before renaming
table = TableHandler(cursor, cls, module_name)
super(AnalyticAccountEntry, cls).__register__(module_name)
# Migration from 3.4: set root value and remove required
if migration_3_4:
account = Account.__table__()
cursor.execute(*account.select(account.id, account.root,
where=account.type != 'root'))
entry = cls.__table__()
for account_id, root_id in cursor.fetchall():
cursor.execute(*entry.update(
columns=[entry.root],
values=[root_id],
where=entry.account == account_id))
table.not_null_action('selection', action='remove')
table.not_null_action('account', action='remove')
开发者ID:kret0s,项目名称:tryton3_8,代码行数:31,代码来源:account.py
示例11: __register__
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
sql_table = cls.__table__()
# Migration from 2.2 new field currency
created_currency = table.column_exist('currency')
super(ProductSupplier, cls).__register__(module_name)
# Migration from 2.2 fill currency
if not created_currency:
Company = Pool().get('company.company')
company = Company.__table__()
limit = cursor.IN_MAX
cursor.execute(*sql_table.select(Count(sql_table.id)))
product_supplier_count, = cursor.fetchone()
for offset in range(0, product_supplier_count, limit):
cursor.execute(*sql_table.join(company,
condition=sql_table.company == company.id
).select(sql_table.id, company.currency,
order_by=sql_table.id,
limit=limit, offset=offset))
for product_supplier_id, currency_id in cursor.fetchall():
cursor.execute(*sql_table.update(
columns=[sql_table.currency],
values=[currency_id],
where=sql_table.id == product_supplier_id))
# Migration from 2.4: drop required on sequence
table.not_null_action('sequence', action='remove')
# Migration from 2.6: drop required on delivery_time
table.not_null_action('delivery_time', action='remove')
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:35,代码来源:product.py
示例12: __register__
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
sql_table = cls.__table__()
# Migration from 1.8: new field company
table = TableHandler(cursor, cls, module_name)
company_exist = table.column_exist('company')
super(Statement, cls).__register__(module_name)
# Migration from 1.8: fill new field company
if not company_exist:
offset = 0
limit = cursor.IN_MAX
statements = True
while statements:
statements = cls.search([], offset=offset, limit=limit)
offset += limit
for statement in statements:
cls.write([statement], {
'company': statement.journal.company.id,
})
table = TableHandler(cursor, cls, module_name)
table.not_null_action('company', action='add')
# Migration from 3.2: remove required on start/end balance
table.not_null_action('start_balance', action='remove')
table.not_null_action('end_balance', action='remove')
# Migration from 3.2: add required name
cursor.execute(*sql_table.update([sql_table.name],
[sql_table.id.cast(cls.name.sql_type().base)],
where=sql_table.name == None))
开发者ID:aleibrecht,项目名称:tryton-modules-ar,代码行数:34,代码来源:statement.py
示例13: __register__
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
sql_table = cls.__table__()
super(PaymentTermLine, cls).__register__(module_name)
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
# Migration from 1.0 percent change into percentage
if table.column_exist('percent'):
cursor.execute(*sql_table.update(
columns=[sql_table.percentage],
values=[sql_table.percent * 100]))
table.drop_column('percent', exception=True)
# Migration from 2.2
if table.column_exist('delay'):
cursor.execute(*sql_table.update(
columns=[sql_table.day],
values=[31],
where=sql_table.delay == 'end_month'))
table.drop_column('delay', exception=True)
lines = cls.search([])
for line in lines:
if line.percentage:
cls.write([line], {
'divisor': cls.round(Decimal('100.0') /
line.percentage, cls.divisor.digits[1]),
})
# Migration from 2.4: drop required on sequence
table.not_null_action('sequence', action='remove')
开发者ID:aleibrecht,项目名称:tryton-modules-ar,代码行数:31,代码来源:payment_term.py
示例14: db_exist
def db_exist():
Database = backend.get('Database')
database = Database().connect()
cursor = database.cursor()
databases = database.list(cursor)
cursor.close()
return DB_NAME in databases
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:7,代码来源:test_tryton.py
示例15: restore_default_party_lang_from_4_2
def restore_default_party_lang_from_4_2(cls):
from trytond.transaction import Transaction
from sql import Null, Table, Cast
from sql.operators import Concat
from trytond.pool import Pool
TableHandler = backend.get('TableHandler')
if not TableHandler.table_exist('ir_property'):
return
pool = Pool()
property = Table('ir_property')
Lang = pool.get('ir.lang')
field = pool.get('ir.model.field').__table__()
lang = Lang.__table__()
cursor = Transaction().connection.cursor()
query_table = property.join(lang, condition=(
property.value == Concat('ir.lang,', Cast(lang.id, 'VARCHAR'))
)).join(field, condition=((property.field == field.id) &
(field.name == 'lang')))
cursor.execute(
*query_table.select(lang.id, where=property.res == Null))
result = cursor.fetchone()
if result:
result = list(result)
default_lang = Lang(result[0])
print('Default Language restored [%s]' % default_lang.rec_name)
pool.get('party.configuration.party_lang'
).create([{'party_lang': default_lang}])
else:
print('No default language on party configuration found')
开发者ID:coopengo,项目名称:party,代码行数:33,代码来源:configuration.py
示例16: __register__
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
super(ProductMedia, cls).__register__(module_name)
media_table = cls.__table__()
if TableHandler.table_exist(cursor, 'product_product_imageset'):
# Migrate data from ProductImageSet table to ProductMedia table
imageset_table = Table('product_product_imageset')
cursor.execute(*media_table.insert(
columns=[
media_table.sequence,
media_table.product, media_table.template,
media_table.static_file,
],
values=imageset_table.select(
Literal(10),
imageset_table.product, imageset_table.template,
imageset_table.image
)
))
TableHandler.drop_table(
cursor, 'product.product.imageset', 'product_product_imageset',
cascade=True
)
开发者ID:gautampanday,项目名称:nereid-catalog,代码行数:29,代码来源:product.py
示例17: __register__
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
sql_table = cls.__table__()
table = TableHandler(cursor, cls, module_name)
if not table.column_exist('shop'):
table.add_raw_column(
'shop',
cls.shop.sql_type(),
cls.shop.sql_format, None, None
)
else:
Shop = Pool().get('sale.shop')
shops = Shop.search([])
if shops:
sales = cls.search([
('shop', '=', None),
])
for sale in sales:
cursor.execute(*sql_table.update(
columns=[sql_table.shop],
values=[shops[0].id],
where=sql_table.id == sale.id))
else:
logging.getLogger('sale shop').warning(
'You must to create a shop and update module '
'to assign current sales to new shop.')
super(Sale, cls).__register__(module_name)
开发者ID:openlabs,项目名称:trytond-sale-shop,代码行数:28,代码来源:sale.py
示例18: login
def login(request, database_name, user, password):
Database = backend.get('Database')
DatabaseOperationalError = backend.get('DatabaseOperationalError')
try:
Database(database_name).connect()
except DatabaseOperationalError:
logger.error('fail to connect to %s', database_name, exc_info=True)
return False
session = security.login(database_name, user, password)
with Transaction().start(database_name, 0):
Cache.clean(database_name)
Cache.resets(database_name)
msg = 'successful login' if session else 'bad login or password'
logger.info('%s \'%s\' from %s using %s on database \'%s\'',
msg, user, request.remote_addr, request.scheme, database_name)
return session
开发者ID:coopengo,项目名称:trytond,代码行数:16,代码来源:dispatcher.py
示例19: run
def run(self):
from trytond.config import CONFIG
CONFIG['db_type'] = 'postgresql'
CONFIG['db_host'] = 'localhost'
CONFIG['db_port'] = 5432
CONFIG['db_user'] = 'postgres'
CONFIG['timezone'] = 'UTC'
from trytond import backend
import trytond.tests.test_tryton
# Set the db_type again because test_tryton writes this to sqlite
# again
CONFIG['db_type'] = 'postgresql'
trytond.tests.test_tryton.DB_NAME = 'test_' + str(int(time.time()))
from trytond.tests.test_tryton import DB_NAME
trytond.tests.test_tryton.DB = backend.get('Database')(DB_NAME)
from trytond.pool import Pool
Pool.test = True
trytond.tests.test_tryton.POOL = Pool(DB_NAME)
from tests import suite
test_result = unittest.TextTestRunner(verbosity=3).run(suite())
if test_result.wasSuccessful():
sys.exit(0)
sys.exit(-1)
开发者ID:rahulsukla,项目名称:nereid,代码行数:28,代码来源:setup.py
示例20: __register__
def __register__(cls, module_name):
pool = Pool()
Employee = pool.get('company.employee')
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
table = cls.__table__()
table_h = TableHandler(cursor, cls, module_name)
migrate_cost_price = not table_h.column_exist('cost_price')
super(TimesheetLine, cls).__register__(module_name)
# Migration from 3.6: add cost_price
if migrate_cost_price:
cursor.execute(*table.select(table.id, table.employee, table.date,
where=(table.cost_price == 0)
& (table.employee != Null)
& (table.date != Null)))
for line_id, employee_id, date in cursor.fetchall():
employee = Employee(employee_id)
cost_price = employee.compute_cost_price(date=date)
cursor.execute(*table.update(
[table.cost_price],
[cost_price],
where=table.id == line_id))
开发者ID:kret0s,项目名称:gnuhealth-live,代码行数:26,代码来源:timesheet.py
注:本文中的trytond.backend.get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论