def upload(self, column_name, content_id):
        form = FileForm()
        content = Content.query.get(content_id)

        if request.method == 'POST':
            try:
                # Save form data to (temporary) local file
                filename = secure_filename(str(kst_now()) + form.file.data.filename)
                form.file.data.save(filename)

                # Upload local file to S3 (Note this is a blocking call)
                image_path = 'uploads/%s' % filename
                aws_key = current_app.config.get('AWS_KEY', None)
                aws_secret_key = current_app.config.get('AWS_SECRET_KEY', None)
                if not aws_key or not aws_secret_key:
                    flash('AWS키가 설정되지 않았습니다.', 'error')
                    raise Exception
                boto3_session = boto3.session.Session(aws_access_key_id=aws_key,
                                                      aws_secret_access_key=aws_secret_key)
                boto3_session.client('s3')
                s3_client = boto3_session.client('s3')
                s3_client.upload_file(filename, 'ticketplace', image_path)

                # Set Image path to column
                setattr(content, column_name, filename)
                self.session.add(content)
                self.session.commit()

                flash('이미지 업로드 완료')
            except:
                flash('이미지 업로드 실패', 'error')
            return redirect(url_for('image.index_view'))

        return self.render('admin/upload.html', form=form, content=content, column_name=column_name)
 def timeago_filter(from_date, to_date=kst_now()):
     interval = to_date - from_date
     interval_second = int(interval.total_seconds())
     if interval_second < 60:
         return str(interval_second) + '초 전'
     elif interval_second < 60 * 60:
         return str(interval_second // 60) + '분 전'
     elif interval_second < 60 * 60 * 24:
         return str(interval_second // (60 * 60)) + '시간 전'
     elif interval_second < 60 * 60 * 24 * 30:
         return str(interval_second // (60 * 60 * 24)) + '일 전'
     elif interval_second < 60 * 60 * 24 * 365:
         return str(interval_second // (60 * 60 * 24 * 30)) + '개월 전'
     else:
         return str(interval_second // (60 * 60 * 24 * 365)) + '년 전'
 def test_company_created_date(self):
     company = Company.query.filter_by(username='******').first()
     assert kst_now() - company.created_date < datetime.timedelta(hours=1)