Repository: fossasia/open-event-server

Issue:
Enhance event model/api
**Rename fields in model:**

- [x] `logo` => `logo_url`
- [x] `thumbnail` => `thumbnail_image_url`
- [x] `large` => `large_image_url`
- [x] `icon` => `icon_image_url`

**Add/Change fields in api:**
- [x] `thumbnail_image_url` => read_only
- [x] `large_image_url` => read_only
- [x]  `icon_image_url` => read_only
and add
- [x] `original_image_url`

**Handle image resizing and save:**

Whenever original_image_url changes then download it, resize it appropriately, upload it back to the storage and update `large_image_url`, `thumbnail_image_url`, `icon_image_url` fields with the new URLs. 



Discussion:
@poush also add a new field called as `original_image_url` 

Whenever original_image_url changes then download it, resize it appropriately, upload it back to the storage and update `large_image_url`, `thumbnail_image_url`, `icon_image_url` fields with the new URLs. 

Be sure to do the resizing as per the image size setting

`original_image_url` isn't similar to `large_image_url`? or we will enlarge the original image for large_image ? Also `original_image_url` will be added to API as well right?
large, thumbnail and icon image have fixed sizes defined by the admin. If original image is smaller, it is expanded. 
Yes. Original_image_url will be added to api. And in api ensure, large_image_url, thumbnail_image_url, icon_image_url are read-only. Ignore any changes to them.

Resolving patch:
diff --git a/app/api/events.py b/app/api/events.py
--- a/app/api/events.py
+++ b/app/api/events.py
@@ -37,20 +37,20 @@ class Meta:
     identifier = fields.Str(dump_only=True)
     name = fields.Str(required=True)
     email = fields.Str()
-    event_url = fields.Str(dump_only=True)
+    event_url = fields.Url(dump_only=True)
     starts_at = fields.DateTime(required=True, timezone=True)
     ends_at = fields.DateTime(required=True, timezone=True)
     timezone = fields.Str(required=True)
     latitude = fields.Float()
     longitude = fields.Float()
-    logo_url = fields.Str(attribute='logo')
+    logo_url = fields.Url()
     location_name = fields.Str()
     searchable_location_name = fields.Str()
     description = fields.Str()
-    thumbnail_image_url = fields.Str(attribute='thumbnail')
-    large_image_url = fields.Str(attribute='large')
-    original_image_url = fields.Str(attribute='background_url')
-    icon_image_url = fields.Str(attribute='icon')
+    original_image_url = fields.Url()
+    thumbnail_image_url = fields.Url(dump_only=True)
+    large_image_url = fields.Url(dump_only=True)
+    icon_image_url = fields.Url(dump_only=True)
     organizer_name = fields.Str()
     show_map = fields.Int()
     organizer_description = fields.Str()
@@ -60,7 +60,7 @@ class Meta:
     type = fields.Str()
     topic = fields.Str()
     sub_topic = fields.Str()
-    ticket_url = fields.Str()
+    ticket_url = fields.Url()
     code_of_conduct = fields.Str()
     schedule_published_on = fields.DateTime()
     ticket_include = fields.Bool(default=False)
diff --git a/app/models/event.py b/app/models/event.py
--- a/app/models/event.py
+++ b/app/models/event.py
@@ -48,7 +48,7 @@ class Event(db.Model):
     name = db.Column(db.String, nullable=False)
     event_url = db.Column(db.String)
     email = db.Column(db.String)
-    logo = db.Column(db.String)
+    logo_url = db.Column(db.String)
     starts_at = db.Column(db.DateTime(timezone=True), nullable=False)
     ends_at = db.Column(db.DateTime(timezone=True), nullable=False)
     timezone = db.Column(db.String, nullable=False, default="UTC")
@@ -57,10 +57,10 @@ class Event(db.Model):
     location_name = db.Column(db.String)
     searchable_location_name = db.Column(db.String)
     description = db.Column(db.Text)
-    background_url = db.Column(db.String)
-    thumbnail = db.Column(db.String)
-    large = db.Column(db.String)
-    icon = db.Column(db.String)
+    original_image_url = db.Column(db.String)
+    thumbnail_image_url = db.Column(db.String)
+    large_image_url = db.Column(db.String)
+    icon_image_url = db.Column(db.String)
     organizer_name = db.Column(db.String)
     show_map = db.Column(db.Integer)
     organizer_description = db.Column(db.String)
diff --git a/migrations/versions/5dcb69824a56_.py b/migrations/versions/5dcb69824a56_.py
new file mode 100644
--- /dev/null
+++ b/migrations/versions/5dcb69824a56_.py
@@ -0,0 +1,48 @@
+"""empty message
+
+Revision ID: 5dcb69824a56
+Revises: c79e6d36a194
+Create Date: 2017-06-16 14:35:52.300308
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '5dcb69824a56'
+down_revision = 'c79e6d36a194'
+
+from alembic import op
+import sqlalchemy as sa
+import sqlalchemy_utils
+
+
+def upgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.alter_column('events', 'background_url', new_column_name='original_image_url')
+    op.alter_column('events', 'logo', new_column_name='logo_url')
+    op.alter_column('events', 'large', new_column_name='large_image_url')
+    op.alter_column('events', 'thumbnail', new_column_name='thumbnail_image_url')
+    op.alter_column('events', 'icon', new_column_name='icon_image_url')
+
+    op.alter_column('events_version', 'background_url', new_column_name='original_image_url')
+    op.alter_column('events_version', 'logo', new_column_name='logo_url')
+    op.alter_column('events_version', 'large', new_column_name='large_image_url')
+    op.alter_column('events_version', 'thumbnail', new_column_name='thumbnail_image_url')
+    op.alter_column('events_version', 'icon', new_column_name='icon_image_url')
+    # ### end Alembic commands ###
+
+
+def downgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+
+    op.alter_column('events', 'original_image_url', new_column_name='background_url')
+    op.alter_column('events', 'logo_url', new_column_name='logo')
+    op.alter_column('events', 'large_image_url', new_column_name='large')
+    op.alter_column('events', 'thumbnail_image_url', new_column_name='thumbnail')
+    op.alter_column('events', 'icon_image_url', new_column_name='icon')
+
+    op.alter_column('events_version', 'original_image_url', new_column_name='background_url')
+    op.alter_column('events_version', 'logo_url', new_column_name='logo')
+    op.alter_column('events_version', 'large_image_url', new_column_name='large')
+    op.alter_column('events_version', 'thumbnail_image_url', new_column_name='thumbnail')
+    op.alter_column('events_version', 'icon_image_url', new_column_name='icon')
+    # ### end Alembic commands ###


Test patch: