def delete_entry(request, primary_key): model_name, model = get_model_name_and_model(request) model.objects.get(pk=primary_key).delete() unsaved_changes(True) if model_name not in singletons: return redirect('/setup/%s/' % model_name) # model list else: return redirect('/setup/%s/new/' % model_name) # Population can be deleted, maybe others
def open_scenario(request, target, wrap_target=True): if wrap_target: target = workspace_path(target) print("Copying ", target, "to", db_path(), ". This could take several minutes...") close_old_connections() shutil.copy(target, db_path(name='scenario_db')) scenario_filename(os.path.basename(target)) print('Sessions overwritten with ', target) update_db_version() unsaved_changes(False) # File is now in sync SmSession.objects.all().update(iteration_text = '', simulation_has_started=outputs_exist()) # This is also reset from delete_all_outputs # else: # print('File does not exist') return redirect('/setup/Scenario/1/')
def adsm_context(request): context = {} if not request.is_ajax() and request.path and request.path != '/' and '/LoadingScreen/' not in request.path: session = SmSession.objects.get() version = session.update_available context = {'filename': scenario_filename(), # context in either mode 'unsaved_changes': unsaved_changes(), 'url': request.path, 'active_link': '/'.join(re.split('\W+', request.path)[2:]), 'dev_version': __version__, 'update_version': version if version and version != 'False' and version != '0' else '', 'workspace_path': workspace_path(), 'db_files': (file_list(".sqlite3")), 'show_help_text': session.show_help_text } return context
def save_scenario(request=None): """Save to the existing session of a new file name if target is provided """ if request is not None and 'filename' in request.POST: target = request.POST['filename'] else: target = scenario_filename() target = strip_tags(target) full_path = workspace_path(target) + ('.sqlite3' if not target.endswith('.sqlite3') else '') try: if '\\' in target or '/' in target: # this validation has to be outside of scenario_filename in order for open_test_scenario to work raise ValueError("Slashes are not allowed: " + target) scenario_filename(target) print('Copying database to', target) shutil.copy(db_path(), full_path) unsaved_changes(False) # File is now in sync print('Done Copying database to', full_path) except (IOError, AssertionError, ValueError) as err: if request is not None: save_error = 'Failed to save filename:' + str(err) print('Encountered an error while copying file', full_path) return render(request, 'ScenarioName.html', {"failure_message": save_error}) if request is not None and request.is_ajax(): return render(request, 'ScenarioName.html', {"success_message": "File saved to " + target, "filename": scenario_filename(), 'unsaved_changes': unsaved_changes()}) else: return redirect('/setup/Scenario/1/')