def set_data_review_status(): recid = int(request.form['publication_recid']) data_id = int(request.form['data_recid']) status = request.form['status'] version = int(request.form['version']) if user_allowed_to_perform_action(recid): record_sql = DataReview.query.filter_by(data_recid=data_id, version=version) try: record = record_sql.first() except NoResultFound: record = create_data_review(data_id, recid, version) record_sql.update({"status": status}, synchronize_session='fetch') try: db.session.commit() except Exception: db.session.rollback() return jsonify( {"recid": record.publication_recid, "data_id": record.data_recid, "status": record.status}) return jsonify( {"recid": recid, "data_id": data_id, 'message': 'You are not authorised to update the review status for ' 'this data record.'})
def set_data_review_status(): recid = int(request.form["publication_recid"]) data_id = int(request.form["data_recid"]) status = request.form["status"] version = int(request.form["version"]) if user_allowed_to_perform_action(recid): record_sql = DataReview.query.filter_by(data_recid=data_id, version=version) try: record = record_sql.one() except NoResultFound: record = create_data_review(data_id, recid, version) record_sql.update({"status": status}, synchronize_session="fetch") try: db.session.commit() except Exception: db.session.rollback() return jsonify({"recid": record.publication_recid, "data_id": record.data_recid, "status": record.status}) return jsonify( { "recid": recid, "data_id": data_id, "message": "You are not authorised to update the review status for " "this data record.", } )
def add_data_review_messsage(publication_recid, data_recid): """ Adds a new review message for a data submission. :param publication_recid: :param data_recid: """ trace = [] message = encode_string(request.form.get('message', '')) version = request.form['version'] userid = current_user.get_id() try: datareview_query = DataReview.query.filter_by(data_recid=data_recid, version=version) # if the data review is not already created, create one. try: data_review_record = datareview_query.one() trace.append("adding data review record") except: data_review_record = create_data_review(data_recid, publication_recid) trace.append("created a new data review record") data_review_message = Message(user=userid, message=message) data_review_record.messages.append(data_review_message) db.session.commit() current_user_obj = get_user_from_id(userid) update_action_for_submission_participant(publication_recid, userid, 'reviewer') send_new_review_message_email(data_review_record, data_review_message, current_user_obj) return json.dumps( { "publication_recid": data_review_record.publication_recid, "data_recid": data_review_record.data_recid, "status": data_review_record.status, "message": decode_string(data_review_message.message), "post_time": data_review_message.creation_date, 'user': current_user_obj.email }, default=default_time) except Exception as e: db.session.rollback() raise e
def set_data_review_status(): recid = int(request.form['publication_recid']) status = request.form['status'] version = int(request.form['version']) all_tables = request.form.get('all_tables') if user_allowed_to_perform_action(recid): if all_tables: data_ids = db.session.query(DataSubmission.id) \ .filter_by(publication_recid=recid, version=version).distinct() else: data_ids = [int(request.form['data_recid'])] for data_id in data_ids: record_sql = DataReview.query.filter_by(data_recid=data_id, version=version) record = record_sql.first() if not record: record = create_data_review(data_id, recid, version) record_sql.update({"status": status}, synchronize_session='fetch') try: db.session.commit() success = True except Exception: db.session.rollback() success = False if all_tables: return jsonify({"recid": recid, "success": success}) else: return jsonify({ "recid": record.publication_recid, "data_id": record.data_recid, "status": record.status }) return jsonify({ "recid": recid, 'message': 'You are not authorised to update the review status for ' 'this data record.' })
def assign_or_create_review_status(data_table_metadata, publication_recid, version): """ If a review already exists, it will be attached to the current data record. If a review does not exist for a data table, it will be created. :param data_table_metadata: the metadata describing the main table. :param publication_recid: publication record id :param version: """ data_review_query = DataReview.query.filter_by( publication_recid=publication_recid, version=version) # this method should also create all the DataReviews for data_tables that # are not currently present to avoid # only creating data reviews when the review is clicked explicitly. assigned_tables = [] if data_review_query.count() > 0: data_review_records = data_review_query.all() for data_review in data_review_records: if data_review.data_recid in data_table_metadata: data_table_metadata[ data_review.data_recid]["review_flag"] = data_review.status data_table_metadata[data_review.data_recid]["review_status"] = \ RECORD_PLAIN_TEXT[data_review.status] data_table_metadata[data_review.data_recid]["messages"] = len( data_review.messages) > 0 assigned_tables.append(data_review.data_recid) # now create the missing data reviews for data_table_id in data_table_metadata: if data_table_id not in assigned_tables: data_record = create_data_review(data_table_id, publication_recid, version=version) data_table_metadata[data_table_id][ "review_flag"] = data_record.status data_table_metadata[data_table_id]["review_status"] = \ RECORD_PLAIN_TEXT[data_record.status]
def add_data_review_messsage(publication_recid, data_recid): # need to set up a session and query for the data review. trace = [] message = request.form["message"] version = request.form["version"] userid = current_user.get_id() datareview_query = DataReview.query.filter_by(data_recid=data_recid, version=version) # if the data review is not already created, create one. try: data_review_record = datareview_query.one() trace.append("adding data review record") except: data_review_record = create_data_review(data_recid, publication_recid) trace.append("created a new data review record") data_review_message = Message(user=userid, message=message) data_review_record.messages.append(data_review_message) db.session.commit() current_user_obj = get_user_from_id(userid) update_action_for_submission_participant(publication_recid, userid, "reviewer") send_new_review_message_email(data_review_record, data_review_message, current_user_obj) return json.dumps( { "publication_recid": data_review_record.publication_recid, "data_recid": data_review_record.data_recid, "status": data_review_record.status, "message": data_review_message.message, "post_time": data_review_message.creation_date, "user": current_user_obj.email, }, default=default_time, )
def assign_or_create_review_status(data_table_metadata, publication_recid, version): """ If a review already exists, it will be attached to the current data record. If a review does not exist for a data table, it will be created. :param data_table_metadata: the metadata describing the main table. :param publication_recid: publication record id """ data_review_query = DataReview.query.filter_by( publication_recid=publication_recid, version=version) # this method should also create all the DataReviews for data_tables that # are not currently present to avoid # only creating data reviews when the review is clicked explicitly. assigned_tables = [] if data_review_query.count() > 0: data_review_records = data_review_query.all() for data_review in data_review_records: if data_review.data_recid in data_table_metadata: data_table_metadata[data_review.data_recid][ "review_flag"] = data_review.status data_table_metadata[data_review.data_recid]["review_status"] = \ RECORD_PLAIN_TEXT[data_review.status] data_table_metadata[data_review.data_recid]["messages"] = len( data_review.messages) > 0 assigned_tables.append(data_review.data_recid) # now create the missing data reviews for data_table_id in data_table_metadata: if data_table_id not in assigned_tables: data_record = create_data_review( data_table_id, publication_recid, version=version) data_table_metadata[data_table_id][ "review_flag"] = data_record.status data_table_metadata[data_table_id]["review_status"] = \ RECORD_PLAIN_TEXT[data_record.status]
def get_table_details(recid, data_recid, version): """ :param recid: :param data_recid: :param version: :return: """ datasub_query = DataSubmission.query.filter_by(id=data_recid, version=version) table_contents = {} if datasub_query.count() > 0: datasub_record = datasub_query.one() data_query = db.session.query(DataResource).filter(DataResource.id == datasub_record.data_file) if data_query.count() > 0: data_record = data_query.one() file_location = data_record.file_location try: table_contents = yaml.load(file(file_location), Loader=yaml.CSafeLoader) except: table_contents = yaml.load(file(file_location)) table_contents["name"] = datasub_record.name table_contents["title"] = datasub_record.description table_contents["keywords"] = datasub_record.keywords table_contents["doi"] = datasub_record.doi # we create a map of files mainly to accommodate the use of thumbnails for images where possible. tmp_assoc_files = {} for associated_data_file in datasub_record.resources: alt_location = associated_data_file.file_location location_parts = alt_location.split("/") key = location_parts[-1].replace("thumb_", "") if key not in tmp_assoc_files: tmp_assoc_files[key] = {} if "thumb_" in alt_location: tmp_assoc_files[key]["preview_location"] = "/record/resource/{0}?view=true".format( associated_data_file.id ) else: tmp_assoc_files[key].update( { "description": associated_data_file.file_description, "type": associated_data_file.file_type, "id": associated_data_file.id, "alt_location": alt_location, } ) # add associated files to the table contents table_contents["associated_files"] = tmp_assoc_files.values() table_contents["review"] = {} data_review_record = create_data_review(data_recid, recid, version) table_contents["review"]["review_flag"] = data_review_record.status table_contents["review"]["messages"] = len(data_review_record.messages) > 0 # translate the table_contents to an easy to render format of the qualifiers (with colspan), # x and y headers (should not require a colspan) # values, that also encompass the errors return jsonify(generate_table_structure(table_contents))
def get_table_details(recid, data_recid, version): """ Get the table details. :param recid: :param data_recid: :param version: :return: """ datasub_query = DataSubmission.query.filter_by(id=data_recid, version=version) table_contents = {} if datasub_query.count() > 0: datasub_record = datasub_query.one() data_query = db.session.query(DataResource).filter( DataResource.id == datasub_record.data_file) if data_query.count() > 0: data_record = data_query.one() file_location = data_record.file_location attempts = 0 while True: try: with open(file_location, 'r') as table_file: table_contents = yaml.load(table_file, Loader=Loader) except: attempts += 1 # allow multiple attempts to read file in case of temporary disk problems if (table_contents and table_contents is not None) or attempts > 5: break table_contents["name"] = datasub_record.name table_contents["title"] = datasub_record.description table_contents["keywords"] = datasub_record.keywords table_contents["doi"] = datasub_record.doi table_contents["location"] = datasub_record.location_in_publication # we create a map of files mainly to accommodate the use of thumbnails for images where possible. tmp_assoc_files = {} for associated_data_file in datasub_record.resources: alt_location = associated_data_file.file_location location_parts = alt_location.split('/') key = location_parts[-1].replace("thumb_", "") if key not in tmp_assoc_files: tmp_assoc_files[key] = {} if "thumb_" in alt_location and associated_data_file.file_type.lower() in IMAGE_TYPES: tmp_assoc_files[key]['preview_location'] = '/record/resource/{0}?view=true'.format( associated_data_file.id) else: tmp_assoc_files[key].update({'description': associated_data_file.file_description, 'type': associated_data_file.file_type, 'id': associated_data_file.id, 'alt_location': alt_location}) # add associated files to the table contents table_contents['associated_files'] = list(tmp_assoc_files.values()) table_contents["review"] = {} data_review_record = create_data_review(data_recid, recid, version) table_contents["review"]["review_flag"] = data_review_record.status if data_review_record else "todo" table_contents["review"]["messages"] = len(data_review_record.messages) > 0 if data_review_record else False # translate the table_contents to an easy to render format of the qualifiers (with colspan), # x and y headers (should not require a colspan) # values, that also encompass the errors return jsonify(generate_table_structure(table_contents))