diff --git a/modules/webalert/lib/webalert.py b/modules/webalert/lib/webalert.py index 2a3833309..73634855b 100644 --- a/modules/webalert/lib/webalert.py +++ b/modules/webalert/lib/webalert.py @@ -1,373 +1,373 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """PERSONAL FEATURES - YOUR ALERTS""" import cgi import time from invenio.config import weburl, cdslang from invenio.dbquery import run_sql from invenio.webuser import isGuestUser from invenio.webaccount import warning_guest_user from invenio.webbasket import create_personal_baskets_selection_box from invenio.messages import gettext_set_language from invenio.dateutils import convert_datestruct_to_datetext, convert_datetext_to_dategui import invenio.template webalert_templates = invenio.template.load('webalert') ### IMPLEMENTATION class AlertError(Exception): pass def check_alert_name(alert_name, uid, ln=cdslang): """check this user does not have another alert with this name.""" sql = """select id_query from user_query_basket where id_user=%s and alert_name='%s'"""%(uid, alert_name.strip()) res = run_sql( sql ) # load the right message language _ = gettext_set_language(ln) if len( run_sql( sql ) ) > 0: raise AlertError( _("You already have an alert which name is %(name)s") % {'name' : alert_name} ) def get_textual_query_info_from_urlargs(urlargs, ln=cdslang): """Return nicely formatted search pattern and catalogue from urlargs of the search query. Suitable for 'your searches' display.""" out = "" args = cgi.parse_qs(urlargs) return webalert_templates.tmpl_textual_query_info_from_urlargs( ln = ln, args = args, ) return out def perform_display(permanent, uid, ln=cdslang): """display the searches performed by the current user input: default permanent="n"; permanent="y" display permanent queries(most popular) output: list of searches in formatted html """ # load the right message language _ = gettext_set_language(ln) # first detect number of queries: nb_queries_total = 0 nb_queries_distinct = 0 id_queries_distinct = [] query = "SELECT COUNT(*),COUNT(DISTINCT(id_query)) FROM user_query WHERE id_user=%s" res = run_sql(query, (uid,), 1) try: nb_queries_total = res[0][0] nb_queries_distinct = res[0][1] except: pass # query for queries: if permanent == "n": SQL_query = "SELECT DISTINCT(q.id),q.urlargs "\ "FROM query q, user_query uq "\ "WHERE uq.id_user='%s' "\ "AND uq.id_query=q.id "\ "ORDER BY q.id DESC" % uid else: # permanent="y" SQL_query = "SELECT q.id,q.urlargs "\ "FROM query q "\ "WHERE q.type='p'" query_result = run_sql(SQL_query) queries = [] if len(query_result) > 0: for row in query_result : if permanent == "n": res = run_sql("SELECT DATE_FORMAT(MAX(date),'%%Y-%%m-%%d %%H:%%i:%%s') FROM user_query WHERE id_user=%s and id_query=%s", (uid, row[0])) try: lastrun = res[0][0] except: lastrun = _("unknown") else: lastrun = "" queries.append({ 'id' : row[0], 'args' : row[1], 'textargs' : get_textual_query_info_from_urlargs(row[1], ln=ln), 'lastrun' : lastrun, }) return webalert_templates.tmpl_display_alerts( ln = ln, permanent = permanent, nb_queries_total = nb_queries_total, nb_queries_distinct = nb_queries_distinct, queries = queries, guest = isGuestUser(uid), guesttxt = warning_guest_user(type="alerts", ln=ln), weburl = weburl ) def perform_input_alert(action, id_query, alert_name, frequency, notification, id_basket,uid, old_id_basket=None, ln = cdslang): """get the alert settings input: action="add" for a new alert (blank form), action="modify" for an update (get old values) id_query id the identifier of the search to be alerted for the "modify" action specify old alert_name, frequency of checking, e-mail notification and basket id. output: alert settings input form""" # display query information res = run_sql("SELECT urlargs FROM query WHERE id=%s", (id_query,)) try: urlargs = res[0][0] except: urlargs = "UNKNOWN" baskets = create_personal_baskets_selection_box(uid=uid, html_select_box_name='idb', selected_bskid=old_id_basket, ln=cdslang) return webalert_templates.tmpl_input_alert( ln = ln, query = get_textual_query_info_from_urlargs(urlargs, ln = ln), action = action, frequency = frequency, notification = notification, alert_name = alert_name, baskets = baskets, old_id_basket = old_id_basket, id_basket = id_basket, id_query = id_query, ) def check_alert_is_unique(id_basket, id_query, uid, ln=cdslang ): """check the user does not have another alert for the specified query and basket""" _ = gettext_set_language(ln) sql = """select id_query from user_query_basket where id_user = %s and id_query = %s and id_basket= %s"""%(uid, id_query, id_basket) res = run_sql(sql) if len(res): raise AlertError(_("You already have an alert defined for the specified query and basket")) def perform_add_alert(alert_name, frequency, notification, id_basket, id_query, uid, ln = cdslang): """add an alert to the database input: the name of the new alert; alert frequency: 'month', 'week' or 'day'; setting for e-mail notification: 'y' for yes, 'n' for no; basket identifier: 'no' for no basket; new basket name for this alert; identifier of the query to be alerted output: confirmation message + the list of alerts Web page""" alert_name = alert_name.strip() # load the right message language _ = gettext_set_language(ln) #check the alert name is not empty if alert_name.strip() == "": raise AlertError(_("The alert name cannot be empty.")) #check if the alert can be created check_alert_name(alert_name, uid, ln) check_alert_is_unique(id_basket, id_query, uid, ln) # add a row to the alerts table: user_query_basket query = """INSERT INTO user_query_basket (id_user, id_query, id_basket, frequency, date_creation, date_lastrun, alert_name, notification) VALUES ('%s','%s','%s','%s','%s','','%s','%s')""" query %= (uid, id_query, id_basket, frequency, convert_datestruct_to_datetext(time.localtime()), alert_name, notification) run_sql(query) out = _("The alert %s has been added to your profile.") out %= '' + alert_name + '' out += perform_list_alerts(uid, ln=ln) return out def perform_list_alerts (uid, ln=cdslang): """perform_list_alerts display the list of alerts for the connected user""" # set variables out = "" # query the database query = """ SELECT q.id, q.urlargs, a.id_basket, b.name, a.alert_name, a.frequency,a.notification, DATE_FORMAT(a.date_creation,'%%Y-%%m-%%d %%H:%%i:%%s'), DATE_FORMAT(a.date_lastrun,'%%Y-%%m-%%d %%H:%%i:%%s') FROM user_query_basket a LEFT JOIN query q ON a.id_query=q.id LEFT JOIN bskBASKET b ON a.id_basket=b.id WHERE a.id_user='%s' ORDER BY a.alert_name ASC """ % uid res = run_sql(query) alerts = [] for (qry_id, qry_args, bsk_id, bsk_name, alrt_name, alrt_frequency, alrt_notification, alrt_creation, alrt_last_run) in res: alerts.append({ 'queryid' : qry_id, 'queryargs' : qry_args, 'textargs' : get_textual_query_info_from_urlargs(qry_args, ln=ln), 'userid' : uid, 'basketid' : bsk_id, 'basketname' : bsk_name, 'alertname' : alrt_name, 'frequency' : alrt_frequency, 'notification' : alrt_notification, 'created' : convert_datetext_to_dategui(alrt_creation), 'lastrun' : convert_datetext_to_dategui(alrt_last_run) }) # link to the "add new alert" form out = webalert_templates.tmpl_list_alerts(ln=ln, weburl=weburl, alerts=alerts, guest=isGuestUser(uid), guesttxt=warning_guest_user(type="alerts", ln=ln)) return out def perform_remove_alert(alert_name, id_user, id_query, id_basket, uid, ln=cdslang): """perform_remove_alert: remove an alert from the database input: identifier of the user; identifier of the query; identifier of the basket output: confirmation message + the list of alerts Web page""" # set variables out = "" # remove a row from the alerts table: user_query_basket query = """DELETE FROM user_query_basket WHERE id_user='%s' AND id_query='%s' AND id_basket='%s'""" query %= (id_user, id_query, id_basket) run_sql(query) out += "The alert %s has been removed from your profile.

