Beispiel #1
0
def moveinst(inst_nm, origin_book_nm, target_book_nm):
    origin_book = db_session.query(models.InstrumentMaster).filter_by(name=origin_book_nm).first()
    if origin_book is None:
        return message.noExistBook(origin_book)

    origin_instruments = json.loads(origin_book.instruments)

    if origin_instruments.has_key(inst_nm):
        inst = origin_instruments.pop(inst_nm)

        target_book = db_session.query(models.InstrumentMaster).filter_by(name=target_book_nm).first()
        if target_book is None:
            return message.noExistBook(target_book)

        target_instruments = json.loads(target_book.instruments)

        if target_instruments.has_key(inst_nm):
            return message.instrumentExistInBook(inst_nm, target_book_nm)

        target_instruments[inst_nm] = inst

        target_book.instruments = target_instruments
        db_session.commit()
    else:
        return message.noInstrumentExistInBook(inst_nm, origin_book_nm)
Beispiel #2
0
def removebook(book_nm):
    book = db_session.query(models.MxfBook).filter_by(name=book_nm).first()
    if book is None:
        return message.noExistBook(book_nm)

    db_session.delete(book)
    db_session.commit()
    return 'book : ' + book_nm + ' is removed'
Beispiel #3
0
def removeinst(inst_nm):
    inst = db_session.query(models.InstrumentMaster).filter_by(name=inst_nm).first()
    if inst is None:
        return message.noExistInst(inst_nm)

    db_session.delete(inst)
    db_session.commit()
    return 'inst : ' + inst_nm + ' is removed'
Beispiel #4
0
def make_book(name):
    # if models.LoginID is None:
    #     raise Exception('Login is needed')

    instruments = '''{  }'''

    book  = models.MxfBook(name=name, user=models.LoginID, created_date=datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), instruments=instruments)
    db_session.add(book)
    db_session.commit()

    return book
Beispiel #5
0
def bookinginst(inst_nm, book_nm, contents):
    book = get_book(book_nm)
    if book is None:
        return message.noExistBook(book_nm)

    inst = models.InstrumentMaster(name=inst_nm, contents=contents)

    if inst is not None:
        return message.noInstrumentExistInBook(inst_nm, book_nm)

    db_session.add(inst)
    db_session.commit()
Beispiel #6
0
    def booking(self, inst):
        inst['booked_time'] = datetime.datetime.now().strftime(
            "%Y-%m-%d %H:%M:%S")
        booked_insts = json.loads(self.instruments)

        if inst.name in booked_insts:
            raise Exception('instrument exist. name : ' + inst.name)

        booked_inst = dict()
        booked_inst['open_time'] = inst['booked_time']
        booked_inst['closed_time'] = None
        booked_inst['is_closed'] = False

        # add inst to book
        booked_insts[inst.name] = booked_inst
        self.instruments = json.dumps(booked_insts)

        # self.instruments.append(inst)
        inst_master = InstrumentMaster()
        inst_master.name = inst.name
        inst_master.contents = json.dumps(inst)

        db_session.add(inst_master)
        db_session.commit()