本文整理匯總了Python中sngconnect.database.DBSession.flush方法的典型用法代碼示例。如果您正苦於以下問題:Python DBSession.flush方法的具體用法?Python DBSession.flush怎麽用?Python DBSession.flush使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sngconnect.database.DBSession
的用法示例。
在下文中一共展示了DBSession.flush方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: create_message
# 需要導入模塊: from sngconnect.database import DBSession [as 別名]
# 或者: from sngconnect.database.DBSession import flush [as 別名]
def create_message(self, message):
DBSession.add(message)
DBSession.flush()
if message.confirmation_required:
if message.feed is not None:
users = DBSession.query(User).join(
FeedUser
).filter(
FeedUser.feed == message.feed,
).all()
else:
users = DBSession.query(User).all()
self.confirmations.set_unconfirmed(
[user.id for user in users],
message.id
)
if message.send_notifications:
if message.feed is not None:
self.notification_service.notify_feed_users(
message.feed,
# TODO What to send in email subject and SMS notification?
"",
message
)
else:
self.notification_service.notify_all(
# TODO What to send in email subject and SMS notification?
"",
message
)
示例2: __call__
# 需要導入模塊: from sngconnect.database import DBSession [as 別名]
# 或者: from sngconnect.database.DBSession import flush [as 別名]
def __call__(self):
if 'access_data_streams' not in self.feed_permissions:
raise httpexceptions.HTTPUnauthorized()
message_service = MessageService(self.request.registry)
comment_form = forms.CommentForm(csrf_context=self.request)
minimal_value = DBSession.query(AlarmDefinition).filter(
AlarmDefinition.data_stream == self.data_stream,
AlarmDefinition.alarm_type == 'MINIMAL_VALUE'
).value('boundary')
if minimal_value is None:
default_minimal_value = self.data_stream.template.default_minimum
else:
default_minimal_value = minimal_value
maximal_value = DBSession.query(AlarmDefinition).filter(
AlarmDefinition.data_stream == self.data_stream,
AlarmDefinition.alarm_type == 'MAXIMAL_VALUE'
).value('boundary')
if maximal_value is None:
default_maximal_value = self.data_stream.template.default_maximum
else:
default_maximal_value = maximal_value
value_bounds_form = forms.ValueBoundsForm(
minimum=default_minimal_value,
maximum=default_maximal_value,
locale=get_locale_name(self.request),
csrf_context=self.request
)
last_data_point = (
data_streams_store.LastDataPoints().get_last_data_stream_data_point(
self.feed.id,
self.data_stream.id
)
)
if self.request.method == 'POST':
if 'submit_value_bounds' in self.request.POST:
value_bounds_form.process(self.request.POST)
if value_bounds_form.validate():
maximum_alarm = None
minimum_alarm = None
if minimal_value is None:
if value_bounds_form.minimum.data is not None:
minimum_alarm = AlarmDefinition(
data_stream=self.data_stream,
alarm_type='MINIMAL_VALUE',
boundary=value_bounds_form.minimum.data
)
DBSession.add(minimum_alarm)
else:
query = DBSession.query(AlarmDefinition).filter(
AlarmDefinition.data_stream == self.data_stream,
AlarmDefinition.alarm_type == 'MINIMAL_VALUE',
)
if value_bounds_form.minimum.data is not None:
query.update({
'boundary': value_bounds_form.minimum.data
})
minimum_alarm = query.one()
else:
query.delete()
minimum_alarm = None
if maximal_value is None:
if value_bounds_form.maximum.data is not None:
maximum_alarm = AlarmDefinition(
data_stream=self.data_stream,
alarm_type='MAXIMAL_VALUE',
boundary=value_bounds_form.maximum.data
)
DBSession.add(maximum_alarm)
else:
query = DBSession.query(AlarmDefinition).filter(
AlarmDefinition.data_stream == self.data_stream,
AlarmDefinition.alarm_type == 'MAXIMAL_VALUE',
)
if value_bounds_form.maximum.data is not None:
query.update({
'boundary': value_bounds_form.maximum.data
})
maximum_alarm = query.one()
else:
query.delete()
maximum_alarm = None
DBSession.flush()
alarms_on = []
alarms_off = []
if last_data_point is not None:
for alarm_definition in [minimum_alarm, maximum_alarm]:
if alarm_definition is None:
continue
if (alarm_definition.check_value(last_data_point[1]) is
None):
alarms_off.append(alarm_definition.id)
else:
alarms_on.append(alarm_definition.id)
alarms_store.Alarms().set_alarms_on(
self.feed.id,
self.data_stream.id,
alarms_on,
last_data_point[0]
)
alarms_store.Alarms().set_alarms_off(
#.........這裏部分代碼省略.........
示例3: feeds_new
# 需要導入模塊: from sngconnect.database import DBSession [as 別名]
# 或者: from sngconnect.database.DBSession import flush [as 別名]
def feeds_new(request):
try:
user = DBSession.query(User).filter(
User.id == authenticated_userid(request)
).one()
except database_exceptions.NoResultFound:
raise httpexceptions.HTTPForbidden()
feed_templates = DBSession.query(FeedTemplate).order_by(
sql.asc(FeedTemplate.name)
)
if user.role_maintainer == True:
forced_user = None
else:
forced_user = user
create_form = forms.CreateFeedForm(
feed_templates,
forced_user,
locale=get_locale_name(request),
csrf_context=request
)
if request.method == 'POST':
create_form.process(request.POST)
if create_form.validate():
feed = Feed()
create_form.populate_obj(feed)
feed.created = pytz.utc.localize(datetime.datetime.utcnow())
feed.regenerate_api_key()
feed.regenerate_activation_code()
DBSession.add(feed)
# need to save Feed within transaction to get it's key id
DBSession.flush([feed])
# create actual Datastreams for this Feed
data_stream_templates = DBSession.query(DataStreamTemplate).filter(
DataStreamTemplate.feed_template_id == feed.template_id
)
for data_stream_template in data_stream_templates:
DBSession.add(
DataStream(
template=data_stream_template,
feed=feed
)
)
# set up user permissions
feed_user = FeedUser(
feed=feed,
role='OWNER_BASIC'
)
if forced_user is None:
feed_user.user = create_form.get_owner()
feed_maintainer = FeedUser(
feed=feed,
user=user,
role='MAINTAINER_PLUS'
)
DBSession.add(feed_maintainer)
else:
feed_user.user = user
DBSession.add(feed_user)
request.session.flash(
_(
"New device has been added. Go to the device dashboard to"
" obtain the activation code."
),
queue='success'
)
return httpexceptions.HTTPFound(
request.route_url('sngconnect.telemetry.dashboard')
)
else:
request.session.flash(
_(
"There were some problems with your request."
" Please check the form for error messages."
),
queue='error'
)
return {
'create_form': create_form,
}