\n" % alert_name out += perform_list_alerts(uid, ln=ln) return out def perform_update_alert(alert_name, frequency, notification, id_basket, id_query, old_id_basket,uid, ln = cdslang): """update alert settings into the database input: the name of the new alert; alert frequency: 'month', 'week' or 'day'; setting for e-mail notification: 'y' for yes, 'n' for no; new basket identifier: 'no' for no basket; new basket name for this alert; identifier of the query to be alerted old identifier of the basket associated to the alert output: confirmation message + the list of alerts Web page""" #set variables out = "" # load the right message language _ = gettext_set_language(ln) #check the alert name is not empty if alert_name.strip() == "": raise AlertError(_("The alert name cannot be empty.")) #check if the alert can be created sql = """select alert_name from user_query_basket where id_user=%s and id_basket=%s and id_query=%s"""%( uid, old_id_basket, id_query ) old_alert_name = run_sql( sql )[0][0] if old_alert_name.strip()!="" and old_alert_name != alert_name: check_alert_name( alert_name, uid, ln) if id_basket != old_id_basket: check_alert_is_unique( id_basket, id_query, uid, ln) # update a row into the alerts table: user_query_basket query = """UPDATE user_query_basket SET alert_name='%s',frequency='%s',notification='%s', date_creation='%s',date_lastrun='',id_basket='%s' WHERE id_user='%s' AND id_query='%s' AND id_basket='%s'""" query %= (alert_name, frequency, notification, convert_datestruct_to_datetext(time.localtime()), id_basket, uid, id_query, old_id_basket) run_sql(query) out += _("The alert %s has been successfully updated.") % ("" + alert_name + "") out += "

\n" + perform_list_alerts(uid, ln=ln) return out def is_selected(var, fld): "Checks if the two are equal, and if yes, returns ' selected'. Useful for select boxes." if var == fld: return " selected" else: return "" def account_list_alerts(uid, ln=cdslang): """account_list_alerts: list alert for the account page input: the user id language output: the list of alerts Web page""" query = """ SELECT q.id, q.urlargs, a.id_user, a.id_query, a.id_basket, a.alert_name, a.frequency, a.notification, DATE_FORMAT(a.date_creation,'%%d %%b %%Y'), DATE_FORMAT(a.date_lastrun,'%%d %%b %%Y'), a.id_basket FROM query q, user_query_basket a WHERE a.id_user='%s' AND a.id_query=q.id ORDER BY a.alert_name ASC """ % uid res = run_sql(query) alerts = [] if len(res): for row in res: alerts.append({ 'id' : row[0], 'name' : row[5] }) return webalert_templates.tmpl_account_list_alerts(ln=ln, alerts=alerts) def account_list_searches(uid, ln=cdslang): """ account_list_searches: list the searches of the user input: the user id output: resume of the searches""" out ="" # first detect number of queries: nb_queries_total = 0 nb_queries_distinct = 0 id_queries_distinct = [] res = run_sql("SELECT COUNT(*),COUNT(DISTINCT(id_query)) FROM user_query WHERE id_user=%s", (uid,), 1) try: nb_queries_total = res[0][0] nb_queries_distinct = res[0][1] except: pass # load the right message language _ = gettext_set_language(ln) - out += _("You have made %(number)s queries. A %(detailed_list)s is available with a posibility to (a) view search results and (b) subscribe for automatic email alerting service for these queries.") % { - 'detailed_list' : """""" % ln + _("detailed list") + """""", - 'number' : nb_queries_total, - } + out += _("You have made %(number)s queries. A %(link_open)sdetailed list%(link_close)s is available with a posibility to (a) view search results and (b) subscribe for automatic email alerting service for these queries.") % { + 'link_open' : '' % ln, + 'link_close': '', + 'number' : nb_queries_total} return out diff --git a/modules/webalert/lib/webalert_templates.py b/modules/webalert/lib/webalert_templates.py index 22df20312..e3126b245 100644 --- a/modules/webalert/lib/webalert_templates.py +++ b/modules/webalert/lib/webalert_templates.py @@ -1,549 +1,551 @@ ## $Id$ ## This file is part of CDS Invenio. ## Copyright (C) 2002, 2003, 2004, 2005, 2006 CERN. ## ## CDS Invenio is free software; you can redistribute it and/or ## modify it under the terms of the GNU General Public License as ## published by the Free Software Foundation; either version 2 of the ## License, or (at your option) any later version. ## ## CDS Invenio is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with CDS Invenio; if not, write to the Free Software Foundation, Inc., ## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. import urllib import time import cgi import gettext import string import locale import re import operator from invenio.config import * from invenio.messages import gettext_set_language from invenio.htmlparser import get_as_text, wrap from invenio.alert_engine_config import cfg_webalert_max_num_of_records_in_alert_email class Template: def tmpl_errorMsg(self, ln, error_msg, rest = ""): """ Adds an error message to the output Parameters: - 'ln' *string* - The language to display the interface in - 'error_msg' *string* - The error message - 'rest' *string* - The rest of the page """ # load the right message language _ = gettext_set_language(ln) - out = """
%(error)s

