summaryrefslogtreecommitdiff
path: root/animism-align/cli/app
diff options
context:
space:
mode:
Diffstat (limited to 'animism-align/cli/app')
-rw-r--r--animism-align/cli/app/controllers/upload_controller.py26
-rw-r--r--animism-align/cli/app/sql/models/media.py2
-rw-r--r--animism-align/cli/app/sql/versions/202007171640_add_post_title_to_media.py29
3 files changed, 46 insertions, 11 deletions
diff --git a/animism-align/cli/app/controllers/upload_controller.py b/animism-align/cli/app/controllers/upload_controller.py
index 1a324cb..e910f28 100644
--- a/animism-align/cli/app/controllers/upload_controller.py
+++ b/animism-align/cli/app/controllers/upload_controller.py
@@ -86,10 +86,18 @@ class UploadView(FlaskView):
# except:
# return jsonify({ 'status': 'error', 'error': 'Image parse error' })
+ uploaded_im_fn = secure_filename(file.filename)
+ uploaded_im_abspath = os.path.join(app_cfg.DIR_UPLOADS, tag)
+ uploaded_im_fullpath = os.path.join(uploaded_im_abspath, uploaded_im_fn)
+
session = Session()
upload = session.query(Upload).filter_by(sha256=sha256).first()
if upload is not None:
print("Already uploaded image")
+ if not os.path.exists(uploaded_im_fullpath):
+ # if we got in some weird state where the record wasnt deleted....
+ os.makedirs(uploaded_im_abspath, exist_ok=True)
+ file.save(uploaded_im_fullpath)
response = {
'status': 'ok',
'notes': 'Image already uploaded',
@@ -98,16 +106,10 @@ class UploadView(FlaskView):
session.close()
return jsonify(response)
- uploaded_im_fn = secure_filename(file.filename)
- uploaded_im_abspath = os.path.join(app_cfg.DIR_UPLOADS, tag)
- uploaded_im_fullpath = os.path.join(uploaded_im_abspath, uploaded_im_fn)
- uploaded_im_stored_fn = uploaded_im_fn
-
os.makedirs(uploaded_im_abspath, exist_ok=True)
- # nparr.tofile(uploaded_im_fullpath)
file.save(uploaded_im_fullpath)
- upload = Upload(username=username, tag=tag, fn=uploaded_im_stored_fn, sha256=sha256, ext=ext)
+ upload = Upload(username=username, tag=tag, fn=uploaded_im_fn, sha256=sha256, ext=ext)
session.add(upload)
session.commit()
response = {
@@ -135,11 +137,13 @@ class UploadView(FlaskView):
tag = upload.tag
# uploaded_im_fn = secure_filename(fn)
- uploaded_im_abspath = os.path.join(app_cfg.DIR_UPLOADS, tag, fn)
+ uploaded_im_abspath = os.path.join(app_cfg.DIR_UPLOADS, tag)
+ uploaded_im_fullpath = os.path.join(uploaded_im_abspath, fn)
+
# uploaded_im_fullpath = os.path.join(uploaded_im_abspath, fn)
- if os.path.exists(uploaded_im_abspath):
- print("Removing " + uploaded_im_abspath)
- os.remove(uploaded_im_abspath)
+ if os.path.exists(uploaded_im_fullpath):
+ print("Removing " + uploaded_im_fullpath)
+ os.remove(uploaded_im_fullpath)
session.delete(upload)
session.commit()
diff --git a/animism-align/cli/app/sql/models/media.py b/animism-align/cli/app/sql/models/media.py
index e3a395d..4628f4d 100644
--- a/animism-align/cli/app/sql/models/media.py
+++ b/animism-align/cli/app/sql/models/media.py
@@ -18,6 +18,7 @@ class Media(Base):
title = Column(String(256, convert_unicode=True), nullable=True)
author = Column(String(256, convert_unicode=True), nullable=True)
pre_title = Column(String(256, convert_unicode=True), nullable=True)
+ post_title = Column(String(256, convert_unicode=True), nullable=True)
translated_title = Column(String(256, convert_unicode=True), nullable=True)
date = Column(String(256, convert_unicode=True), nullable=True)
source = Column(String(256, convert_unicode=True), nullable=True)
@@ -34,6 +35,7 @@ class Media(Base):
'url': self.url,
'title': self.title,
'pre_title': self.pre_title,
+ 'post_title': self.post_title,
'translated_title': self.translated_title,
'date': self.date,
'source': self.source,
diff --git a/animism-align/cli/app/sql/versions/202007171640_add_post_title_to_media.py b/animism-align/cli/app/sql/versions/202007171640_add_post_title_to_media.py
new file mode 100644
index 0000000..63dc00a
--- /dev/null
+++ b/animism-align/cli/app/sql/versions/202007171640_add_post_title_to_media.py
@@ -0,0 +1,29 @@
+"""add post_title to media
+
+Revision ID: 1e3c915ef21f
+Revises: 65b17598c815
+Create Date: 2020-07-17 16:40:08.620589
+
+"""
+from alembic import op
+import sqlalchemy as sa
+import sqlalchemy_utc
+
+
+# revision identifiers, used by Alembic.
+revision = '1e3c915ef21f'
+down_revision = '65b17598c815'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.add_column('media', sa.Column('post_title', sa.String(length=256, _expect_unicode=True), nullable=True))
+ # ### end Alembic commands ###
+
+
+def downgrade():
+ # ### commands auto generated by Alembic - please adjust! ###
+ op.drop_column('media', 'post_title')
+ # ### end Alembic commands ###