Example #1
0
    def get(self, version='v1'):

        device_id = self.request.get('id')

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

        user = users.get_current_user()

        user_list = UserList.all().filter('google_account =', user).get()
        if user_list is None:
            user_list = UserList()
            user_list.google_account = user
            user_list.device_id = device_id
            user_list.status = 'stable'
            user_list.put()
        else:
            if user_list.status != 'stable':
                logout_url = users.create_logout_url(
                    '/page/welcome?action=logout')

                template_values = {'logout_url': logout_url}

                return self.render_template('page/account_locked.html',
                                            template_values)

        if version == 'v2':
            self.redirect('/page/v2/auth?success=True')
        else:
            self.redirect('/page/archives?action=login')
Example #2
0
 def get(self, version='v1'):
     
     device_id = self.request.get('id')
     
     if version not in ('v1', 'v2'):
         return self.error(501)
     
     user = users.get_current_user()
     
     user_list = UserList.all().filter('google_account =', user).get()
     if user_list is None:
         user_list = UserList()
         user_list.google_account = user
         user_list.device_id = device_id
         user_list.status = 'stable'
         user_list.put()
     else:
         if user_list.status != 'stable':
             logout_url = users.create_logout_url('/page/welcome?action=logout')
             
             template_values = {
                 'logout_url': logout_url
             }
             
             return self.render_template('page/account_locked.html', template_values)
             
     if version == 'v2':
         self.redirect('/page/v2/auth?success=True')
     else:
         self.redirect('/page/archives?action=login')
Example #3
0
def get_related_ids(user_id):
    user_list = UserList.all().filter('user_id', user_id).get()
    
    user_id_list = memcache.get('user_id_list_%s' % user_id)
    if user_id_list is None:
        user_id_list = []
        if user_list is not None:
            related_user_list = UserList.all().filter('google_account =', user_list.google_account).fetch(10)
            
            for row in related_user_list:
                user_id_list.append(row.user_id)
                
        if len(user_id_list) <= 0:
            user_id_list.append(user_id)
        
        memcache.add('user_id_list_%s' % user_id, user_id_list, 3600)
        
        logging.info('Load from datastore.')
    else:
        logging.info('Load from memcache.')
                
    return user_id_list
Example #4
0
    def post(self, version='v2'):
        user = users.get_current_user()

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

        data = {}
        msk_image = self.request.get('mask_image')
        org_image = self.request.get('original_image')
        mask_mode = self.request.get('mask_mode')
        mask_type = self.request.get('mask_type')
        access_code = self.request.get('access_code')

        logging.info('original_image: %d' % len(org_image))
        logging.info('mask_image: %d' % len(msk_image))
        logging.info('User: %s' % user.email())
        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 org_image and msk_image:
            image_key = hashlib.md5('%s' % uuid.uuid4()).hexdigest()

            org_image = images.Image(org_image)
            org_image.resize(width=640)
            #org_image.im_feeling_lucky()
            new_org_image = org_image.execute_transforms(
                output_encoding=images.PNG)
            new_org_image = convert_square(new_org_image, 640, 640)

            memcache.add('tmp_org_%s' % image_key,
                         {'org_image': new_org_image}, 3600)
            memcache.add(
                'tmp_msk_%s' % image_key, {
                    'msk_image': msk_image,
                    'mask_mode': mask_mode,
                    'mask_type': mask_type,
                    'access_code': access_code
                }, 3600)

            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)
