def reserve_by_rule(self, rule): self.logger.info('processing rule: id %s' % rule.id) filter = and_(Program.rule_id == None, rule.conditions.make_filter()) programs = Program.get_reservable(filter, sess=self.sess) self.logger.info('%d program(s) to reserve found' % len(programs)) for program in programs: if self.remote_api.reserve(crid=program.crid): self.logger.info('reservation succeeded: crid %s' % program.crid) program.reserve_by = rule self.sess.add(program) self.sess.commit() self.logger.info('update program data: reserved_by = %s' % rule.id) else: self.logger.info('reservation failed: crid %s' % program.crid)
def test(): conditions = generate_conditions() programs = Program.get_reservable(conditions.make_filter()) result = map(lambda p: p.serializable(), programs) return jsonify(status=0, result=result)
def dict_to_program(self, data): p = Program.get_by_crid(data['crid'], sess=self.sess) return self._dict_to_object(data, Program, p)
def index(): dbsess = get_session() rules = Rule.get(sess=dbsess) reserved = Program.get_reserved(sess=dbsess) return render_template("index.html", rules=rules, reserved_programs=reserved)