Пример #1
0
 def get(self, meh_id):
     if self.exists(meh_id):
         meh = Mechanics.query.get(meh_id)
         return Mechanic(meh_id=meh.mongo_id,
                         name=meh.name,
                         lvl=meh.lvl,
                         year=meh.year)
     else:
         return None
Пример #2
0
 def test_get_right(self):
     rep = MehRepository()
     meh_id = rep.create('a', 'a', '100')
     meh1 = rep.get(meh_id)
     meh2 = Mechanic(meh_id=fields.ObjectId(meh_id),
                     name='a',
                     lvl='a',
                     year='100')
     self.assertEqual(meh1, meh2)
     rep.delete(meh_id)
Пример #3
0
 def read_paginated(self, page_number, page_size):
     mehs = []
     mehs_paginated = Mechanics.query.paginate(page=page_number,
                                               per_page=page_size)
     for meh in mehs_paginated.items:
         mehs.append(
             Mechanic(meh_id=meh.mongo_id,
                      name=meh.name,
                      lvl=meh.lvl,
                      year=meh.year))
     is_prev_num = (mehs_paginated.prev_num > 0)
     is_next_num = (mehs_paginated.next_num <= mehs_paginated.pages)
     return mehs, is_prev_num, is_next_num