# 0 = production, nothing on the console, email sent
# 1 = messages on the console, email sent
# 2 = messages on the console, but no email sent
# 3 = many messages on the console, no email sent
# 4 = many messages on the console, email sent to DEVELOPERADDR
DEBUGLEVEL=4
defupdate_date_lastrun(alert):
returnrun_sql('update user_query_basket set date_lastrun=%s where id_user=%s and id_query=%s and id_basket=%s;',(strftime("%Y-%m-%d"),alert[0],alert[1],alert[2],))
defget_alert_queries(frequency):
returnrun_sql('select distinct id, urlargs from query q, user_query_basket uqb where q.id=uqb.id_query and uqb.frequency=%s and uqb.date_lastrun <= now();',(frequency,))
defget_alert_queries_for_user(uid):
returnrun_sql('select distinct id, urlargs, uqb.frequency from query q, user_query_basket uqb where q.id=uqb.id_query and uqb.id_user=%s and uqb.date_lastrun <= now();',(uid,))
defget_alerts(query,frequency):
r=run_sql('select id_user, id_query, id_basket, frequency, date_lastrun, alert_name, notification from user_query_basket where id_query=%s and frequency=%s;',(query['id_query'],frequency,))
msg+='\n\n'+wrap('Only the first %s records are displayed above. Please consult the URL below to see all the results.'%MAXIDS)
returnmsg
defemail_notify(alert,records,argstr):
globalFROMADDR
globalALERTURL
globalDEBUGLEVEL
globalDEVELOPERADDR
iflen(records)==0:
return
msg=""
ifDEBUGLEVEL>0:
msg="*** THIS MESSAGE WAS SENT IN DEBUG MODE, DON'T TAKE IT INTO ACCOUNT ***\n\n"
msg+="Hello\n\n"
msg+=wrap("Below are the results of the email alert that you set up with the CERN Document Server. This is an automatic message, please don't reply to its address. For any question, use <%s> instead."%supportemail)