alert_link.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # -*- coding:utf-8 -*-
  2. # Copyright 2017 Xiaomi, Inc.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. __author__ = 'Ulric Qin'
  16. from rrd import app
  17. from flask import render_template, request
  18. from rrd.utils import random_string
  19. from rrd.model.portal.alert_link import AlertLink
  20. @app.route('/portal/links/<path>', methods=["GET",])
  21. def portal_links(path):
  22. vs = AlertLink.select_vs(where='path=%s', params=[path])
  23. sms_strings = []
  24. if vs:
  25. sms_strings = vs[0].content.split(',,')
  26. return render_template('portal/alert_link/index.html', **locals())
  27. @app.route('/portal/links/store', methods=['POST'])
  28. def portal_links_store():
  29. sms_strings = request.get_data()
  30. path = random_string(8)
  31. ids = AlertLink.column('id', where='path=%s', params=[path])
  32. if ids:
  33. AlertLink.update_dict({'content': sms_strings}, where='id=%s', params=[ids[0]])
  34. else:
  35. AlertLink.insert({'path': path, 'content': sms_strings})
  36. return path