%(rest)s""" % { + out = """
%(error)s

%(rest)s""" % { 'error' : error_msg, 'rest' : rest } return out def tmpl_textual_query_info_from_urlargs(self, ln, args): """ Displays a human inteligible textual representation of a query Parameters: - 'ln' *string* - The language to display the interface in - 'args' *array* - The URL arguments array (parsed) """ # load the right message language _ = gettext_set_language(ln) out = "" if args.has_key('p'): - out += "" + _("Pattern") + ": " + string.join(args['p'], "; ") + "
" + out += "" + _("Pattern") + ": " + string.join(args['p'], "; ") + "
" if args.has_key('f'): - out += "" + _("Field") + ": " + string.join(args['f'], "; ") + "
" + out += "" + _("Field") + ": " + string.join(args['f'], "; ") + "
" if args.has_key('p1'): - out += "" + _("Pattern 1") + ": " + string.join(args['p1'], "; ") + "
" + out += "" + _("Pattern 1") + ": " + string.join(args['p1'], "; ") + "
" if args.has_key('f1'): - out += "" + _("Field 1") + ": " + string.join(args['f1'], "; ") + "
" + out += "" + _("Field 1") + ": " + string.join(args['f1'], "; ") + "
" if args.has_key('p2'): - out += "" + _("Pattern 2") + ": " + string.join(args['p2'], "; ") + "
" + out += "" + _("Pattern 2") + ": " + string.join(args['p2'], "; ") + "
" if args.has_key('f2'): - out += "" + _("Field 2") + ": " + string.join(args['f2'], "; ") + "
" + out += "" + _("Field 2") + ": " + string.join(args['f2'], "; ") + "
" if args.has_key('p3'): - out += "" + _("Pattern 3") + ": " + string.join(args['p3'], "; ") + "
" + out += "" + _("Pattern 3") + ": " + string.join(args['p3'], "; ") + "
" if args.has_key('f3'): - out += "" + _("Field 3") + ": " + string.join(args['f3'], "; ") + "
" + out += "" + _("Field 3") + ": " + string.join(args['f3'], "; ") + "
" if args.has_key('c'): - out += "" + _("Collections") + ": " + string.join(args['c'], "; ") + "
" + out += "" + _("Collections") + ": " + string.join(args['c'], "; ") + "
" elif args.has_key('cc'): - out += "" + _("Collection") + ": " + string.join(args['cc'], "; ") + "
" + out += "" + _("Collection") + ": " + string.join(args['cc'], "; ") + "
" return out def tmpl_account_list_alerts(self, ln, alerts): """ Displays all the alerts in the main "Your account" page Parameters: - 'ln' *string* - The language to display the interface in - 'alerts' *array* - The existing alerts IDs ('id' + 'name' pairs) """ # load the right message language _ = gettext_set_language(ln) - out = """
- %(you_own)s - + """ % { + 'you_own' : _("You own following alerts"), 'alert_name' : _("alert name"), } for alert in alerts : - out += """""" % alert - out += """ -   - -
""" % { + out += """""" % alert + out += """ +   + + """ % { 'show' : _("SHOW"), } return out def tmpl_input_alert(self, ln, query, alert_name, action, frequency, notification, baskets, old_id_basket, id_basket, id_query): """ Displays an alert adding form. Parameters: - 'ln' *string* - The language to display the interface in - 'query' *string* - The HTML code of the textual representation of the query (as returned ultimately by tmpl_textual_query_info_from_urlargs...) - 'alert_name' *string* - The alert name - 'action' *string* - The action to complete ('update' or 'add') - 'frequency' *string* - The frequency of alert running ('day', 'week', 'month') - 'notification' *string* - If notification should be sent by email ('y', 'n') - 'baskets' *array* - The existing baskets ('id' + 'name' pairs) - 'old_id_basket' *string* - The id of the previous basket of this alert - 'id_basket' *string* - The id of the basket of this alert - 'id_query' *string* - The id of the query associated to this alert """ # load the right message language _ = gettext_set_language(ln) out = "" - out += """ - - - - - -
%(notify_cond)s
  %(query_text)s:%(query)s
