def update_accommodation(id_): """Update an accommodation in the database """ accommodation = request.get_json(force=True, silent=True) if not accommodation: return make_error('No accommodation details provided') try: accommodation['id'] = validate_id(id_) validate(accommodation, expect_id=True) accommodation = g.tx.accommodations.update(accommodation) except utils.StoneretreatException as e: return make_error(str(e)) return make_success(accommodation)
def list_accommodations(): """Get a list of all the accommodations for this year """ try: rval = g.tx.accommodations.list_() except utils.StoneretreatException as e: return make_error(str(e)) return make_success(rval)
def list_charges(): """Return a json list of all the charges in the database """ try: rval = g.tx.charges.list_() except utils.StoneretreatException as e: return make_error(str(e)) return make_success(rval)
def list_years(): """Return a json list of all the years """ g.log.debug('list_years') try: rval = g.tx.years.list_() except utils.StoneretreatException as e: return make_error(str(e)) return make_success(rval)
def delete_charge(id_): """API endpoint to remove a charge from the database """ try: id_ = validate_id(id_) g.tx.charges.delete(id_) except utils.StoneretreatException as e: return make_error(str(e)) return make_success({})
def get_accommodation(id_): """Get an accommodation from the database """ try: id_ = validate_id(id_) accommodation = g.tx.accommodations.get(id_) except utils.StoneretreatException as e: return make_error(str(e)) return make_success(accommodation)
def delete_accommodation(id_): """Remove an accommodation from the database """ try: id_ = validate_id(id_) g.tx.accommodations.delete(id_) except utils.StoneretreatException as e: return make_error(str(e)) return make_success({})
def get_charge(id_): """API endpoint to get a charge from the database """ try: id_ = validate_id(id_) charge = g.tx.charges.get(id_) except utils.StoneretreatException as e: return make_error(str(e)) return make_success(charge)
def add_charge(): """API endpoint to add a charge to the database """ charge = request.get_json(force=True, silent=True) try: validate(charge, expect_id=False) charge = g.tx.charges.new(charge) except utils.StoneretreatException as e: return make_error(str(e)) return make_success(charge)
def add_accommodation(): """Add an accommodation to the database """ accommodation = request.get_json(force=True, silent=True) try: validate(accommodation, expect_id=False) accommodation = g.tx.accommodations.new(accommodation) except utils.StoneretreatException as e: return make_error(str(e)) return make_success(accommodation)
def update_charge(id_): """API endpoint to modify a charge's info in the database """ charge = request.get_json(force=True, silent=True) try: charge['id'] = validate_id(id_) validate(charge, expect_id=True) g.tx.charges.udpate(charge) except utils.StoneretreatException as e: return make_error(str(e)) return make_success(charge)
def add_this_year(): """Adds the current year to the database, and makes it the year that modifications will apply to """ g.log.debug('add_this_year') this_year = time.localtime(time.time()).tm_year g.log.debug('year = %s' % (this_year,)) try: g.tx.years.create(this_year) except utils.StoneretreatException as e: g.log.debug('failed to create year: %s' % (str(e),)) return make_error(str(e)) return make_success({'year': this_year})
def set_year(): """Sets the year to be modified in the database """ g.log.debug('set_year') req = request.get_json(force=True, silent=True) g.log.debug('req = %s' % (req,)) if not req: return make_error('Bad request') if 'year' not in req: return make_error('Missing year') try: # We don't strictly have to do this here, but nice to make sure it'll # work before shoving something potentially broken in the session g.tx.years.use(req['year']) except utils.StoneretreatException as e: g.log.debug('failed to use year: %s' % (str(e),)) return make_error(str(e)) session['year'] = req['year'] return make_success({'year': req['year']})
def get_year(year): """Get a year out of the database :return: """ g.log.debug('get_year %s' % (year,)) return make_error('Not implemented')
def add_year(year): """Adds an arbitrary year to the database, and makes it the year that modifications will apply to """ g.log.debug('add_year %s' % (year,)) return make_error('Not implemented')
def delete_year(year): """Remove a year (and all its associated data) from the database. """ g.log.debug('delete_year %s' % (year,)) return make_error('Not implemented')
def update_year(year): """Currently not used - nothing to do """ g.log.debug('update_year %s' % (year,)) return make_error('Not implemented')