diff --git a/modules/webbasket/lib/.cvsignore b/modules/webbasket/lib/.cvsignore
index 9928cf5cf..df3ddb84d 100644
--- a/modules/webbasket/lib/.cvsignore
+++ b/modules/webbasket/lib/.cvsignore
@@ -1,7 +1,6 @@
Makefile
Makefile.in
z_*
*.O
*.shtml
-*.py
*~
\ No newline at end of file
diff --git a/modules/webbasket/lib/Makefile.am b/modules/webbasket/lib/Makefile.am
index 2a65a38ac..3ba4ed52b 100644
--- a/modules/webbasket/lib/Makefile.am
+++ b/modules/webbasket/lib/Makefile.am
@@ -1,29 +1,26 @@
## $Id$
## This file is part of the CERN Document Server Software (CDSware).
## Copyright (C) 2002, 2003, 2004, 2005 CERN.
##
## The CDSware 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.
##
## The CDSware 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 CDSware; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
pylibdir=$(libdir)/python/cdsware
-pylib_DATA=webbasket.py
-FILESWML = $(wildcard $(srcdir)/*.wml)
-EXTRA_DIST = $(FILESWML:$(srcdir)/%=%)
+pylib_DATA=webbasket.py
-CLEANFILES = $(pylib_DATA) *~ *.tmp *.pyc
+EXTRA_DIST = $(pylib_DATA)
-%.py: %.py.wml $(top_srcdir)/config/config.wml $(top_builddir)/config/configbis.wml
- $(WML) -o $@ $<
\ No newline at end of file
+CLEANFILES = *~ *.tmp *.pyc
diff --git a/modules/webbasket/lib/webbasket.py b/modules/webbasket/lib/webbasket.py
index 85d2fe4b7..a1bd83885 100644
--- a/modules/webbasket/lib/webbasket.py
+++ b/modules/webbasket/lib/webbasket.py
@@ -1,813 +1,811 @@
## $Id$
## Personal features - your baskets.
## This file is part of the CERN Document Server Software (CDSware).
## Copyright (C) 2002, 2003, 2004, 2005 CERN.
##
## The CDSware 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.
##
## The CDSware 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 CDSware; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
-
" % msg
except BasketException, e:
out += "The basket has not been deleted: %s" % e
show_actions = 1
else:
# goes to the form which deletes the selected basket
out += delete_basket(uid, id_basket, bname)
basket_name = bname
show_actions = 0
id_basket = '0'
else:
show_actions = 1
if action == "CREATE NEW":
# create a new basket
if newname != "":
# create a new basket newname
try:
id_basket = perform_create_basket(uid, newname)
out += """The private basket %s has been created.
\n""" % newname
except BasketException, e:
out += """The basket %s has not been created: %s""" % (newname, e)
else:
out += """The basket has not been created: specify a basket name."""
else:
if (id_basket != '0') and (id_basket != 0):
if action == "RENAME":
# rename the selected basket
if newbname != "":
# rename basket to newname
try:
id_basket = perform_rename_basket(uid, id_basket,newbname)
out += """The basket %s has been renamed to %s.
\n""" % (bname, newbname)
except BasketException, e:
out += """The basket has not been renamed: %s"""%e
else:
out += """The basket has not been renamed: specify a basket name."""
else:
if action == "SET PUBLIC":
try:
# set public permission
set_permission(uid, id_basket, "y")
url_public_basket = """%s/yourbaskets.py/display_public?id_basket=%s""" \
% (weburl, id_basket)
out += """The selected basket is now publicly accessible at the following URL:
"""\
"""%s
""" % (url_public_basket, url_public_basket)
except BasketException, e:
out += "The basket has not been made public: %s"%e
else:
if action == "SET PRIVATE":
# set private permission
try:
set_permission(uid, id_basket, "n")
out += """The selected basket is no more publically accessible.
"""
except BasketException, e:
out += "The basket has not been made private: %s"%e
else:
if action == "REMOVE":
# remove the selected items from the basket
try:
remove_items(uid, id_basket, mark)
out += """The selected items have been removed.
"""
except BasketException, e:
out += """The items have not been removed: %s"""%e
else:
if action == "EXECUTE":
# copy/move the selected items to another basket
if to_basket == '0':
out += """Select a destination basket to copy/move items.
"""
else:
move_items(uid, id_basket, mark, to_basket, copy_move)
out += """The selected items have been copied/moved.
"""
else:
if action == "ORDER":
# change the order of the items in the basket
try:
order_items(uid, id_basket,idup,ordup,iddown,orddown)
except BasketException, e:
out += """The items have not been re-ordered: %s"""%e
# display the basket's action form
if (show_actions):
# query the database for the list of baskets
query_result = run_sql("SELECT b.id, b.name, b.public, ub.date_modification "\
"FROM basket b, user_basket ub "\
"WHERE ub.id_user=%s AND b.id=ub.id_basket "\
"ORDER BY b.name ASC ",
(uid,))
out += """
The basket %s is empty.""" % basket_name out += out_tmp return out # delete_basket: present a form for the confirmation of the delete action # input: the identifier of the selected basket # the name of the selected basket # output: the information about the selected basket and the form for the confirmation of the delete action def delete_basket(uid, id_basket, basket_name): # set variables out = "" # search for related alerts out += """
""" return out # perform_delete: present a form for the confirmation of the delete action # input: delete_alerts='n' if releted alerts shouldn't be deleted; 'y' if yes # action='YES' if delete action has been confirmed; 'NO' otherwise # id_basket contains the identifier of the selected basket # output: go back to the display baskets form with confirmation message def perform_delete(uid, delete_alerts, confirm_action, id_basket,): # set variables out = "" if (confirm_action=='CONFIRM'): #check that the user which is changing the basket name is the owner of it if not is_basket_owner( uid, id_basket ): raise NotBasketOwner("You are not the owner of this basket") # perform the cancellation msg = "The selected basket has been deleted." if (delete_alerts=='y'): # delete the related alerts, remove from the alerts table: user_query_basket query_result = run_sql("DELETE FROM user_query_basket WHERE id_user=%s AND id_basket=%s", (uid, id_basket)) msg += " The related alerts have been removed." else: # replace the basket identifier with 0 # select the records to update query_result = run_sql("SELECT id_query,alert_name,frequency,notification,date_creation,date_lastrun "\ "FROM user_query_basket WHERE id_user=%s AND id_basket=%s", (uid, id_basket)) # update the records for row in query_result: query_result_temp = run_sql("UPDATE user_query_basket "\ "SET alert_name=%s,frequency=%s,notification=%s,"\ "date_creation=%s,date_lastrun=%s,id_basket='0' "\ "WHERE id_user=%s AND id_query=%s AND id_basket=%s", (row[1],row[2],row[3],row[4],row[5],uid,row[0],id_basket)) # delete the relation with the user table query_result = run_sql("DELETE FROM user_basket WHERE id_user=%s AND id_basket=%s", (uid, id_basket)) # delete the basket information query_result = run_sql("DELETE FROM basket WHERE id=%s", (id_basket,)) # delete the basket content query_result = run_sql("DELETE FROM basket_record WHERE id_basket=%s", (id_basket,)) else: msg="" return msg # perform_rename_basket: rename an existing basket # input: basket identifier, basket new name # output: basket identifier def perform_rename_basket(uid, id_basket, newname): # check that there's no basket owned by this user with the same name if has_user_basket( uid, newname): raise BasketNameAlreadyExists("You already have a basket which name is '%s'"%newname) #check that the user which is changing the basket name is the owner of it if not is_basket_owner( uid, id_basket ): raise NotBasketOwner("You are not the owner of this basket") # update a row to the basket table tmp = run_sql("UPDATE basket SET name=%s WHERE id=%s", (newname, id_basket)) return id_basket class BasketException(Exception): """base exception class for basket related errors """ pass class BasketNameAlreadyExists(BasketException): """exception which is raised when a basket already exists with a certain name for a user """ pass class NotBasketOwner(BasketException): """exception which is raised when a user which is not the owner of a basket tries to perform an operation over it for which he has no privileges """ pass def has_user_basket(uid, basket_name): """checks if a user (uid) already has a basket which name is 'basket_name' (case-sensitive) """ return run_sql("select b.id from basket b, user_basket ub where ub.id_user=%s and b.id=ub.id_basket and b.name=%s", (uid, basket_name.strip())) def is_basket_owner(uid, bid): """checks whether or not the user (uid) is owner for the indicated basket (bid) """ return run_sql("select id_basket from user_basket where id_user=%s and id_basket=%s", (uid, bid)) def get_basket_name(bid): """returns the name of the basket corresponding to the given id """ res = run_sql("select name from basket where id=%s", (bid,)) if not res: return "" return res[0][0] # perform_create_basket: create a new basket and the relation with the user table # input: basket name # output: basket identifier def perform_create_basket(uid, basket_name): # check that there's no basket owned by this user with the same name if has_user_basket(uid, basket_name): raise BasketNameAlreadyExists("You already have a basket which name is '%s'"%basket_name) # add a row to the basket table id_basket = run_sql("INSERT INTO basket(id,name,public) VALUES ('0',%s,'n')", (basket_name,)) # create the relation between the user and the basket: user_basket query_result = run_sql("INSERT INTO user_basket(id_user,id_basket,date_modification) VALUES (%s,%s,%s)", (uid, id_basket, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) return id_basket # basket_exists checks if a basket is in the database # input: the name of the basket # output: the id of the basket if it exists, 0 otherwise def basket_exists (basket_name, uid): id_basket = run_sql("SELECT b.id FROM basket b, user_basket ub "\ "WHERE b.name=%s "\ "AND b.id=ub.id_basket "\ "AND ub.id_user=%s", (basket_name, uid)) return id_basket # set_permission: set access permission on a basket # input: basket identifier, basket public permission # output: basket identifier def set_permission(uid, id_basket, permission): #check that the user which is changing the basket name is the owner of it if not is_basket_owner( uid, id_basket ): raise NotBasketOwner("You are not the owner of this basket") # update a row to the basket table id_basket = run_sql("UPDATE basket SET public=%s WHERE id=%s", (permission, id_basket)) return id_basket # remove_items: remove the selected items from the basket # input: basket identifier, list of selected items # output: basket identifier def remove_items(uid, id_basket, mark): #check that the user which is changing the basket name is the owner of it if not is_basket_owner( uid, id_basket ): raise NotBasketOwner("You are not the owner of this basket") if type(mark)==list: selected_items=mark else: selected_items=[mark] for i in selected_items: # delete the basket content query_result = run_sql("DELETE FROM basket_record WHERE id_basket=%s AND id_record=%s", (id_basket, i)) return id_basket # check_copy: check if the record exists already in the basket # input: basket identifier, list of selected items # output: boolean def check_copy(idbask,i): query_result = run_sql("select * from basket_record where id_basket=%s and id_record=%s", (idbask,i)) if len(query_result)>0 : return 0 return 1 # copy/move the selected items to another basket # input: original basket identifier, list of selected items, # destination basket identifier, copy or move option: "1"=copy, "2"=move #output: basket identifier def move_items(uid, id_basket, mark, to_basket, copy_move="1"): if type(mark)==list: selected_items=mark else: selected_items=[mark] for i in selected_items: if check_copy(to_basket,i): query_result = run_sql("INSERT INTO basket_record(id_basket,id_record,nb_order) VALUES (%s,%s,'0')", (to_basket, i)) if copy_move=="2": #delete from previous basket remove_items(uid, id_basket, mark) return id_basket # change the order of the items in the basket # input: basket identifier # identifiers and positions of the items to be moved #output: basket identifier def order_items(uid, id_basket,idup,ordup,iddown,orddown): #check that the user which is changing the basket name is the owner of it if not is_basket_owner( uid, id_basket ): raise NotBasketOwner("You are not the owner of this basket") # move up the item idup (by switching its order number with the other item): query_result = run_sql("UPDATE basket_record SET nb_order=%s WHERE id_basket=%s AND id_record=%s", (orddown,id_basket,idup)) # move down the item iddown (by switching its order number with the other item): query_result = run_sql("UPDATE basket_record SET nb_order=%s WHERE id_basket=%s AND id_record=%s", (ordup,id_basket,iddown)) return id_basket # perform_display_public: display the content of the selected basket, if public # input: the identifier of the basket # the name of the basket # of is the output format code # output: the basket's content def perform_display_public(uid, id_basket, basket_name, action, to_basket, mark, newname, of): out = "" if action=="EXECUTE": # perform actions if newname != "": # create a new basket to_basket = perform_create_basket(uid, newname) out += """The private basket %s has been created.No records to add." # do we have to create some baskets? if bname: try: new_basket_ID = perform_create_basket(uid, bname) bskIDs = [new_basket_ID] except BasketException, e: out += """The basket %s has not been created: %s""" % (bname, e) if bskIDs == []: # A - some information missing, so propose list of baskets to choose from basket_id_name_list = get_list_of_user_baskets(uid) if basket_id_name_list != []: # there are some baskets; good out += "
Please choose the basket you want to add %d records to:" % len(recIDs) out += """
""" else: # user have to create a basket first out += """You don't own baskets defined yet.""" out += """
""" else: # B - we have baskets IDs, so we can add records out += """Adding %s records to basket(s)...""" % len(recIDs) for bskID in bskIDs: if is_basket_owner(uid, bskID): for recID in recIDs: try: res = run_sql("INSERT INTO basket_record(id_basket,id_record,nb_order) VALUES (%s,%s,%s)", (bskID,recID,'0')) except: pass # maybe records were already there? page reload happened? out += """done.""" else: out += """sorry, you are not the owner of this basket.""" out += perform_display(uid=uid, id_basket=bskIDs[0]) return out def get_list_of_user_baskets(uid): """Return list of lists [[basket_id, basket_name],[basket_id, basket_name],...] for the given user.""" out = [] res = run_sql("SELECT b.id, b.name "\ "FROM basket b, user_basket ub "\ "WHERE ub.id_user=%s AND b.id=ub.id_basket "\ "ORDER BY b.name ASC ", (uid,)) for row in res: out.append([row[0], row[1]]) return out def account_list_baskets(uid, action="", id_basket=0, newname=""): out = "" # query the database for the list of baskets query_result = run_sql("SELECT b.id, b.name, b.public, ub.date_modification "\ "FROM basket b, user_basket ub "\ "WHERE ub.id_user=%s AND b.id=ub.id_basket "\ "ORDER BY b.name ASC ", (uid,)) out += """
""" return out diff --git a/modules/webbasket/lib/webbasket.py.wml b/modules/webbasket/lib/webbasket.py.wml deleted file mode 100644 index 85d2fe4b7..000000000 --- a/modules/webbasket/lib/webbasket.py.wml +++ /dev/null @@ -1,813 +0,0 @@ -## $Id$ -## Personal features - your baskets. - -## This file is part of the CERN Document Server Software (CDSware). -## Copyright (C) 2002, 2003, 2004, 2005 CERN. -## -## The CDSware 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. -## -## The CDSware 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 CDSware; if not, write to the Free Software Foundation, Inc., -## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - -The basket %s is empty.""" % basket_name - out += out_tmp - - return out - - -# delete_basket: present a form for the confirmation of the delete action -# input: the identifier of the selected basket -# the name of the selected basket -# output: the information about the selected basket and the form for the confirmation of the delete action -def delete_basket(uid, id_basket, basket_name): - - # set variables - out = "" - - # search for related alerts - out += """
""" - - return out - - -# perform_delete: present a form for the confirmation of the delete action -# input: delete_alerts='n' if releted alerts shouldn't be deleted; 'y' if yes -# action='YES' if delete action has been confirmed; 'NO' otherwise -# id_basket contains the identifier of the selected basket -# output: go back to the display baskets form with confirmation message -def perform_delete(uid, delete_alerts, confirm_action, id_basket,): - - # set variables - out = "" - - if (confirm_action=='CONFIRM'): - #check that the user which is changing the basket name is the owner of it - if not is_basket_owner( uid, id_basket ): - raise NotBasketOwner("You are not the owner of this basket") - # perform the cancellation - msg = "The selected basket has been deleted." - - if (delete_alerts=='y'): - # delete the related alerts, remove from the alerts table: user_query_basket - query_result = run_sql("DELETE FROM user_query_basket WHERE id_user=%s AND id_basket=%s", - (uid, id_basket)) - msg += " The related alerts have been removed." - else: - # replace the basket identifier with 0 - # select the records to update - query_result = run_sql("SELECT id_query,alert_name,frequency,notification,date_creation,date_lastrun "\ - "FROM user_query_basket WHERE id_user=%s AND id_basket=%s", - (uid, id_basket)) - # update the records - for row in query_result: - query_result_temp = run_sql("UPDATE user_query_basket "\ - "SET alert_name=%s,frequency=%s,notification=%s,"\ - "date_creation=%s,date_lastrun=%s,id_basket='0' "\ - "WHERE id_user=%s AND id_query=%s AND id_basket=%s", - (row[1],row[2],row[3],row[4],row[5],uid,row[0],id_basket)) - - # delete the relation with the user table - query_result = run_sql("DELETE FROM user_basket WHERE id_user=%s AND id_basket=%s", (uid, id_basket)) - # delete the basket information - query_result = run_sql("DELETE FROM basket WHERE id=%s", (id_basket,)) - # delete the basket content - query_result = run_sql("DELETE FROM basket_record WHERE id_basket=%s", (id_basket,)) - - else: - msg="" - - return msg - -# perform_rename_basket: rename an existing basket -# input: basket identifier, basket new name -# output: basket identifier -def perform_rename_basket(uid, id_basket, newname): - # check that there's no basket owned by this user with the same name - if has_user_basket( uid, newname): - raise BasketNameAlreadyExists("You already have a basket which name is '%s'"%newname) - #check that the user which is changing the basket name is the owner of it - if not is_basket_owner( uid, id_basket ): - raise NotBasketOwner("You are not the owner of this basket") - # update a row to the basket table - tmp = run_sql("UPDATE basket SET name=%s WHERE id=%s", (newname, id_basket)) - - return id_basket - -class BasketException(Exception): - """base exception class for basket related errors - """ - pass - -class BasketNameAlreadyExists(BasketException): - """exception which is raised when a basket already exists with a certain name for a user - """ - pass - -class NotBasketOwner(BasketException): - """exception which is raised when a user which is not the owner of a basket tries - to perform an operation over it for which he has no privileges - """ - pass - -def has_user_basket(uid, basket_name): - """checks if a user (uid) already has a basket which name is 'basket_name' (case-sensitive) - """ - return run_sql("select b.id from basket b, user_basket ub where ub.id_user=%s and b.id=ub.id_basket and b.name=%s", - (uid, basket_name.strip())) - -def is_basket_owner(uid, bid): - """checks whether or not the user (uid) is owner for the indicated basket (bid) - """ - return run_sql("select id_basket from user_basket where id_user=%s and id_basket=%s", - (uid, bid)) - - -def get_basket_name(bid): - """returns the name of the basket corresponding to the given id - """ - res = run_sql("select name from basket where id=%s", (bid,)) - if not res: - return "" - return res[0][0] - - -# perform_create_basket: create a new basket and the relation with the user table -# input: basket name -# output: basket identifier -def perform_create_basket(uid, basket_name): - # check that there's no basket owned by this user with the same name - if has_user_basket(uid, basket_name): - raise BasketNameAlreadyExists("You already have a basket which name is '%s'"%basket_name) - # add a row to the basket table - id_basket = run_sql("INSERT INTO basket(id,name,public) VALUES ('0',%s,'n')", (basket_name,)) - - # create the relation between the user and the basket: user_basket - query_result = run_sql("INSERT INTO user_basket(id_user,id_basket,date_modification) VALUES (%s,%s,%s)", - (uid, id_basket, time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))) - return id_basket - - -# basket_exists checks if a basket is in the database -# input: the name of the basket -# output: the id of the basket if it exists, 0 otherwise -def basket_exists (basket_name, uid): - id_basket = run_sql("SELECT b.id FROM basket b, user_basket ub "\ - "WHERE b.name=%s "\ - "AND b.id=ub.id_basket "\ - "AND ub.id_user=%s", - (basket_name, uid)) - return id_basket - -# set_permission: set access permission on a basket -# input: basket identifier, basket public permission -# output: basket identifier -def set_permission(uid, id_basket, permission): - #check that the user which is changing the basket name is the owner of it - if not is_basket_owner( uid, id_basket ): - raise NotBasketOwner("You are not the owner of this basket") - # update a row to the basket table - id_basket = run_sql("UPDATE basket SET public=%s WHERE id=%s", (permission, id_basket)) - - return id_basket - -# remove_items: remove the selected items from the basket -# input: basket identifier, list of selected items -# output: basket identifier -def remove_items(uid, id_basket, mark): - #check that the user which is changing the basket name is the owner of it - if not is_basket_owner( uid, id_basket ): - raise NotBasketOwner("You are not the owner of this basket") - if type(mark)==list: - selected_items=mark - else: - selected_items=[mark] - for i in selected_items: - # delete the basket content - query_result = run_sql("DELETE FROM basket_record WHERE id_basket=%s AND id_record=%s", - (id_basket, i)) - - return id_basket - -# check_copy: check if the record exists already in the basket -# input: basket identifier, list of selected items -# output: boolean -def check_copy(idbask,i): - - query_result = run_sql("select * from basket_record where id_basket=%s and id_record=%s", - (idbask,i)) - if len(query_result)>0 : - return 0 - return 1 - -# copy/move the selected items to another basket -# input: original basket identifier, list of selected items, -# destination basket identifier, copy or move option: "1"=copy, "2"=move -#output: basket identifier -def move_items(uid, id_basket, mark, to_basket, copy_move="1"): - if type(mark)==list: - selected_items=mark - else: - selected_items=[mark] - for i in selected_items: - if check_copy(to_basket,i): - query_result = run_sql("INSERT INTO basket_record(id_basket,id_record,nb_order) VALUES (%s,%s,'0')", - (to_basket, i)) - - if copy_move=="2": - #delete from previous basket - remove_items(uid, id_basket, mark) - - return id_basket - -# change the order of the items in the basket -# input: basket identifier -# identifiers and positions of the items to be moved -#output: basket identifier -def order_items(uid, id_basket,idup,ordup,iddown,orddown): - #check that the user which is changing the basket name is the owner of it - if not is_basket_owner( uid, id_basket ): - raise NotBasketOwner("You are not the owner of this basket") - # move up the item idup (by switching its order number with the other item): - query_result = run_sql("UPDATE basket_record SET nb_order=%s WHERE id_basket=%s AND id_record=%s", - (orddown,id_basket,idup)) - - # move down the item iddown (by switching its order number with the other item): - query_result = run_sql("UPDATE basket_record SET nb_order=%s WHERE id_basket=%s AND id_record=%s", - (ordup,id_basket,iddown)) - - return id_basket - - -# perform_display_public: display the content of the selected basket, if public -# input: the identifier of the basket -# the name of the basket -# of is the output format code -# output: the basket's content -def perform_display_public(uid, id_basket, basket_name, action, to_basket, mark, newname, of): - out = "" - if action=="EXECUTE": - # perform actions - if newname != "": - # create a new basket - to_basket = perform_create_basket(uid, newname) - out += """The private basket %s has been created.No records to add." - # do we have to create some baskets? - if bname: - try: - new_basket_ID = perform_create_basket(uid, bname) - bskIDs = [new_basket_ID] - except BasketException, e: - out += """The basket %s has not been created: %s""" % (bname, e) - if bskIDs == []: - # A - some information missing, so propose list of baskets to choose from - basket_id_name_list = get_list_of_user_baskets(uid) - if basket_id_name_list != []: - # there are some baskets; good - out += "
Please choose the basket you want to add %d records to:" % len(recIDs) - out += """
""" - else: - # user have to create a basket first - out += """You don't own baskets defined yet.""" - out += """
""" - else: - # B - we have baskets IDs, so we can add records - out += """Adding %s records to basket(s)...""" % len(recIDs) - for bskID in bskIDs: - if is_basket_owner(uid, bskID): - for recID in recIDs: - try: - res = run_sql("INSERT INTO basket_record(id_basket,id_record,nb_order) VALUES (%s,%s,%s)", - (bskID,recID,'0')) - except: - pass # maybe records were already there? page reload happened? - out += """done.""" - else: - out += """sorry, you are not the owner of this basket.""" - out += perform_display(uid=uid, id_basket=bskIDs[0]) - return out - -def get_list_of_user_baskets(uid): - """Return list of lists [[basket_id, basket_name],[basket_id, basket_name],...] for the given user.""" - out = [] - res = run_sql("SELECT b.id, b.name "\ - "FROM basket b, user_basket ub "\ - "WHERE ub.id_user=%s AND b.id=ub.id_basket "\ - "ORDER BY b.name ASC ", - (uid,)) - for row in res: - out.append([row[0], row[1]]) - return out - -def account_list_baskets(uid, action="", id_basket=0, newname=""): - - out = "" - # query the database for the list of baskets - query_result = run_sql("SELECT b.id, b.name, b.public, ub.date_modification "\ - "FROM basket b, user_basket ub "\ - "WHERE ub.id_user=%s AND b.id=ub.id_basket "\ - "ORDER BY b.name ASC ", - (uid,)) - - out += """
""" - return out