本文整理汇总了Python中c2corg_api.models.DBSession.add方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.add方法的具体用法?Python DBSession.add怎么用?Python DBSession.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c2corg_api.models.DBSession
的用法示例。
在下文中一共展示了DBSession.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: collection_post
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import add [as 别名]
def collection_post(self):
association = schema_association.objectify(self.request.validated)
association.parent_document_type = \
self.request.validated['parent_document_type']
association.child_document_type = \
self.request.validated['child_document_type']
if exists_already(association):
raise HTTPBadRequest(
'association (or its back-link) exists already')
DBSession.add(association)
DBSession.add(
association.get_log(self.request.authenticated_userid))
update_cache_version_associations(
[{'parent_id': association.parent_document_id,
'parent_type': association.parent_document_type,
'child_id': association.child_document_id,
'child_type': association.child_document_type}], [])
notify_es_syncer_if_needed(association, self.request)
update_feed_association_update(
association.parent_document_id, association.parent_document_type,
association.child_document_id, association.child_document_type,
self.request.authenticated_userid)
return {}
示例2: collection_delete
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import add [as 别名]
def collection_delete(self):
association_in = schema_association.objectify(self.request.validated)
association = self._load(association_in)
if association is None:
# also accept {parent_document_id: y, child_document_id: x} when
# for an association {parent_document_id: x, child_document_id: x}
association_in = Association(
parent_document_id=association_in.child_document_id,
child_document_id=association_in.parent_document_id)
association = self._load(association_in)
if association is None:
raise HTTPBadRequest('association does not exist')
if is_main_waypoint_association(association):
raise HTTPBadRequest(
'as the main waypoint of the route, this waypoint can not '
'be disassociated')
log = association.get_log(
self.request.authenticated_userid, is_creation=False)
DBSession.delete(association)
DBSession.add(log)
return {}
示例3: update_feed_document_create
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import add [as 别名]
def update_feed_document_create(document, user_id):
"""Creates a new entry in the feed table when creating a new document.
"""
if document.redirects_to or \
document.type in NO_FEED_DOCUMENT_TYPES:
return
# make sure all updates are written to the database, so that areas and
# users can be queried
DBSession.flush()
activities = []
if document.type in [ARTICLE_TYPE, OUTING_TYPE, ROUTE_TYPE]:
activities = document.activities
user_ids = [user_id]
if document.type == OUTING_TYPE:
participant_ids = _get_participants_of_outing(document.document_id)
user_ids = list(set(user_ids).union(participant_ids))
area_ids = []
if document.type != ARTICLE_TYPE:
area_ids = _get_area_ids(document)
change = DocumentChange(
user_id=user_id,
change_type='created',
document_id=document.document_id,
document_type=document.type,
activities=activities,
area_ids=area_ids,
user_ids=user_ids
)
DBSession.add(change)
DBSession.flush()
示例4: post
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import add [as 别名]
def post(self):
user = schema_create_user.objectify(self.request.validated)
user.password = self.request.validated['password']
user.update_validation_nonce(
Purpose.registration,
VALIDATION_EXPIRE_DAYS)
# directly create the user profile, the document id of the profile
# is the user id
lang = user.lang
user.profile = UserProfile(
categories=['amateur'],
locales=[DocumentLocale(lang=lang, title='')]
)
DBSession.add(user)
try:
DBSession.flush()
except:
log.warning('Error persisting user', exc_info=True)
raise HTTPInternalServerError('Error persisting user')
# also create a version for the profile
DocumentRest.create_new_version(user.profile, user.id)
# The user needs validation
email_service = get_email_service(self.request)
nonce = user.validation_nonce
settings = self.request.registry.settings
link = settings['mail.validate_register_url_template'] % nonce
email_service.send_registration_confirmation(user, link)
return to_json_dict(user, schema_user)
示例5: _collection_post
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import add [as 别名]
def _collection_post(
self, schema, before_add=None, after_add=None):
user_id = self.request.authenticated_userid
document_in = self.request.validated
document = schema.objectify(document_in)
document.document_id = None
if before_add:
before_add(document, user_id=user_id)
DBSession.add(document)
DBSession.flush()
DocumentRest.create_new_version(document, user_id)
if document.type != AREA_TYPE:
update_areas_for_document(document, reset=False)
if after_add:
after_add(document, user_id=user_id)
if document_in.get('associations', None):
create_associations(document, document_in['associations'], user_id)
notify_es_syncer(self.request.registry.queue_config)
return {'document_id': document.document_id}
示例6: _update_version
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import add [as 别名]
def _update_version(self, document, user_id, comment, update_types,
changed_langs):
assert user_id
assert update_types
meta_data = HistoryMetaData(comment=comment, user_id=user_id)
archive = self._get_document_archive(document, update_types)
geometry_archive = \
self._get_geometry_archive(document, update_types)
cultures = \
self._get_cultures_to_update(document, update_types, changed_langs)
locale_versions = []
for culture in cultures:
locale = document.get_locale(culture)
locale_archive = self._get_locale_archive(locale, changed_langs)
version = DocumentVersion(
document_id=document.document_id,
culture=locale.culture,
document_archive=archive,
document_geometry_archive=geometry_archive,
document_locales_archive=locale_archive,
history_metadata=meta_data
)
locale_versions.append(version)
DBSession.add(archive)
DBSession.add(meta_data)
DBSession.add_all(locale_versions)
DBSession.flush()
示例7: add_or_retrieve_token
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import add [as 别名]
def add_or_retrieve_token(value, expire, userid):
token = DBSession.query(Token).filter(Token.value == value and User.id == userid).first()
if not token:
token = Token(value=value, expire=expire, userid=userid)
DBSession.add(token)
DBSession.flush()
return token
示例8: collection_post
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import add [as 别名]
def collection_post(self):
association = schema_association.objectify(self.request.validated)
if exists_already(association):
raise HTTPBadRequest(
'association (or its back-link) exists already')
DBSession.add(association)
DBSession.add(
association.get_log(self.request.authenticated_userid))
return {}
示例9: post
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import add [as 别名]
def post(self):
user = schema_create_user.objectify(self.request.validated)
user.password = self.request.validated['password']
DBSession.add(user)
try:
DBSession.flush()
except:
# TODO: log the error for debugging
raise HTTPInternalServerError('Error persisting user')
return to_json_dict(user, schema_user)
示例10: _collection_post
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import add [as 别名]
def _collection_post(self, clazz, schema):
document = schema.objectify(self.request.validated)
document.document_id = None
# TODO additional validation: at least one culture, only one instance
# for each culture, geometry
DBSession.add(document)
DBSession.flush()
self._create_new_version(document)
return to_json_dict(document, schema)
示例11: _collection_post
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import add [as 别名]
def _collection_post(self, clazz, schema):
document = schema.objectify(self.request.validated)
document.document_id = None
DBSession.add(document)
DBSession.flush()
user_id = self.request.authenticated_userid
self._create_new_version(document, user_id)
sync_search_index(document)
return to_json_dict(document, schema)
示例12: add_association
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import add [as 别名]
def add_association(
parent_document_id, child_document_id, user_id, check_first=False):
"""Create an association between the two documents and create a log entry
in the association history table with the given user id.
"""
association = Association(
parent_document_id=parent_document_id,
child_document_id=child_document_id)
if check_first and exists_already(association):
return
DBSession.add(association)
DBSession.add(association.get_log(user_id, is_creation=True))
示例13: remove_association
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import add [as 别名]
def remove_association(
parent_document_id, child_document_id, user_id, check_first=False):
"""Remove an association between the two documents and create a log entry
in the association history table with the given user id.
"""
association = Association(
parent_document_id=parent_document_id,
child_document_id=child_document_id)
if check_first and not exists_already(association):
return
DBSession.query(Association).filter_by(
parent_document_id=parent_document_id,
child_document_id=child_document_id).delete()
DBSession.add(association.get_log(user_id, is_creation=False))
示例14: update_feed_images_upload
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import add [as 别名]
def update_feed_images_upload(images, images_in, user_id):
"""When uploading a set of images, create a feed entry for the document
the images are linked to.
"""
if not images or not images_in:
return
assert len(images) == len(images_in)
# get the document that the images were uploaded to
document_id, document_type = get_linked_document(images_in)
if not document_id or not document_type:
return
image1_id, image2_id, image3_id, more_images = get_images(
images, images_in, document_id, document_type)
if not image1_id:
return
# load the feed entry for the images
change = get_existing_change(document_id)
if not change:
log.warn('no feed change for document {}'.format(document_id))
return
if change.user_id == user_id:
# if the same user, only update time and change_type.
# this avoids that multiple entries are shown in the feed for the same
# document.
change.change_type = 'updated'
change.time = func.now()
else:
# if different user: copy the feed entry
change = change.copy()
change.change_type = 'added_photos'
change.user_id = user_id
change.user_ids = list(set(change.user_ids).union([user_id]))
change.image1_id = image1_id
change.image2_id = image2_id
change.image3_id = image3_id
change.more_images = more_images
DBSession.add(change)
DBSession.flush()
示例15: _create_new_version
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import add [as 别名]
def _create_new_version(self, document):
archive = document.to_archive()
archive_locales = document.get_archive_locales()
archive_geometry = document.get_archive_geometry()
meta_data = HistoryMetaData(comment='creation')
versions = []
for locale in archive_locales:
version = DocumentVersion(
document_id=document.document_id,
culture=locale.culture,
document_archive=archive,
document_locales_archive=locale,
document_geometry_archive=archive_geometry,
history_metadata=meta_data
)
versions.append(version)
DBSession.add(archive)
DBSession.add_all(archive_locales)
DBSession.add(meta_data)
DBSession.add_all(versions)
DBSession.flush()