Example #5
0
    def post(self):
        user = users.get_current_user()

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

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

        archive_list_query = ArchiveList().all().filter(
            'account =', user_list.key())

        if date != '':
            archive_list_query.filter(
                'created_at <',
                datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S'))
        archive_list_query.order('-created_at')

        archive_list = archive_list_query.fetch(IMAGE_FETCH_COUNT)

        data = []
        for image in archive_list:
            data.append({
                'image_key':
                image.image_key,
                'created_at':
                image.created_at.strftime('%Y-%m-%dT%H:%M:%S+0000')
            })
            date = image.created_at.strftime('%Y-%m-%d %H:%M:%S')
            #logging.info('date: %s' % date)

        archive_list_query = ArchiveList().all().filter(
            'account =', user_list.key())
        archive_list_query.filter(
            'created_at <',
            datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S'))
        archive_list_query.order('-created_at')
        archive_list = archive_list_query.fetch(IMAGE_FETCH_COUNT)

        if len(archive_list) <= 0:
            date = False

        data = {'data': data, 'date': date}

        json_data = json.dumps(data, ensure_ascii=False)
        self.response.content_type = 'application/json'
        self.response.out.write(json_data)
Example #6
0
 def post(self, version='v2'):
     user = users.get_current_user()
     
     if version not in ('v2'):
         return self.error(501)
     
     data = {}
     msk_image = self.request.get('mask_image')
     org_image = self.request.get('original_image')
     mask_mode = self.request.get('mask_mode')
     mask_type = self.request.get('mask_type')
     access_code = self.request.get('access_code')
     
     logging.info('original_image: %d' % len(org_image))
     logging.info('mask_image: %d' % len(msk_image))
     logging.info('User: %s' % user.email())
     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 org_image and msk_image:
         image_key = hashlib.md5('%s' % uuid.uuid4()).hexdigest()
         
         org_image = images.Image(org_image)
         org_image.resize(width=640)
         #org_image.im_feeling_lucky()
         new_org_image = org_image.execute_transforms(output_encoding=images.PNG)
         new_org_image = convert_square(new_org_image, 640, 640)
         
         memcache.add('tmp_org_%s' % image_key, {'org_image': new_org_image}, 3600)
         memcache.add('tmp_msk_%s' % image_key, {'msk_image': msk_image, 'mask_mode': mask_mode, 'mask_type': mask_type, 'access_code': access_code}, 3600)
         
         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)
Example #7
0
 def post(self):
     user = users.get_current_user()
     
     mode = self.request.get('mode')
     delete = self.request.get('delete')
     
     user_list = UserList.all().filter('google_account =', user).filter('status =', 'stable').get()
     if user_list is None:
         return self.error(401)
     
     status = False
     if mode == 'delete':
         if delete == '1':
             try:
                 taskqueue.add(url='/task/delete_all_photos', params={'id': user_list.key().id()})
                 status = True
             except:
                 status = False
                 logging.error('Taskqueue add failed.')
                 
     self.redirect('/page/settings/delete_all_photos?status=%d' % status)
Example #8
0
 def post(self):
     user = users.get_current_user()
     
     date = self.request.get('date')
     
     user_list = UserList.all().filter('google_account =', user).filter('status =', 'stable').get()
     if user_list is None:
         return self.error(401)
     
     archive_list_query = ArchiveList().all().filter('account =', user_list.key())
     
     if date != '':
         archive_list_query.filter('created_at <', datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S'))
     archive_list_query.order('-created_at')
     
     archive_list = archive_list_query.fetch(IMAGE_FETCH_COUNT)
     
     data = []
     for image in archive_list:
         data.append({'image_key': image.image_key, 'created_at': image.created_at.strftime('%Y-%m-%dT%H:%M:%S+0000')})
         date = image.created_at.strftime('%Y-%m-%d %H:%M:%S')
         #logging.info('date: %s' % date)
         
     archive_list_query = ArchiveList().all().filter('account =', user_list.key())
     archive_list_query.filter('created_at <', datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S'))
     archive_list_query.order('-created_at')
     archive_list = archive_list_query.fetch(IMAGE_FETCH_COUNT)
     
     if len(archive_list) <= 0:
         date = False
         
     data = {'data': data, 'date': date}
     
     json_data = json.dumps(data, ensure_ascii=False)
     self.response.content_type = 'application/json'
     self.response.out.write(json_data)
Example #9
0
    def get(self, version='v1'):
        user = users.get_current_user()

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

        action = self.request.get('action')
        if action not in ('login'):
            action = None

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

        if version == 'v1':
            actionButton = False
        else:
            actionButton = True

        if user is None:
            return self.redirect('/page/%s/welcome' % version)

        user_list = UserList.all().filter('google_account =',
                                          user).filter('status =',
                                                       'stable').get()
        if user_list is None:
            return self.redirect('/page/%s/welcome?action=logout' % version)

        archive_list_query = ArchiveList().all().filter(
            'account =', user_list.key()).filter('delete_flg =', False)
        if date != '':
            archive_list_query.filter(
                'created_at <',
                datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S'))
        archive_list_query.order('-created_at')

        archive_list = archive_list_query.fetch(IMAGE_FETCH_COUNT)

        if len(archive_list) <= 0:
            return self.redirect('/page/%s/start?action=login' % version)

        data = []
        for image in archive_list:
            data.append({
                'image_key':
                image.image_key,
                'created_at':
                image.created_at.strftime('%Y-%m-%dT%H:%M:%S+0000')
            })
            date = image.created_at.strftime('%Y-%m-%d %H:%M:%S')
            logging.info('date: %s' % date)

        how_to_use_it = False
        if len(archive_list) < 5:
            how_to_use_it = True

        load_more_hide = False
        if date != '':
            archive_list_query.filter(
                'created_at <',
                datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S'))
            archive_list = archive_list_query.fetch(IMAGE_FETCH_COUNT)
            if len(archive_list) <= 0:
                load_more_hide = True

        account = user.email()
        logout_url = users.create_logout_url('/page/%s/welcome?action=logout' %
                                             version)

        template_values = {
            'archive_list': data,
            'load_more_hide': load_more_hide,
            'date': date,
            'account': account,
            'logout_url': logout_url,
            'action': action,
            'how_to_use_it': how_to_use_it,
            'version': version,
            'actionButton': actionButton
        }

        self.render_template('page/archives.html', template_values)
Example #10
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)
Example #11
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)
Example #12
0
 def get(self, version='v1'):
     user = users.get_current_user()
     
     date = self.request.get('date')
     
     action = self.request.get('action')
     if action not in ('login'):
         action = None
         
     if version not in ('v1', 'v2'):
         return self.error(501)
     
     if version == 'v1':
         actionButton = False
     else:
         actionButton = True
         
     if user is None:
         return self.redirect('/page/%s/welcome' % version)
     
     user_list = UserList.all().filter('google_account =', user).filter('status =', 'stable').get()
     if user_list is None:
         return self.redirect('/page/%s/welcome?action=logout' % version)
     
     archive_list_query = ArchiveList().all().filter('account =', user_list.key()).filter('delete_flg =', False)
     if date != '':
         archive_list_query.filter('created_at <', datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S'))
     archive_list_query.order('-created_at')
     
     archive_list = archive_list_query.fetch(IMAGE_FETCH_COUNT)
     
     if len(archive_list) <= 0:
         return self.redirect('/page/%s/start?action=login' % version)
     
     data = []
     for image in archive_list:
         data.append({'image_key': image.image_key, 'created_at': image.created_at.strftime('%Y-%m-%dT%H:%M:%S+0000')})
         date = image.created_at.strftime('%Y-%m-%d %H:%M:%S')
         logging.info('date: %s' % date)
     
     how_to_use_it = False
     if len(archive_list) < 5:
         how_to_use_it = True
     
     load_more_hide = False
     if date != '':
         archive_list_query.filter('created_at <', datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S'))
         archive_list = archive_list_query.fetch(IMAGE_FETCH_COUNT)
         if len(archive_list) <= 0:
             load_more_hide = True
     
     account = user.email()
     logout_url = users.create_logout_url('/page/%s/welcome?action=logout' % version)
     
     template_values = {
         'archive_list': data,
         'load_more_hide': load_more_hide,
         'date': date,
         'account': account,
         'logout_url': logout_url,
         'action': action,
         'how_to_use_it': how_to_use_it,
         'version': version,
         'actionButton': actionButton
     }
     
     self.render_template('page/archives.html', template_values)