Exemplo n.º 1
0
    def post(self):
        user_id = self.request.get('id')

        user_list = UserList.get_by_id(int(user_id))

        archive_list = ArchiveList.all().filter('account =',
                                                user_list.key()).filter(
                                                    'delete_flg =',
                                                    False).fetch(10)

        for archive in archive_list:
            archive.delete_flg = True
            archive.updated_at = datetime.datetime.now()
            archive.put()

        logging.info('Operation Account: %s' %
                     user_list.google_account.email())
        logging.info('Deleted %d archives.' % len(archive_list))

        archive_list = ArchiveList.all().filter('account =',
                                                user_list.key()).filter(
                                                    'delete_flg =',
                                                    False).fetch(10)
        if len(archive_list) > 0:
            taskqueue.add(url='/task/delete_all_photos',
                          params={'id': user_id})
Exemplo n.º 2
0
 def post(self):
     user_id = self.request.get('id')
     
     user_list = UserList.get_by_id(int(user_id))
     
     archive_list = ArchiveList.all().filter('account =', user_list.key()).filter('delete_flg =', False).fetch(10)
     
     for archive in archive_list:
         archive.delete_flg = True
         archive.updated_at = datetime.datetime.now()
         archive.put()
     
     logging.info('Operation Account: %s' % user_list.google_account.email())
     logging.info('Deleted %d archives.' % len(archive_list))
     
     archive_list = ArchiveList.all().filter('account =', user_list.key()).filter('delete_flg =', False).fetch(10)
     if len(archive_list) > 0:
         taskqueue.add(url='/task/delete_all_photos', params={'id': user_id})
Exemplo n.º 3
0
 def post(self, version='v1'):
     user = users.get_current_user()
     
     if version not in ('v1', 'v2'):
         return self.error(501)
     
     data = {}
     
     tmp_image_key = self.request.get('tmp_image_key')
     
     if tmp_image_key:
         logging.info('tmp_image_key: %s' % tmp_image_key)
         tmp_org_image = memcache.get('tmp_org_%s' % tmp_image_key)
         tmp_msk_image = memcache.get('tmp_msk_%s' % tmp_image_key)
         
         if tmp_org_image and tmp_msk_image:
             org_image = tmp_org_image['org_image']
             msk_image = tmp_msk_image['msk_image']
             mask_mode = tmp_msk_image['mask_mode']
             mask_type = tmp_msk_image['mask_type']
             access_code = tmp_msk_image['access_code']
         else:
             return self.error(500)
         
     else:
         org_image = self.request.get('original_image')
         msk_image = self.request.get('mask_image')
         mask_mode = self.request.get('mask_mode')
         mask_type = self.request.get('mask_type')
         access_code = self.request.get('access_code')
     
     comment = self.request.get('comment')
     
     logging.info('original_image: %d' % len(org_image))
     logging.info('mask_image: %d' % len(msk_image))
     logging.info('User: %s' % user.email())
     logging.info('Comment: %s', comment)
     logging.info('MaskType: %s', mask_type)
     
     user_list = UserList.all().filter('google_account =', user).filter('status =', 'stable').get()
     if user_list is None:
         return self.error(401)
     
     if len(mask_mode) == 0:
         mask_mode = 'scratch'
     
     mask_mode_list = ['scratch', 'accelerometer1', 'accelerometer2', 'sound_level', 'barcode']
     
     mask_type_list = ['black', 'mosaic', 'caution', 'zebra', 'note']
     if mask_type not in mask_type_list:
         mask_type = 'black'
     
     if org_image and msk_image and mask_mode in mask_mode_list:
         #image_key = hashlib.md5('%s' % uuid.uuid4()).hexdigest()[0:6]
         image_key = gen_imagekey()
         
         # workaround
         tmp_archive = ArchiveList.all().filter('image_key =', image_key).get()
         if tmp_archive is not None:
             return self.error(500)
         
         archive_list = ArchiveList()
         archive_list.image_key = image_key
         archive_list.comment = comment
         archive_list.account = user_list.key()
         archive_list.delete_flg = False
         archive_list.put()
         
         original_image = OriginalImage()
         original_image.archive_list_key = archive_list.key()
         original_image.image = db.Blob(org_image)
         original_image.access_key = hashlib.md5('%s-%s' % (SECRET_IMAGE_KEY, image_key)).hexdigest()
         original_image.put()
         
         mask_image = MaskImage()
         mask_image.mask_mode = mask_mode
         mask_image.archive_list_key = archive_list.key()
         mask_image.image = db.Blob(msk_image)
         mask_image.access_key = hashlib.md5('%s-%s' % (SECRET_MASK_KEY, image_key)).hexdigest()
         mask_image.read_count = 0
         mask_image.access_code = access_code
         mask_image.mask_type = mask_type
         mask_image.put()
         
         data = {'image_key': image_key}
     else:
         data = {'image_key': False}
         
     json_data = json.dumps(data, ensure_ascii=False)
     self.response.content_type = 'application/json'
     self.response.out.write(json_data)
