def delete_template_folder(service_id, template_folder_id): template_folder = current_service.get_template_folder_with_user_permission_or_403( template_folder_id, current_user) if len( current_service.get_template_folders_and_templates( template_type="all", template_folder_id=template_folder_id)) > 0: flash(_l("You must empty this folder before you can delete it"), "info") return redirect( url_for( ".choose_template", service_id=service_id, template_type="all", template_folder_id=template_folder_id, )) if request.method == "POST": try: template_folder_api_client.delete_template_folder( current_service.id, template_folder_id) return redirect( url_for( ".choose_template", service_id=service_id, template_folder_id=template_folder["parent_id"], )) except HTTPError as e: msg = _l("Folder is not empty") if e.status_code == 400 and msg in e.message: flash(_("You must empty this folder before you can delete it"), "info") return redirect( url_for( ".choose_template", service_id=service_id, template_type="all", template_folder_id=template_folder_id, )) else: abort(500, e) else: flash( "{} ‘{}’ {}".format( _l("Are you sure you want to delete the"), template_folder["name"], _l("folder?"), ), "delete", ) return manage_template_folder(service_id, template_folder_id)
def delete_template_folder(service_id, template_folder_id): template_folder = current_service.get_template_folder_with_user_permission_or_403( template_folder_id, current_user) if len( current_service.get_template_folders_and_templates( template_type="all", template_folder_id=template_folder_id)) > 0: flash("You must empty this folder before you can delete it", 'info') return redirect( url_for('.choose_template', service_id=service_id, template_type="all", template_folder_id=template_folder_id)) if request.method == 'POST': try: template_folder_api_client.delete_template_folder( current_service.id, template_folder_id) return redirect( url_for('.choose_template', service_id=service_id, template_folder_id=template_folder['parent_id'])) except HTTPError as e: msg = "Folder is not empty" if e.status_code == 400 and msg in e.message: flash("You must empty this folder before you can delete it", 'info') return redirect( url_for('.choose_template', service_id=service_id, template_type="all", template_folder_id=template_folder_id)) else: abort(500, e) else: flash( "Are you sure you want to delete the ‘{}’ folder?".format( template_folder['name']), 'delete') return manage_template_folder(service_id, template_folder_id)