def delete_category(category_id): """ Deleting category by id """ category_to_delete = session.query(Category)\ .filter(Category.id == category_id).first() session.delete(category_to_delete) session.commit()
def deleteCategory(category_id): categoryToDelete = session.query( Category).filter_by(id=category_id).one() if not userIsOwner(categoryToDelete.user_id): return redirect(url_for('showLogin')) if request.method == 'POST': session.delete(categoryToDelete) flash('%s Successfully Deleted' % categoryToDelete.name) session.commit() return redirect(url_for('showCategories', category_id=category_id)) else: return render_template('deleteCategory.html', category=categoryToDelete)
def deleteItem(category_id, item_id): category = session.query(Category).filter_by(id=category_id).one() itemToDelete = session.query(Item).filter_by(id=item_id).one() if not userIsOwner(itemToDelete.user_id): return redirect(url_for('showLogin')) if request.method == 'POST': session.delete(itemToDelete) session.commit() flash('Menu Item Successfully Deleted') return redirect(url_for('showItems', category_id=category_id)) else: return render_template('deleteItem.html', item=itemToDelete)
def update_variable(old_var): old_var.keep = True # Find the new variable from the script. matching_vars = filter( lambda temp_var: temp_var.name == old_var.name, defaults) if matching_vars and old_var.tracks_script: # Check whether we should and can update the old one. new_var = matching_vars[0] map( lambda name: setattr(old_var, name, getattr(new_var, name) ), ["value", "type", "is_advanced", "help_text"] ) # Copy the new one's important attributes onto the old variable. if save: session.add(old_var) session.commit() elif not matching_vars: # Or remove the variable if it doesn't exist any more. if save: session.delete(old_var) session.commit() old_var.keep = False
def create_retry_run(reduction_run, script=None, variables=None, delay=0, username=None): """ Create a run ready for re-running based on the run provided. If variables (RunVariable) are provided, copy them and associate them with the new one, otherwise use the previous run's. If a script (as a string) is supplied then use it, otherwise use the previous run's. """ # find the previous run version, so we don't create a duplicate last_version = -1 for run in session.query(ReductionRun).filter_by( experiment=reduction_run.experiment, run_number=reduction_run.run_number).all(): last_version = max(last_version, run.run_version) # get the script to use: script_text = script if script is not None else reduction_run.script # create the run object and save it new_job = ReductionRun(run_number=reduction_run.run_number, run_version=last_version + 1, run_name="", experiment=reduction_run.experiment, instrument=reduction_run.instrument, script=script_text, status=StatusUtils().get_queued(), created=datetime.datetime.now(), last_updated=datetime.datetime.now(), message="", started_by=username, cancel=0, hidden_in_failviewer=0, admin_log="", reduction_log="") try: session.add(new_job) session.commit() reduction_run.retry_run = new_job reduction_run.retry_when = datetime.datetime.now( ) + datetime.timedelta(seconds=delay if delay else 0) session.add(new_job) session.commit() data_locations = session.query(DataLocation).filter_by( reduction_run_id=reduction_run.id).all() # copy the previous data locations for data_location in data_locations: new_data_location = DataLocation( file_path=data_location.file_path, reduction_run=new_job) session.add(new_data_location) session.commit() if variables is not None: # associate the variables with the new run for var in variables: var.reduction_run = new_job session.add(var) session.commit() else: # provide variables if they aren't already InstrumentVariablesUtils().create_variables_for_run(new_job) return new_job except: session.delete(new_job) session.commit() raise