""" % { + out += """ + + + + + + +
%(notify_cond)s
%(query_text)s:%(query)s
""" % { 'notify_cond' : _("This alert will notify you each time/only if a new item satisfy the following query"), 'query_text' : _("QUERY"), 'query' : query, } - out += """
- + +
- - - - - - - - - - - - - - - + + + + +
%(alert_name)s
%(freq)s -
%(send_email)s - (%(specify)s)  -
%(store_basket)s%(baskets)s + out += """ + + + - -
+ %(alert_name)s: + + + + + + + + + + + + + - - - - -
%(freq)s: + +
%(send_email)s + + (%(specify)s) +
%(store_basket)s%(baskets)s """ % { 'action': action, - 'alert_name' : _("Alert identification name:"), + 'alert_name' : _("Alert identification name"), 'alert' : alert_name, - 'freq' : _("Search-checking frequency:"), - 'freq_month' : (frequency == 'month' and "selected" or ""), - 'freq_week' : (frequency == 'week' and "selected" or ""), - 'freq_day' : (frequency == 'day' and "selected" or ""), + 'freq' : _("Search-checking frequency"), + 'freq_month' : (frequency == 'month' and 'selected="selected"' or ""), + 'freq_week' : (frequency == 'week' and 'selected="selected"' or ""), + 'freq_day' : (frequency == 'day' and 'selected="selected"' or ""), 'monthly' : _("monthly"), 'weekly' : _("weekly"), 'daily' : _("daily"), 'send_email' : _("Send notification e-mail?"), 'notif_yes' : (notification == 'y' and "selected" or ""), 'notif_no' : (notification == 'n' and "selected" or ""), 'yes' : _("yes"), 'no' : _("no"), - 'specify' : _("if no you must specify a basket"), + 'specify' : _("if %sno%s you must specify a basket") % ('',''), 'store_basket' : _("Store results in basket?"), 'baskets': baskets } - out += """

- - -   - -
-
+ out += """
+ + +   + +
+
""" % { 'idq' : id_query, 'ln' : ln, 'set_alert' : _("SET ALERT"), 'clear_data' : _("CLEAR DATA"), } if action == "update": - out += """""" % old_id_basket - out += "
" + out += '' % old_id_basket + out += "" return out def tmpl_list_alerts(self, ln, weburl, alerts, guest, guesttxt): """ Displays the list of alerts Parameters: - 'ln' *string* - The language to display the interface in - 'weburl' *string* - The url of CDS Invenio - 'alerts' *array* - The existing alerts: - 'queryid' *string* - The id of the associated query - 'queryargs' *string* - The query string - 'textargs' *string* - The textual description of the query string - 'userid' *string* - The user id - 'basketid' *string* - The basket id - 'basketname' *string* - The basket name - 'alertname' *string* - The alert name - 'frequency' *string* - The frequency of alert running ('day', 'week', 'month') - 'notification' *string* - If notification should be sent by email ('y', 'n') - 'created' *string* - The date of alert creation - 'lastrun' *string* - The last running date - 'guest' *bool* - If the user is a guest user - 'guesttxt' *string* - The HTML content of the warning box for guest users (produced by webaccount.tmpl_warning_guest_user) """ # load the right message language _ = gettext_set_language(ln) - out = """

