(project_string_id)
| 176 | methods = ['POST']) |
| 177 | @Project_permissions.user_has_project(["admin", "Editor"]) |
| 178 | def label_edit(project_string_id): |
| 179 | with sessionMaker.session_scope() as session: |
| 180 | |
| 181 | data = request.get_json(force = True) # Force = true if not set as application/json' |
| 182 | label_file = data.get('label_file', None) |
| 183 | |
| 184 | if label_file is None: |
| 185 | return json.dumps("file is None"), 400, {'ContentType': 'application/json'} |
| 186 | |
| 187 | label_proposed = label_file.get('label', None) |
| 188 | if label_proposed is None: |
| 189 | return json.dumps("label is None"), 400, {'ContentType': 'application/json'} |
| 190 | |
| 191 | name_proposed = label_proposed.get('name', None) |
| 192 | if name_proposed is None or len(name_proposed) < 1: |
| 193 | return json.dumps("label less than 1 character"), 400, {'ContentType': 'application/json'} |
| 194 | |
| 195 | label_file_id = label_file.get('id', None) |
| 196 | if label_file_id is None: |
| 197 | return json.dumps("no label id"), 400, {'ContentType': 'application/json'} |
| 198 | |
| 199 | # WIP... |
| 200 | user_id = getUserID(session = session) |
| 201 | |
| 202 | existing_file = File.get_by_id_untrusted(session, |
| 203 | user_id, |
| 204 | project_string_id, |
| 205 | label_file_id) |
| 206 | |
| 207 | if existing_file is None: |
| 208 | return jsonify("No file"), 400 |
| 209 | |
| 210 | if existing_file.committed is not True: |
| 211 | |
| 212 | project = Project.get(session, project_string_id) |
| 213 | |
| 214 | user = session.query(User).filter(User.id == user_id).one() |
| 215 | working_dir = project.directory_default |
| 216 | |
| 217 | colour_proposed = label_file.get("colour", None) |
| 218 | |
| 219 | # Caution |
| 220 | # We need this because we are trying to |
| 221 | # maintain unique labels... |
| 222 | # It's the Label() class we are getting not the File() |
| 223 | # (Which we already have). |
| 224 | label = Label.new( |
| 225 | session, |
| 226 | name=name_proposed) |
| 227 | |
| 228 | existing_file.label_id = label.id |
| 229 | existing_file.colour = colour_proposed |
| 230 | |
| 231 | session.add(existing_file) |
| 232 | |
| 233 | working_dir.label_file_colour_map[existing_file.id] = colour_proposed |
| 234 | # Caution: https://stackoverflow.com/questions/42559434/updates-to-json-field-dont-persist-to-db |
| 235 | flag_modified(working_dir, "label_file_colour_map") |
nothing calls this directly
no test coverage detected