Skip to content
Commits on Source (1)
......@@ -930,17 +930,20 @@ def batch_assign_do():
try:
config.db.query( "DELETE FROM cnm_assignment" )
data = request.form.get( "data" )
data = data.split( "\n" )
assignments_type_dict = get_assignments_types()
sql_insert = utils.sql.sql_insert_generate(
"cnm_assignment",
[ "folder_uuid", "user_id", "assignment_type" ],
"id"
[ "folder_uuid", "user_id", "assignment_type" ]
)
# Preprocess the data
data = request.form.get( "data" )
data = data.split( "\n" )
data = set( data )
# Parse and commit the data
i = 0
for d in data:
if d == "":
continue
......@@ -956,14 +959,19 @@ def batch_assign_do():
user_id = get_user_id( username )
try:
config.db.query_fetchone(
config.db.query(
sql_insert,
( uuid, user_id, assignments_type_dict[ assignment_type ], )
)
# Check for UniqueViolation; This is done with the lookup() function to avoid the linter error
except psycopg2.errors.lookup( "23505" ):
continue
# commit at regular interval
if i % 100 == 0:
config.db.commit()
i += 1
config.db.commit()
......
......@@ -124,6 +124,10 @@
{
var data = $( "#assignements_list" ).val();
$( "#save_button" )
.prop( "disabled", true )
.text( "Please wait..." );
$.ajax( {
url: "{{ url_for( 'afis.batch_assign_do' ) }}",
dataType: "json",
......@@ -174,7 +178,11 @@
modal: true,
width: "550px",
buttons: {
"Save": assignements_function_db,
save: {
id: "save_button",
text: "Save",
click: assignements_function_db
},
"Close": function()
{
$( this ).dialog( "close" );
......