def add_records_to_basket(records, basket_id): """Add the given records to the given baskets""" index = 0 nrec = len(records[0]) index += nrec if index > CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL: index = CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL if nrec > 0: nrec_to_add = nrec < index and nrec or index if CFG_WEBALERT_DEBUG_LEVEL > 0: print "-> adding %i records into basket %s: %s" % (nrec_to_add, basket_id, records[0][:nrec_to_add]) if nrec > nrec_to_add: print "-> not added %i records into basket %s: %s due to maximum limit restrictions." % (nrec - nrec_to_add, basket_id, records[0][nrec_to_add:]) try: if CFG_WEBALERT_DEBUG_LEVEL < 4: owner_uid = get_basket_owner_id(basket_id) add_to_basket(owner_uid, records[0][:nrec_to_add], 0, basket_id) else: print ' NOT ADDED, DEBUG LEVEL == 4' except Exception: register_exception() if index < CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL: for external_collection_results in records[1][0]: nrec = len(external_collection_results[1][0]) # index_tmp: the number of maximum allowed records to be added to # the basket for the next collection. index_tmp = CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL - index index += nrec if index > CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL: index = CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL if nrec > 0 and index_tmp > 0: nrec_to_add = nrec < index_tmp and nrec or index_tmp if CFG_WEBALERT_DEBUG_LEVEL > 0: print "-> adding %s external records (collection \"%s\") into basket %s: %s" % (nrec_to_add, external_collection_results[0], basket_id, external_collection_results[1][0][:nrec_to_add]) if nrec > nrec_to_add: print "-> not added %s external records (collection \"%s\") into basket %s: %s due to maximum limit restriction" % (nrec - nrec_to_add, external_collection_results[0], basket_id, external_collection_results[1][0][nrec_to_add:]) try: if CFG_WEBALERT_DEBUG_LEVEL < 4: owner_uid = get_basket_owner_id(basket_id) collection_id = get_collection_id(external_collection_results[0]) added_items = add_to_basket(owner_uid, external_collection_results[1][0][:nrec_to_add], collection_id, basket_id) format_external_records(added_items, of="xm") else: print ' NOT ADDED, DEBUG LEVEL == 4' except Exception: register_exception() elif nrec > 0 and CFG_WEBALERT_DEBUG_LEVEL > 0: print "-> not added %s external records (collection \"%s\") into basket %s: %s due to maximum limit restriction" % (nrec, external_collection_results[0], basket_id, external_collection_results[1][0]) elif CFG_WEBALERT_DEBUG_LEVEL > 0: for external_collection_results in records[1][0]: nrec = len(external_collection_results[1][0]) if nrec > 0: print "-> not added %i external records (collection \"%s\") into basket %s: %s due to maximum limit restrictions" % (nrec, external_collection_results[0], basket_id, external_collection_results[1][0])
def add_records_to_basket(records, basket_id): """Add the given records to the given baskets""" index = 0 nrec = len(records[0]) index += nrec if index > CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL: index = CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL if nrec > 0: nrec_to_add = nrec < index and nrec or index if CFG_WEBALERT_DEBUG_LEVEL > 0: print "-> adding %i records into basket %s: %s" % (nrec_to_add, basket_id, records[0][:nrec_to_add]) if nrec > nrec_to_add: print "-> not added %i records into basket %s: %s due to maximum limit restrictions." % (nrec - nrec_to_add, basket_id, records[0][nrec_to_add:]) try: if CFG_WEBALERT_DEBUG_LEVEL == 0: owner_uid = get_basket_owner_id(basket_id) add_to_basket(owner_uid, records[0][:nrec_to_add], 0, basket_id) else: print ' NOT ADDED, DEBUG LEVEL > 0' except Exception: register_exception() if index < CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL: for external_collection_results in records[1][0]: nrec = len(external_collection_results[1][0]) # index_tmp: the number of maximum allowed records to be added to # the basket for the next collection. index_tmp = CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL - index index += nrec if index > CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL: index = CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL if nrec > 0 and index_tmp > 0: nrec_to_add = nrec < index_tmp and nrec or index_tmp if CFG_WEBALERT_DEBUG_LEVEL > 0: print "-> adding %s external records (collection \"%s\") into basket %s: %s" % (nrec_to_add, external_collection_results[0], basket_id, external_collection_results[1][0][:nrec_to_add]) if nrec > nrec_to_add: print "-> not added %s external records (collection \"%s\") into basket %s: %s due to maximum limit restriction" % (nrec - nrec_to_add, external_collection_results[0], basket_id, external_collection_results[1][0][nrec_to_add:]) try: if CFG_WEBALERT_DEBUG_LEVEL == 0: owner_uid = get_basket_owner_id(basket_id) collection_id = get_collection_id(external_collection_results[0]) added_items = add_to_basket(owner_uid, external_collection_results[1][0][:nrec_to_add], collection_id, basket_id) format_external_records(added_items, of="xm") else: print ' NOT ADDED, DEBUG LEVEL > 0' except Exception: register_exception() elif nrec > 0 and CFG_WEBALERT_DEBUG_LEVEL > 0: print "-> not added %s external records (collection \"%s\") into basket %s: %s due to maximum limit restriction" % (nrec, external_collection_results[0], basket_id, external_collection_results[1][0]) elif CFG_WEBALERT_DEBUG_LEVEL > 0: for external_collection_results in records[1][0]: nrec = len(external_collection_results[1][0]) if nrec > 0: print "-> not added %i external records (collection \"%s\") into basket %s: %s due to maximum limit restrictions" % (nrec, external_collection_results[0], basket_id, external_collection_results[1][0])
def add_records_to_basket(records, basket_id): """Add the given records to the given baskets""" index = 0 owner_uid = get_basket_owner_id(basket_id) # We check that the owner of the recipient basket would be allowed # to view the records. This does not apply to external records # (hosted collections). user_info = collect_user_info(owner_uid) filtered_records = ([], records[1]) filtered_out_recids = [] # only set in debug mode for recid in records[0]: (auth_code, auth_msg) = check_user_can_view_record(user_info, recid) if auth_code == 0: filtered_records[0].append(recid) elif CFG_WEBALERT_DEBUG_LEVEL > 2: # only keep track of this in DEBUG mode filtered_out_recids.append(recid) nrec = len(filtered_records[0]) index += nrec if index > CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL: index = CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL if nrec > 0: nrec_to_add = nrec < index and nrec or index if CFG_WEBALERT_DEBUG_LEVEL > 0: print "-> adding %i records into basket %s: %s" % (nrec_to_add, basket_id, filtered_records[0][:nrec_to_add]) if nrec > nrec_to_add: print "-> not added %i records into basket %s: %s due to maximum limit restrictions." % (nrec - nrec_to_add, basket_id, filtered_records[0][nrec_to_add:]) try: if CFG_WEBALERT_DEBUG_LEVEL == 0: add_to_basket(owner_uid, filtered_records[0][:nrec_to_add], 0, basket_id) else: print ' NOT ADDED, DEBUG LEVEL > 0' except Exception: register_exception() if CFG_WEBALERT_DEBUG_LEVEL > 2 and filtered_out_recids: print "-> these records have been filtered out, as user id %s did not have access:\n%s" % \ (owner_uid, repr(filtered_out_recids)) if index < CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL: for external_collection_results in filtered_records[1][0]: nrec = len(external_collection_results[1][0]) # index_tmp: the number of maximum allowed records to be added to # the basket for the next collection. index_tmp = CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL - index index += nrec if index > CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL: index = CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL if nrec > 0 and index_tmp > 0: nrec_to_add = nrec < index_tmp and nrec or index_tmp if CFG_WEBALERT_DEBUG_LEVEL > 0: print "-> adding %s external records (collection \"%s\") into basket %s: %s" % (nrec_to_add, external_collection_results[0], basket_id, external_collection_results[1][0][:nrec_to_add]) if nrec > nrec_to_add: print "-> not added %s external records (collection \"%s\") into basket %s: %s due to maximum limit restriction" % (nrec - nrec_to_add, external_collection_results[0], basket_id, external_collection_results[1][0][nrec_to_add:]) try: if CFG_WEBALERT_DEBUG_LEVEL == 0: collection_id = get_collection_id(external_collection_results[0]) added_items = add_to_basket(owner_uid, external_collection_results[1][0][:nrec_to_add], collection_id, basket_id) format_external_records(added_items, of="xm") else: print ' NOT ADDED, DEBUG LEVEL > 0' except Exception: register_exception() elif nrec > 0 and CFG_WEBALERT_DEBUG_LEVEL > 0: print "-> not added %s external records (collection \"%s\") into basket %s: %s due to maximum limit restriction" % (nrec, external_collection_results[0], basket_id, external_collection_results[1][0]) elif CFG_WEBALERT_DEBUG_LEVEL > 0: for external_collection_results in filtered_records[1][0]: nrec = len(external_collection_results[1][0]) if nrec > 0: print "-> not added %i external records (collection \"%s\") into basket %s: %s due to maximum limit restrictions" % (nrec, external_collection_results[0], basket_id, external_collection_results[1][0])
def add_records_to_basket(records, basket_id): """Add the given records to the given baskets""" index = 0 owner_uid = get_basket_owner_id(basket_id) # We check that the owner of the recipient basket would be allowed # to view the records. This does not apply to external records # (hosted collections). user_info = collect_user_info(owner_uid) filtered_records = ([], records[1]) filtered_out_recids = [] # only set in debug mode for recid in records[0]: (auth_code, auth_msg) = check_user_can_view_record(user_info, recid) if auth_code == 0: filtered_records[0].append(recid) elif CFG_WEBALERT_DEBUG_LEVEL > 2: # only keep track of this in DEBUG mode filtered_out_recids.append(recid) nrec = len(filtered_records[0]) index += nrec if index > CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL: index = CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL if nrec > 0: nrec_to_add = nrec < index and nrec or index if CFG_WEBALERT_DEBUG_LEVEL > 0: print "-> adding %i records into basket %s: %s" % ( nrec_to_add, basket_id, filtered_records[0][:nrec_to_add]) if nrec > nrec_to_add: print "-> not added %i records into basket %s: %s due to maximum limit restrictions." % ( nrec - nrec_to_add, basket_id, filtered_records[0][nrec_to_add:]) try: if CFG_WEBALERT_DEBUG_LEVEL == 0: add_to_basket(owner_uid, filtered_records[0][:nrec_to_add], 0, basket_id) else: print ' NOT ADDED, DEBUG LEVEL > 0' except Exception: register_exception() if CFG_WEBALERT_DEBUG_LEVEL > 2 and filtered_out_recids: print "-> these records have been filtered out, as user id %s did not have access:\n%s" % \ (owner_uid, repr(filtered_out_recids)) if index < CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL: for external_collection_results in filtered_records[1][0]: nrec = len(external_collection_results[1][0]) # index_tmp: the number of maximum allowed records to be added to # the basket for the next collection. index_tmp = CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL - index index += nrec if index > CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL: index = CFG_WEBALERT_MAX_NUM_OF_RECORDS_IN_ALERT_EMAIL if nrec > 0 and index_tmp > 0: nrec_to_add = nrec < index_tmp and nrec or index_tmp if CFG_WEBALERT_DEBUG_LEVEL > 0: print "-> adding %s external records (collection \"%s\") into basket %s: %s" % ( nrec_to_add, external_collection_results[0], basket_id, external_collection_results[1][0][:nrec_to_add]) if nrec > nrec_to_add: print "-> not added %s external records (collection \"%s\") into basket %s: %s due to maximum limit restriction" % ( nrec - nrec_to_add, external_collection_results[0], basket_id, external_collection_results[1][0][nrec_to_add:]) try: if CFG_WEBALERT_DEBUG_LEVEL == 0: collection_id = get_collection_id( external_collection_results[0]) added_items = add_to_basket( owner_uid, external_collection_results[1][0][:nrec_to_add], collection_id, basket_id) format_external_records(added_items, of="xm") else: print ' NOT ADDED, DEBUG LEVEL > 0' except Exception: register_exception() elif nrec > 0 and CFG_WEBALERT_DEBUG_LEVEL > 0: print "-> not added %s external records (collection \"%s\") into basket %s: %s due to maximum limit restriction" % ( nrec, external_collection_results[0], basket_id, external_collection_results[1][0]) elif CFG_WEBALERT_DEBUG_LEVEL > 0: for external_collection_results in filtered_records[1][0]: nrec = len(external_collection_results[1][0]) if nrec > 0: print "-> not added %i external records (collection \"%s\") into basket %s: %s due to maximum limit restrictions" % ( nrec, external_collection_results[0], basket_id, external_collection_results[1][0])