本文整理汇总了Python中sngconnect.database.DBSession.add方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.add方法的具体用法?Python DBSession.add怎么用?Python DBSession.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sngconnect.database.DBSession
的用法示例。
在下文中一共展示了DBSession.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: activate
# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import add [as 别名]
def activate(request):
"""
Activate the feed and get configuration.
"""
try:
feed_id = int(request.matchdict['feed_id'])
activation_code = request.POST['activation_code']
device_uuid = uuid.UUID(request.POST['device_uuid'])
except (KeyError, ValueError):
raise httpexceptions.HTTPNotFound("Invalid request arguments.")
try:
feed = DBSession.query(Feed).filter(Feed.id == feed_id).one()
except database_exceptions.NoResultFound:
raise httpexceptions.HTTPNotFound("Feed not found.")
if feed.activation_code == activation_code:
if not feed.has_activation_code_expired():
feed.regenerate_api_key()
feed.activation_code = None
feed.activation_code_regenerated = None
feed.device_uuid = device_uuid.hex
DBSession.add(feed)
cstruct = schemas.ActivateResponse().serialize({
'api_key': feed.api_key,
})
return Response(
json.dumps(cstruct),
content_type='application/json'
)
else:
raise httpexceptions.HTTPForbidden(
"This activation code has expired."
)
else:
raise httpexceptions.HTTPForbidden("Invalid activation code.")
示例2: create_message
# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import add [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
)
示例3: upload_log
# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import add [as 别名]
def upload_log(request):
"""
Store new piece of log sent by tinyputer. Logs can be sent as a response to 'upload_log' command
which created placeholder LogRequest objects.
Parameters:
log_request_id
log_request_hash
"""
try:
log_request_id = int(request.matchdict['log_request_id'])
log_request_hash = str(request.matchdict['log_request_hash'])
except (KeyError, ValueError):
raise httpexceptions.HTTPNotFound("Invalid request arguments.")
try:
log_request = DBSession.query(LogRequest).filter(
LogRequest.id == log_request_id,
LogRequest.hash == log_request_hash,
LogRequest.log == None
).one()
except database_exceptions.NoResultFound:
raise httpexceptions.HTTPNotFound("Log request not found.")
log_request.log = request.body
DBSession.add(log_request)
return Response()
示例4: test_normal_operation
# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import add [as 别名]
def test_normal_operation(self):
request = self.get_request(1)
response = views.commands(request)
self.assertEqual(response.status_code, 200)
self.assertDictEqual(response.json_body, {
'commands': [],
})
command = Command(
feed_id=1,
date=_utc_datetime(2012, 5, 17, 23, 4, 11),
command='upload_log',
arguments={
'url': 'http://example.org',
}
)
#with transaction.manager:
DBSession.add(command)
request = self.get_request(1)
response = views.commands(request)
self.assertEqual(response.status_code, 200)
self.assertDictEqual(response.json_body, {
u'commands': [
{
u'command': u'upload_log',
u'arguments': {
u'url': u'http://example.org',
},
},
],
})
示例5: __call__
# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import add [as 别名]
def __call__(self):
update_chart_form = forms.UpdateChartDefinitionForm(
self.chart_definition.id,
self.feed,
self.feed.template.data_stream_templates,
csrf_context=self.request
)
update_chart_form.process(self.request.POST)
data_stream_templates_dict = dict((
(template.id, template)
for template in self.feed.template.data_stream_templates
))
if update_chart_form.validate():
update_chart_form.populate_obj(self.chart_definition)
self.chart_definition.data_stream_templates = []
for id in update_chart_form.data_stream_template_ids.data:
self.chart_definition.data_stream_templates.append(
data_stream_templates_dict[id]
)
DBSession.add(self.chart_definition)
return Response(
json.dumps({
'redirect': None,
}),
content_type='application/json'
)
return Response(
json.dumps({
'errors': update_chart_form.errors,
}),
content_type='application/json'
)
示例6: sing_up
# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import add [as 别名]
def sing_up(request):
sign_up_form = forms.SignUpForm(csrf_context=request)
successful_submission = False
if request.method == 'POST':
sign_up_form.process(request.POST)
if sign_up_form.validate():
user = User(
email=sign_up_form.email.data.lower(),
phone=sign_up_form.phone.data,
name=sign_up_form.user_name.data,
company_name=(
sign_up_form.company_name.data
if sign_up_form.company_name.data else
None
),
timezone_tzname=str(request.registry['default_timezone'])
)
user.set_password(sign_up_form.password.data)
DBSession.add(user)
template = request.registry['jinja2_environment'].get_template(
'sngconnect.accounts:templates/emails/account_activation.txt'
)
activation_email = EmailMessage(
subject=_("Activate your account at SNG Connect"),
sender=request.registry['settings']['mail.sender'],
recipients=[user.email],
body=template.render(
activation_url=request.route_url(
'sngconnect.accounts.activate',
email=user.email,
email_activation_code=user.email_activation_code
)
)
)
get_mailer(request).send(activation_email)
sms_service = SMSService(request.registry)
sms_service.send_sms(
[user.phone],
_(
"Your SNG:connect confirmation code is: ${code}",
mapping={
'code': user.phone_activation_code,
}
)
)
successful_submission = True
return {
'sign_up_form': sign_up_form,
'successful_submission': successful_submission,
}
示例7: feed_templates
# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import add [as 别名]
def feed_templates(request):
feed_template_form = forms.AddFeedTemplateForm(csrf_context=request)
if request.method == 'POST':
feed_template_form.process(request.POST)
if feed_template_form.validate():
feed_template = FeedTemplate()
feed_template_form.populate_obj(feed_template)
DBSession.add(feed_template)
request.session.flash(
_("Device template has been successfully added."),
queue='success'
)
return httpexceptions.HTTPFound(
request.route_url('sngconnect.devices.feed_templates')
)
else:
request.session.flash(
_(
"There were some problems with your request."
" Please check the form for error messages."
),
queue='error'
)
feed_templates = DBSession.query(FeedTemplate).order_by(
FeedTemplate.name
)
return {
'feed_template_form': feed_template_form,
'feed_templates': [
{
'id': feed_template.id,
'name': feed_template.name,
'url': request.route_url(
'sngconnect.devices.feed_template',
feed_template_id=feed_template.id
),
'delete_url': request.route_url(
'sngconnect.devices.feed_template_delete',
feed_template_id=feed_template.id
),
'delete_form': forms.DeleteFeedTemplateForm(
csrf_context=request,
feed_template_id=feed_template.id
),
}
for feed_template in feed_templates
]
}
示例8: index
# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import add [as 别名]
def index(request):
order_maximum = int(
request.registry['settings']['sngconnect.payments.order_maximum']
)
token_prices = _get_token_prices(request.registry['settings'])
buy_form = forms.BuyForm(
order_maximum=order_maximum,
csrf_context=request
)
if request.method == 'POST':
buy_form.process(request.POST)
if buy_form.validate():
tokens = buy_form.tokens.data
user_service = UserService(request.registry)
user = user_service.get_user(authenticated_userid(request))
price = _get_price(tokens, token_prices)
order = Order(
status='PLACED',
placed=datetime.datetime.utcnow(),
user=user,
client_email=user.email,
audit_data=json.dumps({
'ip': request.client_addr,
'user_agent': request.user_agent,
'cookies': request.cookies.values(),
'accept_language': str(request.accept_language),
}),
tokens=tokens,
price_net=price['price_net'],
price_tax=price['price_tax'],
price_gross=price['price_gross'],
value_net=price['price_net'] * tokens,
value_tax=price['price_tax'] * tokens,
value_gross=price['price_gross'] * tokens
)
DBSession.add(order)
payment_backend = PayUPaymentBackend(
request,
request.route_url('sngconnect.payments.index'),
request.route_url('sngconnect.payments.confirmation')
)
payment_backend.process_order(order)
return httpexceptions.HTTPSeeOther(
)
return {
'token_prices': token_prices,
'buy_form': buy_form,
}
示例9: chart_definition
# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import add [as 别名]
def chart_definition(request):
try:
feed_template, chart_definition = DBSession.query(
FeedTemplate,
ChartDefinition
).filter(
FeedTemplate.id == request.matchdict['feed_template_id'],
(ChartDefinition.id ==
request.matchdict['chart_definition_id']),
ChartDefinition.feed_template_id == FeedTemplate.id,
ChartDefinition.feed == None
).one()
except database_exceptions.NoResultFound:
raise httpexceptions.HTTPNotFound()
data_stream_templates = DBSession.query(DataStreamTemplate).filter(
DataStreamTemplate.feed_template == feed_template
).order_by(DataStreamTemplate.name)
chart_definition_form = forms.UpdateChartDefinitionForm(
chart_definition.id,
feed_template,
data_stream_templates,
obj=chart_definition,
csrf_context=request
)
if request.method == 'POST':
chart_definition_form.process(request.POST)
data_stream_templates_dict = dict((
(template.id, template)
for template in data_stream_templates
))
if chart_definition_form.validate():
chart_definition_form.populate_obj(chart_definition)
chart_definition.data_stream_templates = []
for id in chart_definition_form.data_stream_template_ids.data:
chart_definition.data_stream_templates.append(
data_stream_templates_dict[id]
)
DBSession.add(chart_definition)
request.session.flash(
_("Parameter template has been successfully saved."),
queue='success'
)
return httpexceptions.HTTPFound(
request.route_url(
'sngconnect.devices.chart_definition',
feed_template_id=feed_template.id,
chart_definition_id=chart_definition.id
)
)
else:
request.session.flash(
_(
"There were some problems with your request."
" Please check the form for error messages."
),
queue='error'
)
return {
'chart_definition_form': chart_definition_form,
'feed_template': {
'id': feed_template.id,
'name': feed_template.name,
'url': request.route_url(
'sngconnect.devices.feed_template',
feed_template_id=feed_template.id
),
},
'chart_definition': {
'id': chart_definition.id,
'name': chart_definition.name,
'url': request.route_url(
'sngconnect.devices.chart_definition',
feed_template_id=feed_template.id,
chart_definition_id=chart_definition.id
),
},
}
示例10: data_stream_template
# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import add [as 别名]
def data_stream_template(request):
try:
feed_template, data_stream_template = DBSession.query(
FeedTemplate,
DataStreamTemplate
).filter(
FeedTemplate.id == request.matchdict['feed_template_id'],
(DataStreamTemplate.id ==
request.matchdict['data_stream_template_id']),
DataStreamTemplate.feed_template_id == FeedTemplate.id
).one()
except database_exceptions.NoResultFound:
raise httpexceptions.HTTPNotFound()
data_stream_template_form = forms.UpdateDataStreamTemplateForm(
feed_template_id=feed_template.id,
obj=data_stream_template,
csrf_context=request,
locale=get_locale_name(request)
)
if request.method == 'POST':
data_stream_template_form.process(request.POST)
if data_stream_template_form.validate():
data_stream_template_form.populate_obj(data_stream_template)
DBSession.add(data_stream_template)
request.session.flash(
_("Parameter template has been successfully saved."),
queue='success'
)
return httpexceptions.HTTPFound(
request.route_url(
'sngconnect.devices.data_stream_template',
feed_template_id=feed_template.id,
data_stream_template_id=data_stream_template.id
)
)
else:
request.session.flash(
_(
"There were some problems with your request."
" Please check the form for error messages."
),
queue='error'
)
return {
'data_stream_template_form': data_stream_template_form,
'feed_template': {
'id': feed_template.id,
'name': feed_template.name,
'url': request.route_url(
'sngconnect.devices.feed_template',
feed_template_id=feed_template.id
),
},
'data_stream_template': {
'id': data_stream_template.id,
'name': data_stream_template.name,
'url': request.route_url(
'sngconnect.devices.data_stream_template',
feed_template_id=feed_template.id,
data_stream_template_id=data_stream_template.id
),
},
}
示例11: feed_template
# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import add [as 别名]
def feed_template(request):
try:
feed_template = DBSession.query(FeedTemplate).filter(
FeedTemplate.id == request.matchdict['feed_template_id']
).one()
except database_exceptions.NoResultFound:
raise httpexceptions.HTTPNotFound()
data_stream_templates = DBSession.query(DataStreamTemplate).filter(
DataStreamTemplate.feed_template == feed_template
).order_by(DataStreamTemplate.name)
feed_template_form = forms.UpdateFeedTemplateForm(
obj=feed_template,
csrf_context=request
)
data_stream_template_form = forms.AddDataStreamTemplateForm(
feed_template_id=feed_template.id,
csrf_context=request,
locale=get_locale_name(request)
)
chart_definition_form = forms.AddChartDefinitionForm(
feed_template,
data_stream_templates,
csrf_context=request
)
change_image_form = forms.ChangeFeedTemplateImageForm(
csrf_context=request
)
if request.method == 'POST':
if 'submit_save_feed_template' in request.POST:
feed_template_form.process(request.POST)
if feed_template_form.validate():
feed_template_form.populate_obj(feed_template)
DBSession.add(feed_template)
request.session.flash(
_("Device template has been successfully saved."),
queue='success'
)
return httpexceptions.HTTPFound(
request.route_url(
'sngconnect.devices.feed_template',
feed_template_id=feed_template.id
)
)
else:
request.session.flash(
_(
"There were some problems with your request."
" Please check the form for error messages."
),
queue='error'
)
elif 'submit_add_data_stream_template' in request.POST:
data_stream_template_form.process(request.POST)
if data_stream_template_form.validate():
data_stream_template = DataStreamTemplate()
data_stream_template_form.populate_obj(data_stream_template)
DBSession.add(data_stream_template)
request.session.flash(
_("Parameter template has been successfully added."),
queue='success'
)
return httpexceptions.HTTPFound(
request.route_url(
'sngconnect.devices.feed_template',
feed_template_id=feed_template.id
)
)
else:
request.session.flash(
_(
"There were some problems with your request."
" Please check the form for error messages."
),
queue='error'
)
elif 'submit_add_chart_definition' in request.POST:
chart_definition_form.process(request.POST)
data_stream_templates_dict = dict((
(template.id, template)
for template in data_stream_templates
))
if chart_definition_form.validate():
chart_definition = ChartDefinition(
feed_template=feed_template
)
chart_definition_form.populate_obj(chart_definition)
for id in chart_definition_form.data_stream_template_ids.data:
chart_definition.data_stream_templates.append(
data_stream_templates_dict[id]
)
DBSession.add(chart_definition)
request.session.flash(
_("Chart has been successfully added."),
queue='success'
)
return httpexceptions.HTTPFound(
request.route_url(
'sngconnect.devices.feed_template',
feed_template_id=feed_template.id
)
#.........这里部分代码省略.........
示例12: inactive
# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import add [as 别名]
def inactive(request):
user_id = authenticated_userid(request)
try:
user = DBSession.query(User).filter(
User.id == user_id
).one()
except database_exceptions.NoResultFound:
raise httpexceptions.HTTPForbidden()
try:
feed = DBSession.query(Feed).filter(
Feed.id == request.matchdict['feed_id']
).one()
except database_exceptions.NoResultFound:
raise httpexceptions.HTTPNotFound()
try:
feed_user = DBSession.query(FeedUser).filter(
FeedUser.feed_id == feed.id,
FeedUser.user_id == user_id
).one()
except database_exceptions.NoResultFound:
raise httpexceptions.HTTPNotFound()
if feed_user.paid:
raise httpexceptions.HTTPSeeOther(
request.route_url(
'sngconnect.telemetry.feed_dashboard',
feed_id=feed.id
)
)
settings = request.registry['settings']
prices = {
'OWNER_STANDARD': int(settings['sngconnect.prices.owner_standard.activation']),
'OWNER_PLUS': int(settings['sngconnect.prices.owner_plus.activation']),
'MAINTAINER_PLUS': int(settings['sngconnect.prices.owner_plus.activation']),
}
price = prices[feed_user.role]
if request.method == 'POST':
if price <= user.tokens:
if user.last_payment is None:
user.last_payment = datetime.datetime.utcnow()
user.tokens -= price
DBSession.add(user)
feed_user.paid = True
DBSession.add(feed_user)
request.session.flash(
_("The feed has been successfully activated."),
queue='success'
)
return httpexceptions.HTTPSeeOther(
request.route_url(
'sngconnect.telemetry.feed_dashboard',
feed_id=feed.id
)
)
else:
request.session.flash(
_("You don't have enough tokens for setup fee."),
queue='error'
)
return {
'price': price,
}
示例13: create_test_data
# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import add [as 别名]
def create_test_data():
starting_id = 100000
feed_template = FeedTemplate(
id=starting_id,
name=u"Licznik prądu",
dashboard_layout="GAUGES",
modbus_bandwidth=9600,
modbus_port='/dev/ttyS0',
modbus_parity='EVEN',
modbus_data_bits=8,
modbus_stop_bits=1,
modbus_timeout=5,
modbus_endianness='BIG',
modbus_polling_interval=120
)
feed = Feed(
id=starting_id,
template=feed_template,
name=u"Licznik energii Saia-Burgess ALE3",
description=u"Licznik prądu w biurze Synergii w Warszawie",
address=u"ul. Bysławska 82 lok. 312\n04-993 Warszawa",
latitude=52.158427,
longitude=21.198292,
api_key='pnqt1tgDLBbzoghjCBDrpcD2NXUCP1WGFUDwm7baQTgmgueS5eU5c4W9EpLrnorJKC4DMfKe255YbwPvAJ7ppbD21NAs8XLk4XQb',
created=pytz.utc.localize(datetime.datetime.utcnow())
)
feed.regenerate_activation_code()
user = DBSession.query(User).filter(User.email == '[email protected]').one()
feed_user = FeedUser(
id=starting_id,
feed=feed,
user=user,
role='OWNER_PLUS'
)
DBSession.add_all([feed_template, feed, feed_user])
data_stream_templates = [
DataStreamTemplate(
id=starting_id,
feed_template=feed_template,
label='t1_total',
name='t1_total',
measurement_unit='0.01 kWh',
writable=False,
modbus_register_type='HOLDING',
modbus_slave=1,
modbus_address=27,
modbus_count=2,
show_on_dashboard=True,
default_minimum=0,
default_maximum=100,
),
DataStreamTemplate(
id=starting_id + 1,
feed_template=feed_template,
label='t2_total',
name='t2_total',
measurement_unit='0.01 kWh',
writable=False,
modbus_register_type='HOLDING',
modbus_slave=1,
modbus_address=31,
modbus_count=2,
show_on_dashboard=True,
default_minimum=0,
default_maximum=100,
),
DataStreamTemplate(
id=starting_id + 2,
feed_template=feed_template,
label='baud',
name='baud',
measurement_unit='baud',
writable=False,
modbus_register_type='HOLDING',
modbus_slave=1,
modbus_address=2,
modbus_count=2
),
DataStreamTemplate(
id=starting_id + 3,
feed_template=feed_template,
label='version',
name='version',
measurement_unit='.',
writable=False,
modbus_register_type='HOLDING',
modbus_slave=1,
modbus_address=0,
modbus_count=1
),
DataStreamTemplate(
id=starting_id + 4,
feed_template=feed_template,
label='phase1_URMS',
name='phase1_URMS',
measurement_unit='V',
writable=False,
modbus_register_type='HOLDING',
modbus_slave=1,
modbus_address=35,
#.........这里部分代码省略.........
示例14: settings
# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import add [as 别名]
def settings(request):
user = DBSession.query(User).filter(
User.id == security.authenticated_userid(request)
).one()
change_account_data_form = forms.ChangeAccountDataForm(
obj=user,
csrf_context=request
)
change_notification_settings_form = forms.ChangeNotificationSettings(
obj=user,
csrf_context=request
)
change_password_form = forms.ChangePasswordForm(csrf_context=request)
if request.method == 'POST':
if 'submit_change_account_data' in request.POST:
change_account_data_form.process(request.POST)
if change_account_data_form.validate():
change_account_data_form.populate_obj(user)
DBSession.add(user)
request.session.flash(
_("Your account data has been successfully changed."),
queue='success'
)
return httpexceptions.HTTPFound(
request.route_url('sngconnect.accounts.settings')
)
if 'submit_change_notification_settings' in request.POST:
change_notification_settings_form.process(request.POST)
if change_notification_settings_form.validate():
change_notification_settings_form.populate_obj(user)
DBSession.add(user)
request.session.flash(
_(
"Your notification settings have been successfully"
" changed."
),
queue='success'
)
return httpexceptions.HTTPFound(
request.route_url('sngconnect.accounts.settings')
)
elif 'submit_change_password' in request.POST:
change_password_form.process(request.POST)
if change_password_form.validate():
user.set_password(change_password_form.password.data)
DBSession.add(user)
request.session.flash(
_("Your password has been successfully changed."),
queue='success'
)
return httpexceptions.HTTPFound(
request.route_url('sngconnect.accounts.settings')
)
request.session.flash(
_(
"There were some problems with your request."
" Please check the form for error messages."
),
queue='error'
)
return {
'change_account_data_form': change_account_data_form,
'change_notification_settings_form': change_notification_settings_form,
'change_password_form': change_password_form,
}
示例15: __call__
# 需要导入模块: from sngconnect.database import DBSession [as 别名]
# 或者: from sngconnect.database.DBSession import add [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(
#.........这里部分代码省略.........