%(set_new_alert)s

""" % { - 'set_new_alert' : _("Set a new alert from %(your_searches)s, the %(popular_searches)s or the input form.") % { - 'your_searches' : """%s""" % (ln, _("your searches")), - 'popular_searches' : """%s""" % (ln, _("most popular searches")), - } - } - + out = '

' + _("Set a new alert from %syour searches%s, the %spopular_searches%s or the input form.") + '

' + out %= ('' % ln, '', + """""" % ln, '') if len(alerts): - out += """ - - - - - - - - - - """ % { + out += """
%(no)s%(name)s%(search_freq)s%(notification)s%(result_basket)s%(date_run)s%(date_created)s%(query)s%(action)s
+ + + + + + + + + + """ % { 'no' : _("No"), 'name' : _("Name"), 'search_freq' : _("Search checking frequency"), 'notification' : _("Notification by e-mail"), 'result_basket' : _("Result in basket"), 'date_run' : _("Date last run"), 'date_created' : _("Creation date"), 'query' : _("Query"), 'action' : _("Action"), } i = 0 for alert in alerts: i += 1 if alert['frequency'] == "day": frequency = _("daily"), else: if alert['frequency'] == "week": frequency = _("weekly") else: frequency = _("monthly") if alert['notification'] == "y": notification = _("yes") else: notification = _("no") - out += """ - - - - - - - - - - """ % { + out += """ + + + + + + + + + + """ % { 'index' : i, 'alertname' : alert['alertname'], 'frequency' : frequency, 'notification' : notification, 'basketname' : alert['basketname'], 'lastrun' : alert['lastrun'], 'created' : alert['created'], 'textargs' : alert['textargs'], 'userid' : alert['userid'], 'queryid' : alert['queryid'], 'basketid' : alert['basketid'], 'freq' : alert['frequency'], 'notif' : alert['notification'], 'ln' : ln, 'remove' : _("Remove"), 'modify' : _("Modify"), 'weburl' : weburl, 'search' : _("Execute search"), 'queryargs' : alert['queryargs'] } - out += '
%(no)s%(name)s%(search_freq)s%(notification)s%(result_basket)s%(date_run)s%(date_created)s%(query)s%(action)s
#%(index)d%(alertname)s%(frequency)s%(notification)s%(basketname)s%(lastrun)s%(created)s%(textargs)s%(remove)s
- %(modify)s
- %(search)s -
#%(index)d%(alertname)s%(frequency)s%(notification)s%(basketname)s%(lastrun)s%(created)s%(textargs)s + %(remove)s
+ %(modify)s
+ %(search)s +
' + out += '' - out += """

