示例#1
0
文件: api.py 项目: SCOAP3/invenio
def perform_list_alerts(uid, ln=CFG_SITE_LANG):
    """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 """
    res = run_sql(query, (uid,))
    alerts = []
    for (qry_id, qry_args,
         bsk_id, bsk_name,
         alrt_name, alrt_frequency, alrt_notification, alrt_creation, alrt_last_run) in res:
        try:
            if not qry_id:
                raise StandardError("""\
Warning: I have detected a bad alert for user id %d.
It seems one of his/her alert queries was deleted from the 'query' table.
Please check this and delete it if needed.
Otherwise no problem, I'm continuing with the other alerts now.
Here are all the alerts defined by this user: %s""" % (uid, repr(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)
                 })
        except StandardError:
            register_exception(alert_admin=True)

    # link to the "add new alert" form
    out = webalert_templates.tmpl_list_alerts(ln=ln, alerts=alerts,
                                              guest=isGuestUser(uid),
                                              guesttxt=warning_guest_user(type="alerts", ln=ln))
    return out
示例#2
0
def perform_input_alert(action,
                        id_query,
                        alert_name,
                        frequency,
                        notification,
                        id_basket,
                        uid,
                        old_id_basket=None,
                        ln=CFG_SITE_LANG):
    """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"""
    # load the right language
    _ = gettext_set_language(ln)
    # security check:
    if not check_user_can_add_alert(uid, id_query):
        raise AlertError(_("You do not have rights for this operation."))
    # 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=ln)
    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,
        guest=isGuestUser(uid),
        guesttxt=warning_guest_user(type="alerts", ln=ln))
示例#3
0
文件: api.py 项目: SCOAP3/invenio
def perform_input_alert(action, id_query, alert_name, frequency, notification, id_basket, uid, old_id_basket=None, ln = CFG_SITE_LANG):
    """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"""
    # load the right language
    _ = gettext_set_language(ln)
    # security check:
    if not check_user_can_add_alert(uid, id_query):
        raise AlertError(_("You do not have rights for this operation."))
    # 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=ln)
    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,
             guest = isGuestUser(uid),
             guesttxt = warning_guest_user(type="alerts", ln=ln)
           )
示例#4
0
def perform_display(permanent, uid, ln=CFG_SITE_LANG):
    """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 language
    _ = gettext_set_language(ln)

    # first detect number of queries:
    nb_queries_total = 0
    nb_queries_distinct = 0
    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:
    params = ()
    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"
        params = (uid, )
    else:
        # permanent="y"
        SQL_query = "SELECT q.id,q.urlargs "\
                    "FROM query q "\
                    "WHERE q.type='p'"
    query_result = run_sql(SQL_query, params)

    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))
示例#5
0
def perform_list_alerts(uid, ln=CFG_SITE_LANG):
    """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 """
    res = run_sql(query, (uid, ))
    alerts = []
    for (qry_id, qry_args, bsk_id, bsk_name, alrt_name, alrt_frequency,
         alrt_notification, alrt_creation, alrt_last_run) in res:
        try:
            if not qry_id:
                raise StandardError("""\
Warning: I have detected a bad alert for user id %d.
It seems one of his/her alert queries was deleted from the 'query' table.
Please check this and delete it if needed.
Otherwise no problem, I'm continuing with the other alerts now.
Here are all the alerts defined by this user: %s""" % (uid, repr(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)
            })
        except StandardError:
            register_exception(alert_admin=True)

    # link to the "add new alert" form
    out = webalert_templates.tmpl_list_alerts(ln=ln,
                                              alerts=alerts,
                                              guest=isGuestUser(uid),
                                              guesttxt=warning_guest_user(
                                                  type="alerts", ln=ln))
    return out
示例#6
0
文件: api.py 项目: SCOAP3/invenio
def perform_display(permanent, uid, ln=CFG_SITE_LANG):
    """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 language
    _ = gettext_set_language(ln)

    # first detect number of queries:
    nb_queries_total = 0
    nb_queries_distinct = 0
    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:
    params = ()
    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"
        params = (uid,)
    else:
        # permanent="y"
        SQL_query = "SELECT q.id,q.urlargs "\
                    "FROM query q "\
                    "WHERE q.type='p'"
    query_result = run_sql(SQL_query, params)

    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)
           )