예제 #1
0
파일: room.py 프로젝트: TelematicaUSM/Tidys
    def create(cls, name, svg_path):
        try:
            _path = msg.join_path(cls._path, 'create')

            ElementTree.register_namespace('', NS['svg'])
            elem_tree = yield run_in_thread(
                ElementTree.parse, svg_path)

            seat_circles = elem_tree.iterfind(
                ".//svg:circle[@class='seat']", NS)
            seat_attributes = (c.attrib
                               for c in seat_circles)
            seats = {a['id']: {'used': False,
                               'x': a['cx'],
                               'y': a['cy']}
                     for a in seat_attributes}

            self = yield super().create(name)
            self.setattr(
                '_map', elem_tree.getroot()
            )
            yield self.store_dict(
                {
                    'map_source': ElementTree.tostring(
                        self.map, encoding="unicode"),
                    'seats': seats
                }
            )

            code = yield Code.create(
                room_id=self.id, code_type=CodeType.room)

            codes = [code]
            for seat in self.seats:
                code = yield Code.create(
                    room_id=self.id,
                    code_type=CodeType.seat,
                    seat_id=seat
                )
                codes.append(code)

            return (self, codes)

        except DuplicateKeyError:
            raise

        except OperationFailure:
            msg.obj_creation_error(_path, cls, name=name,
                                   svg_path=svg_path)
            cls.coll.remove(name)
            raise
예제 #2
0
파일: room.py 프로젝트: TelematicaUSM/Tidys
    def create(cls, name, svg_path):
        try:
            _path = msg.join_path(cls._path, 'create')

            ElementTree.register_namespace('', NS['svg'])
            elem_tree = yield run_in_thread(ElementTree.parse, svg_path)

            seat_circles = elem_tree.iterfind(".//svg:circle[@class='seat']",
                                              NS)
            seat_attributes = (c.attrib for c in seat_circles)
            seats = {
                a['id']: {
                    'used': False,
                    'x': a['cx'],
                    'y': a['cy']
                }
                for a in seat_attributes
            }

            self = yield super().create(name)
            self.setattr('_map', elem_tree.getroot())
            yield self.store_dict({
                'map_source':
                ElementTree.tostring(self.map, encoding="unicode"),
                'seats':
                seats
            })

            code = yield Code.create(room_id=self.id, code_type=CodeType.room)

            codes = [code]
            for seat in self.seats:
                code = yield Code.create(room_id=self.id,
                                         code_type=CodeType.seat,
                                         seat_id=seat)
                codes.append(code)

            return (self, codes)

        except DuplicateKeyError:
            raise

        except OperationFailure:
            msg.obj_creation_error(_path, cls, name=name, svg_path=svg_path)
            cls.coll.remove(name)
            raise
예제 #3
0
 def create(cls, room_id, code_type, seat_id=None):
     code_path = cls.path + '.create'
     creat_err_msg = lambda: msg.obj_creation_error(
         code_path, cls, room_id=room_id,
         code_type=code_type, seat_id=seat_id)
         
     if not isinstance(code_type, CodeType):
         raise TypeError
     
     if seat_id and not isinstance(seat_id, str):
         raise TypeError
     
     if (code_type is CodeType.room) == bool(seat_id):
         raise ValueError
     
     try:
         #Throws NoObjectReturnedFromDB
         room = yield Room(room_id)
             
         for i in range(200):
             try:
                 code = random_word(5,
                     ascii_lowercase+digits)
                 self = yield super().create(code)
                 break
                 
             except DuplicateKeyError:
                 msg.try_new_id_after_dup_obj_in_db(
                     cls.path+'.create')
         else:
             msg.exhausted_tries(cls.path+'.create')
         
         self.setattr('_room', room)
         #Trhows OperationFailure
         yield self.store_dict(
             {'room_id': room_id,
              'code_type': code_type.value,
              'seat_id': seat_id})
         return self
     
     except NoObjectReturnedFromDB:
         creat_err_msg()
         raise OperationFailure
     
     except OperationFailure:
         creat_err_msg()
         cls.coll.remove(code)
         raise
예제 #4
0
파일: room.py 프로젝트: TelematicaUSM/Tidys
 def creat_err_msg():
     msg.obj_creation_error(_path, cls,
                            room_id=room_id,
                            code_type=code_type,
                            seat_id=seat_id)
예제 #5
0
파일: room.py 프로젝트: TelematicaUSM/Tidys
 def creat_err_msg():
     msg.obj_creation_error(_path,
                            cls,
                            room_id=room_id,
                            code_type=code_type,
                            seat_id=seat_id)