%(defined)s

""" % { - 'defined' : _("You have defined %(number)s alerts.") % { 'number' : len(alerts)} - } - + out += '

' + (_("You have defined %s alerts.") % ('' + str(len(alerts)) + '' )) + '

' if guest: out += guesttxt - return out def tmpl_display_alerts(self, ln, weburl, permanent, nb_queries_total, nb_queries_distinct, queries, guest, guesttxt): """ Displays the list of alerts Parameters: - 'ln' *string* - The language to display the interface in - 'weburl' *string* - The url of CDS Invenio - 'permanent' *string* - If displaying most popular searches ('y') or only personal searches ('n') - 'nb_queries_total' *string* - The number of personal queries in the last period - 'nb_queries_distinct' *string* - The number of distinct queries in the last period - 'queries' *array* - The existing queries: - 'id' *string* - The id of the associated query - 'args' *string* - The query string - 'textargs' *string* - The textual description of the query string - 'lastrun' *string* - The last running date (only for personal queries) - 'guest' *bool* - If the user is a guest user - 'guesttxt' *string* - The HTML content of the warning box for guest users (produced by webaccount.tmpl_warning_guest_user) """ # load the right message language _ = gettext_set_language(ln) if len(queries) == 0: - return _("You have not executed any search yet. %(click_here)s for search.") % { - 'click_here' : """%(click)s""" % { - 'weburl' : weburl, - 'ln': ln, - 'click' : _("Click here"), - } - } + out = _("You have not executed any search yet. %(link_open)sClick here%(link_close)s for search.") + out %= {'link_open' : '' % (weburl, ln), + 'link_close': ''} + return out out = '' # display message: number of items in the list if permanent=="n": - out += """

