Repository: fossasia/open-event-server

Issue:
Add `show_stats_public` field in public tickets page
This is the server issue for fossasia/open-event-frontend#3090

Adding a Boolean field to allow event owner to show remaining tickets on the public event page


Discussion:

Resolving patch:
diff --git a/app/api/schema/events.py b/app/api/schema/events.py
--- a/app/api/schema/events.py
+++ b/app/api/schema/events.py
@@ -84,6 +84,7 @@ def validate_timezone(self, data, original_data):
     thumbnail_image_url = fields.Url(dump_only=True)
     large_image_url = fields.Url(dump_only=True)
     icon_image_url = fields.Url(dump_only=True)
+    show_remaining_tickets = fields.Bool(allow_none=False, default=False)
     organizer_name = fields.Str(allow_none=True)
     is_map_shown = fields.Bool(default=False)
     has_organizer_info = 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
@@ -58,6 +58,7 @@ class Event(SoftDeletionModel):
     original_image_url = db.Column(db.String)
     thumbnail_image_url = db.Column(db.String)
     large_image_url = db.Column(db.String)
+    show_remaining_tickets = db.Column(db.Boolean, default=False, nullable=False)
     icon_image_url = db.Column(db.String)
     organizer_name = db.Column(db.String)
     is_map_shown = db.Column(db.Boolean)
@@ -198,6 +199,7 @@ def __init__(self,
                  code_of_conduct=None,
                  schedule_published_on=None,
                  is_sessions_speakers_enabled=False,
+                 show_remaining_tickets=False,
                  is_ticket_form_enabled=True,
                  is_donation_enabled=False,
                  is_map_shown=False,
@@ -259,6 +261,7 @@ def __init__(self,
         self.privacy = privacy
         self.event_type_id = event_type_id
         self.event_topic_id = event_topic_id
+        self.show_remaining_tickets = show_remaining_tickets
         self.copyright = copyright
         self.event_sub_topic_id = event_sub_topic_id
         self.events_orga_id = events_orga_id
diff --git a/migrations/versions/09c86e38f5e7_.py b/migrations/versions/09c86e38f5e7_.py
new file mode 100644
--- /dev/null
+++ b/migrations/versions/09c86e38f5e7_.py
@@ -0,0 +1,30 @@
+"""empty message
+
+Revision ID: 09c86e38f5e7
+Revises: a6e5abbcc205
+Create Date: 2019-06-12 12:12:24.692657
+
+"""
+
+from alembic import op
+import sqlalchemy as sa
+import sqlalchemy_utils
+
+
+# revision identifiers, used by Alembic.
+revision = '09c86e38f5e7'
+down_revision = 'a6e5abbcc205'
+
+
+def upgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.add_column('events', sa.Column('show_remaining_tickets', sa.Boolean(), server_default='False', nullable=False))
+    op.add_column('events_version', sa.Column('show_remaining_tickets', sa.Boolean(), server_default='False', nullable=False))
+    # ### end Alembic commands ###
+
+
+def downgrade():
+    # ### commands auto generated by Alembic - please adjust! ###
+    op.drop_column('events_version', 'show_remaining_tickets')
+    op.drop_column('events', 'show_remaining_tickets')
+    # ### end Alembic commands ###


Test patch: