Ejemplo n.º 1
0
    def get(self, photo_id=0):
        user_id, user = self.get_user()

        if not user or not user.admin:
            self.redirect('/')
            return

        photo_id = int(photo_id)
        if photo_id == 0:
            photos = list(Photo.query().fetch())
        else:
            photo = Photo.get_by_id(photo_id)
            if not photo:
                data = {
                    'user': user,
                    'page_title': 'Exif data - no such photo',
                    'message': 'no photo exists with this id',
                }
                self.render('error.html', **data)
            photos = [photo]

        results = []
        for photo in photos:
            exif = blob_exif(photo.blob)
            results.append((
                photo,
                exif,
            ))
            photo.populate(**exif)
            photo.put()

        data = {
            'user': user,
            'page_title': 'Exif data extractor',
            'photos': results,
        }

        self.render('help/exif.html', **data)
Ejemplo n.º 2
0
    def post(self):
        user_id, user = self.get_user()
        #user_id, username = self.get_cookie()
        extra_photo = int(self.request.get('is_photo_extra', '0'))
        if extra_photo:
            upload_files = self.get_uploads('photo-extra-submit')
        else:
            upload_files = self.get_uploads('photo-submit')

        if not upload_files:
            data = {
                'user': user,
                'page_title': 'Upload error',
                'error': 'You forgot to select an image file.'
            }
            self.render('upload_error.html', **data)
            return

        blob_info = upload_files[0]

        if blob_info.content_type != 'image/jpeg':
            # only store jpegs - delete file otherwise
            blob_info.delete()
            data = {
                'user': user,
                'public_profile': True,
                'page_title': 'Upload error',
                'error': (
                    'You tried to upload a file which was '
                    'not a jpeg image.'
                )
            }
            self.render('upload_error.html', **data)
            return

        if extra_photo:
            if blob_info.size > 512 * 1024:
                # only store jpegs - delete file otherwise
                blob_info.delete()
                data = {
                    'user': user,
                    'public_profile': True,
                    'page_title': 'Upload error',
                    'error': (
                        'You tried to upload a file which was '
                        'larger than 512kB.'
                    )
                }
                self.render('upload_error.html', **data)
                return
            extra_data = self._extra_photo(user)
        else:
            extra_data = self._comp_photo(user)

        photo_data = {
            'user': user.key,
            'blob': blob_info.key(),
        }

        exif = blob_exif(blob_info.key())
        photo_data.update(exif)
        photo_data.update(extra_data)

        # add photo details to database
        photo = Photo(**photo_data)
        photo.put()
        logging.info('new photo: %s' % photo)

        self.redirect('/user/%d' % user_id)