def refresh_alerts(request, random=None): try: from datetime import datetime cmd_list = [] #this command will insert or update the row value if the row with the user exists. cmd = ["INSERT OR REPLACE INTO admin_alerts (user, last_refresh_time) values (?,?);", (request.user.username, datetime.now())] cmd_list.append(cmd) db_path, err = common.get_db_path() if err: raise Exception(err) test, err = db.execute_iud("%s/integral_view_config.db"%db_path, cmd_list) if err: raise Exception(err) new_alerts_present, err = alerts.new_alerts() if err: raise Exception(err) if new_alerts_present: import json alerts_list, err = alerts.load_alerts() if err: raise Exception(err) if not alerts_list: raise Exception('Error loading alerts') new_alerts = json.dumps([dict(alert=pn) for pn in alerts_list]) return django.http.HttpResponse(new_alerts, mimetype='application/json') else: clss = "btn btn-default btn-sm" message = "View alerts" return django.http.HttpResponse("No New Alerts") except Exception, e: return django.http.HttpResponse("Error loading alerts : %s"%str(e))
def refresh_alerts(request, random=None): try: from datetime import datetime cmd_list = [] #this command will insert or update the row value if the row with the user exists. cmd = ["INSERT OR REPLACE INTO admin_alerts (user, last_refresh_time) values (?,?);", (request.user.username, datetime.now())] cmd_list.append(cmd) db_path, err = common.get_db_path() if err: raise Exception(err) test, err = db.execute_iud(db_path, cmd_list) if err: raise Exception(err) new_alerts_present, err = alerts.new_alerts() if err: raise Exception(err) if new_alerts_present: import json alerts_list, err = alerts.load_alerts(last_n = 5) if err: raise Exception(err) if not alerts_list: raise Exception('Error loading alerts') new_alerts = json.dumps([dict(alert=pn) for pn in alerts_list]) return django.http.HttpResponse(new_alerts, content_type='application/json') else: clss = "btn btn-default btn-sm" message = "View alerts" return django.http.HttpResponse("No New Alerts") except Exception, e: return django.http.HttpResponse("Error loading alerts : %s"%str(e))
def refresh_alerts(request, random=None): from datetime import datetime cmd_list = [] #this command will insert or update the row value if the row with the user exists. cmd = ["INSERT OR REPLACE INTO admin_alerts (user, last_refresh_time) values (?,?);", (request.user.username, datetime.now())] cmd_list.append(cmd) test = db.execute_iud("%s/integral_view_config.db"%common.get_db_path(), cmd_list) if alerts.new_alerts(): import json new_alerts = json.dumps([dict(alert=pn) for pn in alerts.load_alerts()]) return django.http.HttpResponse(new_alerts, mimetype='application/json') else: clss = "btn btn-default btn-sm" message = "View alerts" return django.http.HttpResponse("No New Alerts")