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