""" + _("You have performed %(number)d searches (%(different)d different questions) during the last 30 days or so.""") % { - 'number' : nb_queries_total, - 'different' : nb_queries_distinct - } + """

""" + msg = _("You have performed %(nb_search)s searches (%(nb_questions)s different questions) during the last 30 days or so.") + msg %= {'nb_search' : nb_queries_total, 'nb_questions' : nb_queries_distinct} + out += '

' + msg + '

' else: # permanent="y" - out += """

Here are listed the %s most popular searches.

""" % len(query_result) + msg = _("Here are listed the %s most popular searches.") + msg %= ('' + str(len(query_result)) + '') + out += '

' + msg + '

' # display the list of searches - out += """ - - """ % { + out += """
%(no)s%(question)s%(action)s
+ + + + """ % { 'no' : _("#"), 'question' : _("Question"), 'action' : _("Action") } if permanent=="n": - out += """""" % _("Last Run") - out += """\n""" + out += '' % _("Last Run") + out += "\n" i = 0 for query in queries : i += 1 # id, pattern, base, search url and search set alert, date - out += """ - - - """ % { + out += """ + + + """ % { 'index' : i, 'textargs' : query['textargs'], 'weburl' : weburl, 'args' : query['args'], 'id' : query['id'], 'ln': ln, 'execute_query' : _("Execute search"), 'set_alert' : _("Set new alert") } if permanent=="n": - out += """""" % query - out += """\n""" - out += """
%(no)s%(question)s%(action)s%s
%s
#%(index)d%(textargs)s%(execute_query)s
%(set_alert)s
#%(index)d%(textargs)s%(execute_query)s
+ %(set_alert)s
%(lastrun)s

\n""" + out += '%s' % query['lastrun'] + out += """\n""" + out += "
\n" if guest : out += guesttxt return out def tmpl_alert_email_headers(self, name, headers): headers['Subject'] = 'Alert %s run on %s' % ( name, time.strftime("%Y-%m-%d")) headers['From'] = 'CDS Alert Engine <%s>' % alertengineemail def tmpl_alert_email_body(self, name, url, records, pattern, catalogues, frequency): l = len(catalogues) if l == 0: collections = '' elif l == 1: collections = "collection: %s\n" % catalogues[0] else: collections = "collections: %s\n" % wrap(', '.join(catalogues)) if pattern: pattern = 'pattern: %s\n' % pattern frequency = {'day': 'daily', 'month': 'monthly', 'year': 'yearly'}[frequency] l = len(records) if l == 1: total = '1 record' else: total = '%d records' % l body = """\ Hello: Below are the results of the email notification alert that you set up with the %(cdsname)s. This is an automatic message, please don't reply to it. For any question, please use <%(supportemail)s> instead. alert name: %(name)s %(pattern)s%(collections)sfrequency: %(frequency)s run time: %(runtime)s found: %(total)s url: <%(url)s> """ % {'supportemail': supportemail, 'name': name, 'cdsname': cdsname, 'pattern': pattern, 'collections': collections, 'frequency': frequency, 'runtime': time.strftime("%a %Y-%m-%d %H:%M:%S"), 'total': total, 'url': url} for index, recid in enumerate(records[:cfg_webalert_max_num_of_records_in_alert_email]): body += "\n%i) " % (index + 1) body += self.tmpl_alert_email_record(recid) body += "\n" if len(records) > cfg_webalert_max_num_of_records_in_alert_email: body += ''' Only the first %s records were displayed. Please consult the search URL given at the top of this email to see all the results. ''' % cfg_webalert_max_num_of_records_in_alert_email body += ''' -- %s Alert Service <%s> Unsubscribe? See <%s> Need human intervention? Contact <%s> ''' % (cdsname, weburl, weburl + '/youralerts/list', supportemail) return body def tmpl_alert_email_record(self, recid): """ Format a single record.""" out = wrap(get_as_text(recid)) out += "Detailed record: <%s/record/%s>" % (weburl, recid) return out