Repository: fossasia/open-event-server

Issue:
Add more steps in Import status messages
Right now, the status "IMPORTING" is shown from the moment import is started to the point where it is done. It is only after that that the status changes to UPLOADING. 
We can add more steps inside IMPORTING that show which file (along with percentage) is being imported like -- 

Importing event
Importing sessions (54/108)
Importing tracks (12/23)
.....



Discussion:

Resolving patch:
diff --git a/app/api/helpers/import_helpers.py b/app/api/helpers/import_helpers.py
--- a/app/api/helpers/import_helpers.py
+++ b/app/api/helpers/import_helpers.py
@@ -160,7 +160,7 @@ def _upload_media(task_handle, event_id, base_path):
     for i in UPLOAD_QUEUE:
         # update progress
         ct += 1
-        update_state(task_handle, 'UPLOADING MEDIA (%d/%d)' % (ct, total))
+        update_state(task_handle, 'Uploading media (%d/%d)' % (ct, total))
         # get upload infos
         name, dao = i['srv']
         id_ = i['id']
@@ -250,7 +250,7 @@ def _fix_related_fields(srv, data, service_ids):
     return data
 
 
-def create_service_from_json(data, srv, event_id, service_ids={}):
+def create_service_from_json(task_handle, data, srv, event_id, service_ids={}):
     """
     Given :data as json, create the service on server
     :service_ids are the mapping of ids of already created services.
@@ -260,8 +260,13 @@ def create_service_from_json(data, srv, event_id, service_ids={}):
     # sort by id
     data.sort(key=lambda k: k['id'])
     ids = {}
+    ct = 0
+    total = len(data)
     # start creating
     for obj in data:
+        # update status
+        ct += 1
+        update_state(task_handle, 'Importing %s (%d/%d)' % (srv[0], ct, total))
         # trim id field
         old_id, obj = _trim_id(obj)
         CUR_ID = old_id
@@ -284,7 +289,7 @@ def import_event_json(task_handle, zip_path):
     """
     global CUR_ID, UPLOAD_QUEUE
     UPLOAD_QUEUE = []
-    update_state(task_handle, 'IMPORTING')
+    update_state(task_handle, 'Started')
 
     with app.app_context():
         path = app.config['BASE_DIR'] + '/static/temp/import_event'
@@ -296,6 +301,7 @@ def import_event_json(task_handle, zip_path):
         z.extractall(path)
     # create event
     try:
+        update_state(task_handle, 'Importing event core')
         data = json.loads(open(path + '/event', 'r').read())
         _, data = _trim_id(data)
         srv = ('event', EventDAO)
@@ -319,7 +325,7 @@ def import_event_json(task_handle, zip_path):
             data = open(path + '/%s' % item[0], 'r').read()
             dic = json.loads(data)
             changed_ids = create_service_from_json(
-                dic, item, new_event.id, service_ids)
+                task_handle, dic, item, new_event.id, service_ids)
             service_ids[item[0]] = changed_ids.copy()
             CUR_ID = None
             item[1].is_importing = False
@@ -333,6 +339,7 @@ def import_event_json(task_handle, zip_path):
         EventDAO.delete(new_event.id)
         raise make_error(item[0], er=ServerError('Invalid json'))
     except Exception:
+        print traceback.format_exc()
         EventDAO.delete(new_event.id)
         raise make_error(item[0], id_=CUR_ID)
     # run uploads


Test patch: