本文整理汇总了Python中autonomie.models.company.Company类的典型用法代码示例。如果您正苦于以下问题:Python Company类的具体用法?Python Company怎么用?Python Company使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Company类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_company
def add_company(self, name, user):
"""
Add a company 'name' in the database
( set its goal by default )
"""
log.info(u"Adding company : %s" % name)
company = Company()
company.name = name
company.goal = u"Entreprise de {0}".format(format_account(user))
company.contribution = self.request.config.get('contribution_cae')
company = self.dbsession.merge(company)
self.dbsession.flush()
return company
示例2: company2
def company2(dbsession, user):
from autonomie.models.company import Company
company = Company(
name=u"Company 2",
email=u"[email protected]",
)
company.employees = [user]
dbsession.add(company)
dbsession.flush()
user.companies = [company]
user = dbsession.merge(user)
dbsession.flush()
return company
示例3: other_company
def other_company(dbsession, other_user):
from autonomie.models.company import Company
company = Company(
name=u"Company2",
email=u"[email protected]",
code_compta="0USER2",
)
company.employees = [other_user]
dbsession.add(company)
dbsession.flush()
other_user.companies = [company]
other_user = dbsession.merge(other_user)
dbsession.flush()
return company
示例4: TestCompanyModel
class TestCompanyModel(BaseTestCase):
def setUp(self):
BaseTestCase.setUp(self)
self.company = Company(name=u"Test", id=1)
self.company.logo = dict(filename=u"logo.png")
self.company.header = dict(filename=u"header.png")
def test_get_path(self):
self.assertEqual(self.company.get_path(), "company/1")
self.assertEqual(self.company.get_logo_filepath(), "company/1/logo/logo.png")
self.assertEqual(self.company.get_header_filepath(), "company/1/header/header.png")
def test_get_company_id(self):
self.assertEqual(self.company.get_company_id(), 1)
示例5: _mk_company
def _mk_company(name, email, code_compta):
from autonomie.models.company import Company
company = Company(
name=name,
email=email,
code_compta=code_compta,
)
company.employees = [user]
dbsession.add(company)
dbsession.flush()
user.companies = [company]
dbsession.merge(user)
dbsession.flush()
return company
示例6: add_company
def add_company(user, company_name, goal=""):
company = Company()
company.name = company_name
company.goal = goal or u"Entreprise de %s" % user.login
user.companies.append(company)
session = DBSESSION()
session.add(company)
session.flush()
print "Added company for %s: %s" % (user.login, company_name)
return company
示例7: gen_companies
def gen_companies(self):
"""
Generate companies as expected
"""
from autonomie.models.company import Company
companies = []
for data in self.activity_companydatas:
# Try to retrieve an existing company (and avoid duplicates)
company = Company.query().filter(
Company.name == data.name
).first()
if company is None:
company = Company(
name=data.name,
goal=data.title,
email=self.coordonnees_email1,
phone=self.coordonnees_tel,
mobile=self.coordonnees_mobile,
)
if data.activity is not None:
company.activities.append(data.activity)
company.employees.append(self.user)
companies.append(company)
return companies
示例8: get_company_by_code
def get_company_by_code(code_compta):
"""
Return the company associated to this code_compta
:param str code_compta: The analytic code of the company to find
"""
query = Company.query().filter(Company.code_compta==code_compta)
return query.first()
示例9: submit_success
def submit_success(self, appstruct):
"""
Insert config informations into database
"""
# la table config étant un stockage clé valeur
# le merge_session_with_post ne peut être utilisé
dbdatas = Config.query().all()
log.debug(u"Cae configuration submission")
log.debug(appstruct)
new_dbdatas = merge_config_datas(dbdatas, appstruct)
for dbdata in new_dbdatas:
log.debug(dbdata.name)
if dbdata in dbdatas:
self.dbsession.merge(dbdata)
else:
self.dbsession.add(dbdata)
# If we set the contribution_cae value, we want it to be the default
# for every company that has no contribution value set
if dbdata.name == 'contribution_cae':
for comp in Company.query():
if comp.contribution is None:
comp.contribution = dbdata.value
self.dbsession.merge(comp)
self.dbsession.flush()
self.request.session.flash(self.validation_msg)
return HTTPFound(self.request.route_path("admin_cae"))
示例10: submit_success
def submit_success(self, appstruct):
"""
Edit the database entry and return redirect
"""
user_id = appstruct.get("user_id")
company = Company()
company.activities = fetch_activities_objects(appstruct)
company = merge_session_with_post(company, appstruct)
if user_id is not None:
user_account = User.get(user_id)
if user_account is not None:
company.employees.append(user_account)
self.dbsession.add(company)
self.dbsession.flush()
message = u"L'entreprise '{0}' a bien été ajoutée".format(company.name)
self.session.flash(message)
return HTTPFound(self.request.route_path("company", id=company.id))
示例11: upgrade
def upgrade():
from autonomie.models.company import Company
from autonomie.models.files import File
from autonomie.models import DBSESSION
from alembic.context import get_bind
from autonomie.models.config import ConfigFiles
for i in ('header_id', 'logo_id',):
col = sa.Column(i, sa.Integer, sa.ForeignKey('file.id'))
op.add_column('company', col)
query = "select id, header, logo from company;"
conn = get_bind()
result = conn.execute(query)
session = DBSESSION()
for id_, header, logo in result:
company = Company.get(id_)
basepath = u"%scompany/%s" % (BASEFILEPATH, id_,)
if header:
header_path = u"%s/header/%s" % (basepath, header)
try:
file_datas = load_file_struct(header_path, header)
except:
print("Error while loading a header")
print(id_)
file_datas = None
if file_datas:
company.header = file_datas
session.add(company.header_file)
session.flush()
if logo:
logo_path = u"%s/logo/%s" % (basepath, logo)
try:
file_datas = load_file_struct(logo_path, logo)
except:
print("Error while loading a logo")
print(id_)
file_datas = None
if file_datas:
company.logo = file_datas
company = session.merge(company)
session.flush()
filepath = u"%s/main/logo.png" % BASEFILEPATH
if os.path.isfile(filepath):
ConfigFiles.set('logo.png', load_file_struct(filepath, 'logo.png'))
filepath = u"%s/main/accompagnement_header.png" % BASEFILEPATH
if os.path.isfile(filepath):
ConfigFiles.set(
'accompagnement_header.png',
load_file_struct(filepath, 'accompagnement_header.png')
)
示例12: get_company
def get_company(self, name, user):
"""
Return a company object, create a new one if needed
"""
company = Company.query().filter(Company.name==name).first()
#avoid creating duplicate companies
if company is None:
company = self.add_company(name, user)
return company
示例13: get_companies
def get_companies(request):
"""
Retrieve the companies the current user has access to
"""
companies = []
if request.user.is_admin() or request.user.is_manager():
companies = Company.query().all()
else:
companies = request.user.companies
return companies
示例14: customer
def customer(config, content, get_csrf_request_with_db):
config.add_route('customer', '/')
request = get_csrf_request_with_db()
comp = Company.query().first()
comp.__name__ = 'company'
request.context = comp
request.user = get_user()
view = CustomerAdd(request)
view.submit_success(APPSTRUCT)
return getOne()
示例15: project
def project(config, get_csrf_request_with_db):
from autonomie.views.project import ProjectAdd
config.add_route('project', '/')
req = get_csrf_request_with_db()
company = Company.query().first()
company.__name__ = 'company'
req.context = company
view = ProjectAdd(req)
appstruct = APPSTRUCT.copy()
view.submit_success(appstruct)
return getone()