Exemplo n.º 4
0
    def post(self, version='v1'):
        user = users.get_current_user()

        if version not in ('v1', 'v2'):
            return self.error(501)

        data = {}

        tmp_image_key = self.request.get('tmp_image_key')

        if tmp_image_key:
            logging.info('tmp_image_key: %s' % tmp_image_key)
            tmp_org_image = memcache.get('tmp_org_%s' % tmp_image_key)
            tmp_msk_image = memcache.get('tmp_msk_%s' % tmp_image_key)

            if tmp_org_image and tmp_msk_image:
                org_image = tmp_org_image['org_image']
                msk_image = tmp_msk_image['msk_image']
                mask_mode = tmp_msk_image['mask_mode']
                mask_type = tmp_msk_image['mask_type']
                access_code = tmp_msk_image['access_code']
            else:
                return self.error(500)

        else:
            org_image = self.request.get('original_image')
            msk_image = self.request.get('mask_image')
            mask_mode = self.request.get('mask_mode')
            mask_type = self.request.get('mask_type')
            access_code = self.request.get('access_code')

        comment = self.request.get('comment')

        logging.info('original_image: %d' % len(org_image))
        logging.info('mask_image: %d' % len(msk_image))
        logging.info('User: %s' % user.email())
        logging.info('Comment: %s', comment)
        logging.info('MaskType: %s', mask_type)

        user_list = UserList.all().filter('google_account =',
                                          user).filter('status =',
                                                       'stable').get()
        if user_list is None:
            return self.error(401)

        if len(mask_mode) == 0:
            mask_mode = 'scratch'

        mask_mode_list = [
            'scratch', 'accelerometer1', 'accelerometer2', 'sound_level',
            'barcode'
        ]

        mask_type_list = ['black', 'mosaic', 'caution', 'zebra', 'note']
        if mask_type not in mask_type_list:
            mask_type = 'black'

        if org_image and msk_image and mask_mode in mask_mode_list:
            #image_key = hashlib.md5('%s' % uuid.uuid4()).hexdigest()[0:6]
            image_key = gen_imagekey()

            # workaround
            tmp_archive = ArchiveList.all().filter('image_key =',
                                                   image_key).get()
            if tmp_archive is not None:
                return self.error(500)

            archive_list = ArchiveList()
            archive_list.image_key = image_key
            archive_list.comment = comment
            archive_list.account = user_list.key()
            archive_list.delete_flg = False
            archive_list.put()

            original_image = OriginalImage()
            original_image.archive_list_key = archive_list.key()
            original_image.image = db.Blob(org_image)
            original_image.access_key = hashlib.md5(
                '%s-%s' % (SECRET_IMAGE_KEY, image_key)).hexdigest()
            original_image.put()

            mask_image = MaskImage()
            mask_image.mask_mode = mask_mode
            mask_image.archive_list_key = archive_list.key()
            mask_image.image = db.Blob(msk_image)
            mask_image.access_key = hashlib.md5(
                '%s-%s' % (SECRET_MASK_KEY, image_key)).hexdigest()
            mask_image.read_count = 0
            mask_image.access_code = access_code
            mask_image.mask_type = mask_type
            mask_image.put()

            data = {'image_key': image_key}
        else:
            data = {'image_key': False}

        json_data = json.dumps(data, ensure_ascii=False)
        self.response.content_type = 'application/json'
        self.response.out.write(json_data)