Пример #1
0
 def process_girl(self, data):
     """:rtype: (Girl, bool)"""
     try:
         girl_id = data['girl_id']
         return Girl.find_by_pk_with_cache(girl_id), False
     except Girl.DoesNotExist:
         girl = Girl()
         girl.id = data['girl_id']
         girl.name = data['name']
         girl.age = data.get('age')
         girl.shop_id = data.get('shop_id')
         girl.img_url = data['img_url']
         self.save_or_raise(girl)
         return girl, True
Пример #2
0
    def process_attendance(self, data):
        """:rtype: (Attendance, bool)"""
        if data.get('clock_in') is None or data.get('clock_out') is None:
            raise NotOurDataException

        try:
            pk = Attendance.composite_pk(
                data['girl_id'],
                to_biz_date(data['checked_term']))
            return Attendance.find_by_pk_with_cache(pk), False
        except Attendance.DoesNotExist:
            atnd = Attendance()
            atnd.girl = Girl.find_by_pk_with_cache(data['girl_id'])
            atnd.date = to_biz_date(data['checked_term'])
            atnd.clock_in = data['clock_in']
            atnd.clock_out = data['clock_out']
            self.save_or_raise(atnd)
            return atnd, True