本文整理汇总了Python中penelope.core.models.DBSession.add方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.add方法的具体用法?Python DBSession.add怎么用?Python DBSession.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类penelope.core.models.DBSession
的用法示例。
在下文中一共展示了DBSession.add方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_initial_application_acl
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import add [as 别名]
def create_initial_application_acl(mapper, connection, target):
if target.application_type == SVN:
acl_rules = [
('internal_developer', 'edit'),
('internal_developer', 'view'),
('external_developer', 'edit'),
('external_developer', 'view'),
]
else:
acl_rules = [
('internal_developer', 'view'),
('external_developer', 'view'),
('secretary', 'view'),
('secretary', 'edit'),
]
if target.application_type == 'trac':
acl_rules.append(('customer', 'view'))
for role_id, permission_name in acl_rules:
acl = DBSession.query(ApplicationACL).get((target.id, role_id, permission_name))
if not acl:
acl = ApplicationACL(application_id=target.id,
role_id=role_id,
permission_name=permission_name)
DBSession.add(acl)
else:
# XXX this should not happen.
pass
示例2: test_get_user_by_attribute
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import add [as 别名]
def test_get_user_by_attribute(self):
session = DBSession()
user = User(email=u'[email protected]')
session.add(user)
transaction.commit()
#Get the user by email
resp = self.proxy.get_user_by_email('[email protected]')
self.assertEqual(resp['email'], u'[email protected]')
示例3: test_get_customer_by_name
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import add [as 别名]
def test_get_customer_by_name(self):
customer_name = u'A rich customer'
session = DBSession()
customer = Customer(name=customer_name)
session.add(customer)
transaction.commit()
resp = self.proxy.get_customer_by_name(customer_name)
self.assertEqual(resp['name'], customer_name)
示例4: test_get_user_by_openid
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import add [as 别名]
def test_get_user_by_openid(self):
session = DBSession()
user = User(email=u'[email protected]')
user.add_openid(u'[email protected]')
session.add(user)
transaction.commit()
resp = self.proxy.get_user_by_openid('[email protected]')
self.assertTrue(u'[email protected]' in resp['openids'])
示例5: autoregister
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import add [as 别名]
def autoregister(profile):
session = DBSession()
chars = string.letters + string.digits
password = ''.join(choice(chars) for _ in range(9))
user = User(fullname = profile.get('displayName'),
email = profile.get('emails')[0])
user.set_password(password)
user.add_openid(profile.get('accounts')[0].get('username'))
session.add(user)
return user
示例6: test_get_project_by_name
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import add [as 别名]
def test_get_project_by_name(self):
project_name = u'A nice project'
customer_name = u'A good customer'
session = DBSession()
project = Project(name=project_name)
customer = Customer(name=customer_name)
customer.add_project(project)
session.add(customer)
transaction.commit()
resp = self.proxy.get_project_by_name(project_name)
self.assertEqual(resp['name'], project_name)
示例7: security_save
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import add [as 别名]
def security_save(self):
context = self.context.get_instance()
for acl in context.acl:
DBSession.delete(acl)
for checkbox_name in self.request.POST:
role_id, permission_name = checkbox_name.split('.')
acl = ApplicationACL(application_id=context.id,
role_id=role_id,
permission_name=permission_name)
DBSession.add(acl)
request = self.request
return HTTPFound(location=request.fa_url(request.model_name, request.model_id, 'security'))
示例8: save_query
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import add [as 别名]
def save_query(context, request):
current_uid = request.authenticated_user.id
query_meta = cgi.parse_qs(request.POST['query_meta'])
if not 'query_name' in query_meta:
return Response(u"Please specify a query name.", status=409)
query_name = query_meta['query_name'][0]
taken = DBSession.query(SavedQuery).filter(SavedQuery.author_id==current_uid).filter(SavedQuery.query_name==query_name).count()
submit_type = request.POST['submit_type']
if submit_type == 'submit_edit':
if taken:
return Response(u"Name already in use: '%s'." % query_name, status=409)
sq_id = query_meta['sq_id'][0]
qry = DBSession.query(SavedQuery)
qry = qry.filter(SavedQuery.author_id==current_uid)
qry = qry.filter(SavedQuery.id==sq_id)
sq = qry.one()
sq.query_name = query_name
return Response(u"The query has been renamed as '%s'." % query_name)
elif submit_type == 'submit_delete':
sq_id = query_meta['sq_id'][0]
qry = DBSession.query(SavedQuery)
qry = qry.filter(SavedQuery.author_id==current_uid)
qry = qry.filter(SavedQuery.id==sq_id)
sq = qry.one()
DBSession.delete(sq)
return Response(u"The saved query has been deleted.")
elif submit_type == 'submit_add':
if taken:
return Response(u"Name already in use: '%s'." % query_name, status=409)
# add
sq = SavedQuery(query_name=query_name,
report_name=query_meta['report_name'][0],
query_string=request.POST['query_string'],
author_id = current_uid)
DBSession.add(sq)
return Response(u"The query has been saved as '%s'." % query_name)
示例9: password_reset
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import add [as 别名]
def password_reset(request):
email = request.params.get('email')
try:
session = DBSession()
user = DBSession.query(User).filter_by(email=email).one()
ptoken = DBSession.query(PasswordResetToken).get(user.id)
if not ptoken:
ptoken = PasswordResetToken(user_id=user.id)
token = str(uuid4())
ptoken.token = token
session.add(ptoken)
except NoResultFound:
token = None
if token:
settings = request.registry.settings
if not settings:
return {'request': request, 'token': token}
notify_with_password_reset(email, token)
return {'request': request, 'token': token}
示例10: test_project_attributes
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import add [as 别名]
def test_project_attributes(self):
project_name = u'Another nice project'
customer_name = u'A very good customer'
session = DBSession()
project = Project(name=project_name)
customer = Customer(name=customer_name)
customer.add_project(project)
applications1 = Application(name=u'Trac')
applications2 = Application(name=u'Svn')
customerR1 = CustomerRequest(name=u'A bad request')
customerR2 = CustomerRequest(name=u'A good request')
project.add_application(applications1)
project.add_application(applications2)
project.add_customer_request(customerR1)
project.add_customer_request(customerR2)
session.add(customer)
transaction.commit()
resp = self.proxy.get_project_by_name(project_name)
self.assertTrue(u'Trac' in resp['applications'])
self.assertTrue(u'another-nice-project_1' in [item for sublist in resp['customer_requests'] for item in sublist])
self.assertTrue(u'another-nice-project_2' in [item for sublist in resp['customer_requests'] for item in sublist])
self.assertTrue(2, len(resp['customer_requests']))
self.assertTrue(2, len(resp['applications']))
示例11: timeentry_crstate_validation_errors
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import add [as 别名]
crstate_errors = timeentry_crstate_validation_errors(entry_project, [entry_ticket], request)
if crstate_errors:
return {
'state': False,
'message': '\n'.join(crstate_errors),
}
time_entry = TimeEntry(date = entry_date,
hours = entry_time_delta,
location = entry_location,
description = entry_description,
ticket = entry_ticket)
time_entry.request = request # bind for user lookup
time_entry.project_id = entry_project
session.add(time_entry)
session.flush()
return {
'status': True,
'message': u'Correctly added time entry %s for %s ticket #%s' % (time_entry.id, entry_project, entry_ticket),
}
@jsonrpc_method(endpoint='DashboardAPI')
def create_new_advanced_time_entry(request, entry_ticket, entry_start, entry_end,
entry_description, entry_location, entry_project):
"""
Time entry creation: simple time entry case
"""
示例12: add_user
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import add [as 别名]
def add_user(self, email):
session = DBSession()
user = User(email=email)
session.add(user)
transaction.commit()
示例13: test_time_entry_creation
# 需要导入模块: from penelope.core.models import DBSession [as 别名]
# 或者: from penelope.core.models.DBSession import add [as 别名]
def test_time_entry_creation(self):
"""
This test check time entry parameters
"""
#customer data
customer_name = u'RFCCustomer'
#project data
project_name = u'A new project'
project_id = 'a-new-project'
#entry data
entry_date = datetime.date(2011, 05, 26)
entry_hours = '2:30'
entry_location = u'RedTurtle Technology'
entry_description = u'Trying to create ticket for API tests'
entry_ticket = '45'
#Start to create customer, project and time entry for project
session = DBSession()
project = Project(name=project_name, id=project_id)
customer = Customer(name=customer_name)
customer.add_project(project)
session.add(customer)
transaction.commit()
#Try to get errors
resp = self.proxy.create_new_simple_time_entry(1, entry_date,
entry_hours, entry_description,
entry_location, project_id)
self.assertEqual(resp['message'], u"'int' object has no attribute 'decode'")
resp = self.proxy.create_new_simple_time_entry(entry_ticket,
entry_date,
u'9000',
entry_description,
entry_location,
project_id)
self.assertEqual(resp['message'], u'Cannot parse time (must be HH:MM)')
resp = self.proxy.create_new_simple_time_entry(entry_ticket,
entry_date,
u'19:40',
entry_description,
entry_location,
project_id)
self.assertEqual(resp['message'], u'Time value too big (must be <= 16:00)')
resp = self.proxy.create_new_simple_time_entry(entry_ticket,
entry_date,
entry_hours,
entry_description,
entry_location,
100)
self.assertEqual(resp['message'], u'Not able to get the project with id 100')
resp = self.proxy.create_new_simple_time_entry(entry_ticket,
'2011 01 01',
entry_hours,
entry_description,
entry_location,
100)
self.assertEqual(resp['message'], u"time data '2011 01 01' does not match format '%Y-%m-%d'")
#Let's try to create a simple time entry
resp = self.proxy.create_new_simple_time_entry(entry_ticket,
entry_date,
entry_hours,
entry_description,
entry_location,
project_id)
self.assertRegexpMatches(resp['message'], u'Correctly added time entry \d+ for %s ticket #%s' %(project_id, entry_ticket))
resp = self.proxy.create_new_simple_time_entry(entry_ticket,
entry_date,
entry_hours,
'',
entry_location,
project_id)
self.assertEqual(resp['message'], u"Description is required.")
#Now try to create a more complex time entry
entry_start = datetime.datetime(2011, 01, 01, 15, 30)
entry_end = datetime.datetime(2011, 01, 01, 17, 30)
entry_ticket = '#99'
resp = self.proxy.create_new_advanced_time_entry(99,
entry_start,
entry_end,
entry_description,
entry_location,
10)
self.assertEqual(resp['message'], u"'int' object has no attribute 'decode'")
resp = self.proxy.create_new_advanced_time_entry(entry_ticket,
entry_start,
entry_end,
entry_description,
entry_location,
#.........这里部分代码省略.........