We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Add stripe test key for testing purposes on the heroku deployment
**Is your feature request related to a problem? Please describe.**
<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->
Stripe test key needs to be added for testing purposes on the heroku deployment.

**Describe the solution you'd like**
<!-- A clear and concise description of what you want to happen. -->
Update the `populate_db.py` file to add it in the settings. 


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `populate_db.py`
Content:
```
1 from app import current_app
2 from app.models import db
3 from app.api.helpers.db import get_or_create  # , save_to_db
4 
5 # Admin message settings
6 from app.api.helpers.system_mails import MAILS
7 from app.models.message_setting import MessageSettings
8 
9 # Event Role-Service Permissions
10 from app.models.role import Role
11 from app.models.service import Service
12 from app.models.permission import Permission
13 
14 from app.models.track import Track
15 from app.models.session import Session
16 from app.models.speaker import Speaker
17 from app.models.sponsor import Sponsor
18 from app.models.microlocation import Microlocation
19 
20 from app.models.user import ORGANIZER, COORGANIZER, TRACK_ORGANIZER, MODERATOR, ATTENDEE, REGISTRAR
21 
22 # Admin Panel Permissions
23 from app.models.panel_permission import PanelPermission
24 from app.models.custom_system_role import CustomSysRole
25 
26 from app.models.setting import Setting
27 from app.models.image_size import ImageSizes
28 from app.models.module import Module
29 
30 # EventTopic
31 from app.models.event_topic import EventTopic
32 
33 # EventType
34 from app.models.event_type import EventType
35 
36 # EventLocation
37 from app.models.event_location import EventLocation
38 
39 # User Permissions
40 from app.models.user_permission import UserPermission
41 SALES = 'sales'
42 
43 
44 def create_roles():
45     get_or_create(Role, name=ORGANIZER, title_name='Organizer')
46     get_or_create(Role, name=COORGANIZER, title_name='Co-organizer')
47     get_or_create(Role, name=TRACK_ORGANIZER, title_name='Track Organizer')
48     get_or_create(Role, name=MODERATOR, title_name='Moderator')
49     get_or_create(Role, name=ATTENDEE, title_name='Attendee')
50     get_or_create(Role, name=REGISTRAR, title_name='Registrar')
51 
52 
53 def create_services():
54     track = Track.get_service_name()
55     session = Session.get_service_name()
56     speaker = Speaker.get_service_name()
57     sponsor = Sponsor.get_service_name()
58     microlocation = Microlocation.get_service_name()
59 
60     get_or_create(Service, name=track)
61     get_or_create(Service, name=session)
62     get_or_create(Service, name=speaker)
63     get_or_create(Service, name=sponsor)
64     get_or_create(Service, name=microlocation)
65 
66 
67 def create_settings():
68     get_or_create(Setting, app_name='Open Event')
69 
70 
71 def create_event_image_sizes():
72     get_or_create(
73         ImageSizes, type='event-image', full_width=1300,
74         full_height=500, full_aspect=True, full_quality=80,
75         icon_width=75, icon_height=30, icon_aspect=True,
76         icon_quality=80, thumbnail_width=500, thumbnail_height=200,
77         thumbnail_aspect=True, thumbnail_quality=80, logo_width=500,
78         logo_height=200
79     )
80 
81 
82 def create_speaker_image_sizes():
83     get_or_create(
84         ImageSizes, type='speaker-image', icon_size_width_height=35, icon_size_quality=80,
85         small_size_width_height=50, small_size_quality=80,
86         thumbnail_size_width_height=500, thumbnail_quality=80
87     )
88 
89 
90 def create_modules():
91     get_or_create(Module, donation_include=False)
92 
93 
94 def create_event_topics():
95     event_topic = ['Health & Wellness', 'Home & Lifestyle',
96                    'Charity & Causes', 'Other', 'Religion & Spirituality',
97                    'Community & Culture', 'Government & Politics',
98                    'Government & Politics', 'Auto, Boat & Air',
99                    'Travel & Outdoor', 'Hobbies & Special Interest',
100                    'Sports & Fitness', 'Business & Professional',
101                    'Music', 'Seasonal & Holiday',
102                    'Film, Media & Entertainment', 'Family & Education',
103                    'Science & Technology', 'Performing & Visual Arts',
104                    'Food & Drink', 'Family & Education']
105     for topic in event_topic:
106         get_or_create(EventTopic, name=topic)
107 
108 
109 def create_event_types():
110     event_type = ['Camp, Treat & Retreat', 'Dinner or Gala',
111                   'Other', 'Concert or Performance', 'Conference',
112                   'Seminar or Talk', 'Convention',
113                   'Festival or Fair', 'Tour',
114                   'Screening', 'Game or Competition',
115                   'Party or Social Gathering', 'Race or Endurance Event',
116                   'Meeting or Networking Event', 'Attraction',
117                   'Class, Training, or Workshop', 'Appearance or Signing',
118                   'Tournament', 'Rally']
119     for type_ in event_type:
120         get_or_create(EventType, name=type_)
121 
122 
123 def create_event_locations():
124     event_location = ['India', 'Singapore', 'Berlin', 'New York', 'Hong Kong']
125     for loc_ in event_location:
126         get_or_create(EventLocation, name=loc_)
127 
128 
129 def create_permissions():
130     orgr = Role.query.get(1)
131     coorgr = Role.query.get(2)
132     track_orgr = Role.query.get(3)
133     mod = Role.query.get(4)
134     attend = Role.query.get(5)
135     regist = Role.query.get(6)
136 
137     track = Service.query.get(1)
138     session = Service.query.get(2)
139     speaker = Service.query.get(3)
140     sponsor = Service.query.get(4)
141     microlocation = Service.query.get(5)
142 
143     # For ORGANIZER
144     # All four permissions set to True
145     services = [track, session, speaker, sponsor, microlocation]
146     roles = [attend, regist]
147     for service in services:
148         perm, _ = get_or_create(Permission, role=orgr, service=service)
149         db.session.add(perm)
150 
151     # For COORGANIZER
152     for service in services:
153         perm, _ = get_or_create(Permission, role=coorgr, service=service)
154         perm.can_create, perm.can_delete = False, False
155         db.session.add(perm)
156 
157     # For TRACK_ORGANIZER
158     for service in services:
159         perm, _ = get_or_create(Permission, role=track_orgr, service=service)
160         if not service == track:
161             perm.can_create, perm.can_update, perm.can_delete = False, False, False
162         db.session.add(perm)
163 
164     # For MODERATOR
165     for service in services:
166         perm, _ = get_or_create(Permission, role=mod, service=service)
167         perm.can_create, perm.can_update, perm.can_delete = False, False, False
168         db.session.add(perm)
169 
170     # For ATTENDEE and REGISTRAR
171     services = [track, session, speaker, sponsor, microlocation]
172     roles = [attend, regist]
173     for role in roles:
174         for service in services:
175             perm, _ = get_or_create(Permission, role=role, service=service)
176             perm.can_create, perm.can_update, perm.can_delete = False, False, False
177             db.session.add(perm)
178 
179 
180 def create_custom_sys_roles():
181     role, _ = get_or_create(CustomSysRole, name='Sales Admin')
182     db.session.add(role)
183     role, _ = get_or_create(CustomSysRole, name='Marketer')
184     db.session.add(role)
185 
186 
187 def create_panel_permissions():
188     sales_admin = CustomSysRole.query.filter_by(name='Sales Admin').first()
189     perm, _ = get_or_create(PanelPermission, panel_name=SALES, role=sales_admin)
190     db.session.add(perm)
191     marketer = CustomSysRole.query.filter_by(name='Marketer').first()
192     perm, _ = get_or_create(PanelPermission, panel_name=SALES, role=marketer)
193     db.session.add(perm)
194 
195 
196 def create_user_permissions():
197     # Publish Event
198     user_perm, _ = get_or_create(UserPermission, name='publish_event',
199                                  description='Publish event (make event live)')
200     user_perm.verified_user = True
201     db.session.add(user_perm)
202 
203     # Create Event
204     user_perm, _ = get_or_create(UserPermission, name='create_event',
205                                  description='Create event')
206     user_perm.verified_user, user_perm.unverified_user = True, False
207     db.session.add(user_perm)
208 
209 
210 def create_admin_message_settings():
211     default_mails = ["Next Event",
212                      "Session Schedule Change",
213                      "User email",
214                      "Invitation For Papers",
215                      "After Event",
216                      "Ticket(s) Purchased",
217                      "Session Accept or Reject",
218                      "Event Published",
219                      "Event Export Failed",
220                      "Event Exported",
221                      "Event Role Invitation",
222                      "New Session Proposal"]
223     for mail in MAILS:
224         if mail in default_mails:
225             get_or_create(MessageSettings, action=mail, mail_status=True,
226                           notification_status=True, user_control_status=True)
227         else:
228             get_or_create(
229                 MessageSettings, action=mail, mail_status=False,
230                 notification_status=False, user_control_status=False
231             )
232 
233 
234 def populate():
235     """
236     Create defined Roles, Services and Permissions.
237     """
238     print('Creating roles...')
239     create_roles()
240     print('Creating services...')
241     create_services()
242     print('Creating permissions...')
243     create_permissions()
244     print('Creating custom system roles...')
245     create_custom_sys_roles()
246     print('Creating admin panel permissions...')
247     create_panel_permissions()
248     print('Creating user permissions...')
249     create_user_permissions()
250     print('Creating settings...')
251     create_settings()
252     print('Creating modules...')
253     create_modules()
254     print('Creating event image size...')
255     create_event_image_sizes()
256     print('Creating speaker image size...')
257     create_speaker_image_sizes()
258     print('Creating Event Topics...')
259     create_event_topics()
260     print('Creating Event Types...')
261     create_event_types()
262     print('Creating Event Locations...')
263     create_event_locations()
264     print('Creating admin message settings...')
265     create_admin_message_settings()
266 
267 
268 def populate_without_print():
269     """
270     Create defined Roles, Services and Permissions.
271     """
272     create_roles()
273     create_services()
274     create_permissions()
275     create_custom_sys_roles()
276     create_panel_permissions()
277     create_user_permissions()
278     create_settings()
279     create_modules()
280     create_event_image_sizes()
281     create_speaker_image_sizes()
282     create_event_topics()
283     create_event_types()
284     create_event_locations()
285     create_admin_message_settings()
286 
287     db.session.commit()
288 
289 
290 if __name__ == '__main__':
291     with current_app.app_context():
292         populate()
293
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/populate_db.py b/populate_db.py
--- a/populate_db.py
+++ b/populate_db.py
@@ -1,6 +1,7 @@
 from app import current_app
 from app.models import db
 from app.api.helpers.db import get_or_create  # , save_to_db
+from envparse import env
 
 # Admin message settings
 from app.api.helpers.system_mails import MAILS
@@ -67,6 +68,21 @@
 def create_settings():
     get_or_create(Setting, app_name='Open Event')
 
+    if current_app.config['DEVELOPMENT']:
+        # get the stripe keys from the env file and save it in the settings.
+        env.read_envfile()
+        stripe_secret_key = env('STRIPE_SECRET_KEY', default=None)
+        stripe_publishable_key = env('STRIPE_PUBLISHABLE_KEY', default=None)
+        stripe_client_id = env('STRIPE_CLIENT_ID', default=None)
+
+        if stripe_client_id and stripe_secret_key and stripe_publishable_key:
+            setting, _ = get_or_create(Setting, app_name='Open Event')
+            setting.stripe_client_id = stripe_client_id
+            setting.stripe_publishable_key = stripe_publishable_key
+            setting.stripe_secret_key = stripe_secret_key
+            db.session.add(setting)
+            db.session.commit()
+
 
 def create_event_image_sizes():
     get_or_create(

{"golden_diff": "diff --git a/populate_db.py b/populate_db.py\n--- a/populate_db.py\n+++ b/populate_db.py\n@@ -1,6 +1,7 @@\n from app import current_app\n from app.models import db\n from app.api.helpers.db import get_or_create  # , save_to_db\n+from envparse import env\n \n # Admin message settings\n from app.api.helpers.system_mails import MAILS\n@@ -67,6 +68,21 @@\n def create_settings():\n     get_or_create(Setting, app_name='Open Event')\n \n+    if current_app.config['DEVELOPMENT']:\n+        # get the stripe keys from the env file and save it in the settings.\n+        env.read_envfile()\n+        stripe_secret_key = env('STRIPE_SECRET_KEY', default=None)\n+        stripe_publishable_key = env('STRIPE_PUBLISHABLE_KEY', default=None)\n+        stripe_client_id = env('STRIPE_CLIENT_ID', default=None)\n+\n+        if stripe_client_id and stripe_secret_key and stripe_publishable_key:\n+            setting, _ = get_or_create(Setting, app_name='Open Event')\n+            setting.stripe_client_id = stripe_client_id\n+            setting.stripe_publishable_key = stripe_publishable_key\n+            setting.stripe_secret_key = stripe_secret_key\n+            db.session.add(setting)\n+            db.session.commit()\n+\n \n def create_event_image_sizes():\n     get_or_create(\n", "issue": "Add stripe test key for testing purposes on the heroku deployment\n**Is your feature request related to a problem? Please describe.**\r\n<!-- A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] -->\r\nStripe test key needs to be added for testing purposes on the heroku deployment.\r\n\r\n**Describe the solution you'd like**\r\n<!-- A clear and concise description of what you want to happen. -->\r\nUpdate the `populate_db.py` file to add it in the settings. \r\n\n", "before_files": [{"content": "from app import current_app\nfrom app.models import db\nfrom app.api.helpers.db import get_or_create  # , save_to_db\n\n# Admin message settings\nfrom app.api.helpers.system_mails import MAILS\nfrom app.models.message_setting import MessageSettings\n\n# Event Role-Service Permissions\nfrom app.models.role import Role\nfrom app.models.service import Service\nfrom app.models.permission import Permission\n\nfrom app.models.track import Track\nfrom app.models.session import Session\nfrom app.models.speaker import Speaker\nfrom app.models.sponsor import Sponsor\nfrom app.models.microlocation import Microlocation\n\nfrom app.models.user import ORGANIZER, COORGANIZER, TRACK_ORGANIZER, MODERATOR, ATTENDEE, REGISTRAR\n\n# Admin Panel Permissions\nfrom app.models.panel_permission import PanelPermission\nfrom app.models.custom_system_role import CustomSysRole\n\nfrom app.models.setting import Setting\nfrom app.models.image_size import ImageSizes\nfrom app.models.module import Module\n\n# EventTopic\nfrom app.models.event_topic import EventTopic\n\n# EventType\nfrom app.models.event_type import EventType\n\n# EventLocation\nfrom app.models.event_location import EventLocation\n\n# User Permissions\nfrom app.models.user_permission import UserPermission\nSALES = 'sales'\n\n\ndef create_roles():\n    get_or_create(Role, name=ORGANIZER, title_name='Organizer')\n    get_or_create(Role, name=COORGANIZER, title_name='Co-organizer')\n    get_or_create(Role, name=TRACK_ORGANIZER, title_name='Track Organizer')\n    get_or_create(Role, name=MODERATOR, title_name='Moderator')\n    get_or_create(Role, name=ATTENDEE, title_name='Attendee')\n    get_or_create(Role, name=REGISTRAR, title_name='Registrar')\n\n\ndef create_services():\n    track = Track.get_service_name()\n    session = Session.get_service_name()\n    speaker = Speaker.get_service_name()\n    sponsor = Sponsor.get_service_name()\n    microlocation = Microlocation.get_service_name()\n\n    get_or_create(Service, name=track)\n    get_or_create(Service, name=session)\n    get_or_create(Service, name=speaker)\n    get_or_create(Service, name=sponsor)\n    get_or_create(Service, name=microlocation)\n\n\ndef create_settings():\n    get_or_create(Setting, app_name='Open Event')\n\n\ndef create_event_image_sizes():\n    get_or_create(\n        ImageSizes, type='event-image', full_width=1300,\n        full_height=500, full_aspect=True, full_quality=80,\n        icon_width=75, icon_height=30, icon_aspect=True,\n        icon_quality=80, thumbnail_width=500, thumbnail_height=200,\n        thumbnail_aspect=True, thumbnail_quality=80, logo_width=500,\n        logo_height=200\n    )\n\n\ndef create_speaker_image_sizes():\n    get_or_create(\n        ImageSizes, type='speaker-image', icon_size_width_height=35, icon_size_quality=80,\n        small_size_width_height=50, small_size_quality=80,\n        thumbnail_size_width_height=500, thumbnail_quality=80\n    )\n\n\ndef create_modules():\n    get_or_create(Module, donation_include=False)\n\n\ndef create_event_topics():\n    event_topic = ['Health & Wellness', 'Home & Lifestyle',\n                   'Charity & Causes', 'Other', 'Religion & Spirituality',\n                   'Community & Culture', 'Government & Politics',\n                   'Government & Politics', 'Auto, Boat & Air',\n                   'Travel & Outdoor', 'Hobbies & Special Interest',\n                   'Sports & Fitness', 'Business & Professional',\n                   'Music', 'Seasonal & Holiday',\n                   'Film, Media & Entertainment', 'Family & Education',\n                   'Science & Technology', 'Performing & Visual Arts',\n                   'Food & Drink', 'Family & Education']\n    for topic in event_topic:\n        get_or_create(EventTopic, name=topic)\n\n\ndef create_event_types():\n    event_type = ['Camp, Treat & Retreat', 'Dinner or Gala',\n                  'Other', 'Concert or Performance', 'Conference',\n                  'Seminar or Talk', 'Convention',\n                  'Festival or Fair', 'Tour',\n                  'Screening', 'Game or Competition',\n                  'Party or Social Gathering', 'Race or Endurance Event',\n                  'Meeting or Networking Event', 'Attraction',\n                  'Class, Training, or Workshop', 'Appearance or Signing',\n                  'Tournament', 'Rally']\n    for type_ in event_type:\n        get_or_create(EventType, name=type_)\n\n\ndef create_event_locations():\n    event_location = ['India', 'Singapore', 'Berlin', 'New York', 'Hong Kong']\n    for loc_ in event_location:\n        get_or_create(EventLocation, name=loc_)\n\n\ndef create_permissions():\n    orgr = Role.query.get(1)\n    coorgr = Role.query.get(2)\n    track_orgr = Role.query.get(3)\n    mod = Role.query.get(4)\n    attend = Role.query.get(5)\n    regist = Role.query.get(6)\n\n    track = Service.query.get(1)\n    session = Service.query.get(2)\n    speaker = Service.query.get(3)\n    sponsor = Service.query.get(4)\n    microlocation = Service.query.get(5)\n\n    # For ORGANIZER\n    # All four permissions set to True\n    services = [track, session, speaker, sponsor, microlocation]\n    roles = [attend, regist]\n    for service in services:\n        perm, _ = get_or_create(Permission, role=orgr, service=service)\n        db.session.add(perm)\n\n    # For COORGANIZER\n    for service in services:\n        perm, _ = get_or_create(Permission, role=coorgr, service=service)\n        perm.can_create, perm.can_delete = False, False\n        db.session.add(perm)\n\n    # For TRACK_ORGANIZER\n    for service in services:\n        perm, _ = get_or_create(Permission, role=track_orgr, service=service)\n        if not service == track:\n            perm.can_create, perm.can_update, perm.can_delete = False, False, False\n        db.session.add(perm)\n\n    # For MODERATOR\n    for service in services:\n        perm, _ = get_or_create(Permission, role=mod, service=service)\n        perm.can_create, perm.can_update, perm.can_delete = False, False, False\n        db.session.add(perm)\n\n    # For ATTENDEE and REGISTRAR\n    services = [track, session, speaker, sponsor, microlocation]\n    roles = [attend, regist]\n    for role in roles:\n        for service in services:\n            perm, _ = get_or_create(Permission, role=role, service=service)\n            perm.can_create, perm.can_update, perm.can_delete = False, False, False\n            db.session.add(perm)\n\n\ndef create_custom_sys_roles():\n    role, _ = get_or_create(CustomSysRole, name='Sales Admin')\n    db.session.add(role)\n    role, _ = get_or_create(CustomSysRole, name='Marketer')\n    db.session.add(role)\n\n\ndef create_panel_permissions():\n    sales_admin = CustomSysRole.query.filter_by(name='Sales Admin').first()\n    perm, _ = get_or_create(PanelPermission, panel_name=SALES, role=sales_admin)\n    db.session.add(perm)\n    marketer = CustomSysRole.query.filter_by(name='Marketer').first()\n    perm, _ = get_or_create(PanelPermission, panel_name=SALES, role=marketer)\n    db.session.add(perm)\n\n\ndef create_user_permissions():\n    # Publish Event\n    user_perm, _ = get_or_create(UserPermission, name='publish_event',\n                                 description='Publish event (make event live)')\n    user_perm.verified_user = True\n    db.session.add(user_perm)\n\n    # Create Event\n    user_perm, _ = get_or_create(UserPermission, name='create_event',\n                                 description='Create event')\n    user_perm.verified_user, user_perm.unverified_user = True, False\n    db.session.add(user_perm)\n\n\ndef create_admin_message_settings():\n    default_mails = [\"Next Event\",\n                     \"Session Schedule Change\",\n                     \"User email\",\n                     \"Invitation For Papers\",\n                     \"After Event\",\n                     \"Ticket(s) Purchased\",\n                     \"Session Accept or Reject\",\n                     \"Event Published\",\n                     \"Event Export Failed\",\n                     \"Event Exported\",\n                     \"Event Role Invitation\",\n                     \"New Session Proposal\"]\n    for mail in MAILS:\n        if mail in default_mails:\n            get_or_create(MessageSettings, action=mail, mail_status=True,\n                          notification_status=True, user_control_status=True)\n        else:\n            get_or_create(\n                MessageSettings, action=mail, mail_status=False,\n                notification_status=False, user_control_status=False\n            )\n\n\ndef populate():\n    \"\"\"\n    Create defined Roles, Services and Permissions.\n    \"\"\"\n    print('Creating roles...')\n    create_roles()\n    print('Creating services...')\n    create_services()\n    print('Creating permissions...')\n    create_permissions()\n    print('Creating custom system roles...')\n    create_custom_sys_roles()\n    print('Creating admin panel permissions...')\n    create_panel_permissions()\n    print('Creating user permissions...')\n    create_user_permissions()\n    print('Creating settings...')\n    create_settings()\n    print('Creating modules...')\n    create_modules()\n    print('Creating event image size...')\n    create_event_image_sizes()\n    print('Creating speaker image size...')\n    create_speaker_image_sizes()\n    print('Creating Event Topics...')\n    create_event_topics()\n    print('Creating Event Types...')\n    create_event_types()\n    print('Creating Event Locations...')\n    create_event_locations()\n    print('Creating admin message settings...')\n    create_admin_message_settings()\n\n\ndef populate_without_print():\n    \"\"\"\n    Create defined Roles, Services and Permissions.\n    \"\"\"\n    create_roles()\n    create_services()\n    create_permissions()\n    create_custom_sys_roles()\n    create_panel_permissions()\n    create_user_permissions()\n    create_settings()\n    create_modules()\n    create_event_image_sizes()\n    create_speaker_image_sizes()\n    create_event_topics()\n    create_event_types()\n    create_event_locations()\n    create_admin_message_settings()\n\n    db.session.commit()\n\n\nif __name__ == '__main__':\n    with current_app.app_context():\n        populate()\n", "path": "populate_db.py"}], "after_files": [{"content": "from app import current_app\nfrom app.models import db\nfrom app.api.helpers.db import get_or_create  # , save_to_db\nfrom envparse import env\n\n# Admin message settings\nfrom app.api.helpers.system_mails import MAILS\nfrom app.models.message_setting import MessageSettings\n\n# Event Role-Service Permissions\nfrom app.models.role import Role\nfrom app.models.service import Service\nfrom app.models.permission import Permission\n\nfrom app.models.track import Track\nfrom app.models.session import Session\nfrom app.models.speaker import Speaker\nfrom app.models.sponsor import Sponsor\nfrom app.models.microlocation import Microlocation\n\nfrom app.models.user import ORGANIZER, COORGANIZER, TRACK_ORGANIZER, MODERATOR, ATTENDEE, REGISTRAR\n\n# Admin Panel Permissions\nfrom app.models.panel_permission import PanelPermission\nfrom app.models.custom_system_role import CustomSysRole\n\nfrom app.models.setting import Setting\nfrom app.models.image_size import ImageSizes\nfrom app.models.module import Module\n\n# EventTopic\nfrom app.models.event_topic import EventTopic\n\n# EventType\nfrom app.models.event_type import EventType\n\n# EventLocation\nfrom app.models.event_location import EventLocation\n\n# User Permissions\nfrom app.models.user_permission import UserPermission\nSALES = 'sales'\n\n\ndef create_roles():\n    get_or_create(Role, name=ORGANIZER, title_name='Organizer')\n    get_or_create(Role, name=COORGANIZER, title_name='Co-organizer')\n    get_or_create(Role, name=TRACK_ORGANIZER, title_name='Track Organizer')\n    get_or_create(Role, name=MODERATOR, title_name='Moderator')\n    get_or_create(Role, name=ATTENDEE, title_name='Attendee')\n    get_or_create(Role, name=REGISTRAR, title_name='Registrar')\n\n\ndef create_services():\n    track = Track.get_service_name()\n    session = Session.get_service_name()\n    speaker = Speaker.get_service_name()\n    sponsor = Sponsor.get_service_name()\n    microlocation = Microlocation.get_service_name()\n\n    get_or_create(Service, name=track)\n    get_or_create(Service, name=session)\n    get_or_create(Service, name=speaker)\n    get_or_create(Service, name=sponsor)\n    get_or_create(Service, name=microlocation)\n\n\ndef create_settings():\n    get_or_create(Setting, app_name='Open Event')\n\n    if current_app.config['DEVELOPMENT']:\n        # get the stripe keys from the env file and save it in the settings.\n        env.read_envfile()\n        stripe_secret_key = env('STRIPE_SECRET_KEY', default=None)\n        stripe_publishable_key = env('STRIPE_PUBLISHABLE_KEY', default=None)\n        stripe_client_id = env('STRIPE_CLIENT_ID', default=None)\n\n        if stripe_client_id and stripe_secret_key and stripe_publishable_key:\n            setting, _ = get_or_create(Setting, app_name='Open Event')\n            setting.stripe_client_id = stripe_client_id\n            setting.stripe_publishable_key = stripe_publishable_key\n            setting.stripe_secret_key = stripe_secret_key\n            db.session.add(setting)\n            db.session.commit()\n\n\ndef create_event_image_sizes():\n    get_or_create(\n        ImageSizes, type='event-image', full_width=1300,\n        full_height=500, full_aspect=True, full_quality=80,\n        icon_width=75, icon_height=30, icon_aspect=True,\n        icon_quality=80, thumbnail_width=500, thumbnail_height=200,\n        thumbnail_aspect=True, thumbnail_quality=80, logo_width=500,\n        logo_height=200\n    )\n\n\ndef create_speaker_image_sizes():\n    get_or_create(\n        ImageSizes, type='speaker-image', icon_size_width_height=35, icon_size_quality=80,\n        small_size_width_height=50, small_size_quality=80,\n        thumbnail_size_width_height=500, thumbnail_quality=80\n    )\n\n\ndef create_modules():\n    get_or_create(Module, donation_include=False)\n\n\ndef create_event_topics():\n    event_topic = ['Health & Wellness', 'Home & Lifestyle',\n                   'Charity & Causes', 'Other', 'Religion & Spirituality',\n                   'Community & Culture', 'Government & Politics',\n                   'Government & Politics', 'Auto, Boat & Air',\n                   'Travel & Outdoor', 'Hobbies & Special Interest',\n                   'Sports & Fitness', 'Business & Professional',\n                   'Music', 'Seasonal & Holiday',\n                   'Film, Media & Entertainment', 'Family & Education',\n                   'Science & Technology', 'Performing & Visual Arts',\n                   'Food & Drink', 'Family & Education']\n    for topic in event_topic:\n        get_or_create(EventTopic, name=topic)\n\n\ndef create_event_types():\n    event_type = ['Camp, Treat & Retreat', 'Dinner or Gala',\n                  'Other', 'Concert or Performance', 'Conference',\n                  'Seminar or Talk', 'Convention',\n                  'Festival or Fair', 'Tour',\n                  'Screening', 'Game or Competition',\n                  'Party or Social Gathering', 'Race or Endurance Event',\n                  'Meeting or Networking Event', 'Attraction',\n                  'Class, Training, or Workshop', 'Appearance or Signing',\n                  'Tournament', 'Rally']\n    for type_ in event_type:\n        get_or_create(EventType, name=type_)\n\n\ndef create_event_locations():\n    event_location = ['India', 'Singapore', 'Berlin', 'New York', 'Hong Kong']\n    for loc_ in event_location:\n        get_or_create(EventLocation, name=loc_)\n\n\ndef create_permissions():\n    orgr = Role.query.get(1)\n    coorgr = Role.query.get(2)\n    track_orgr = Role.query.get(3)\n    mod = Role.query.get(4)\n    attend = Role.query.get(5)\n    regist = Role.query.get(6)\n\n    track = Service.query.get(1)\n    session = Service.query.get(2)\n    speaker = Service.query.get(3)\n    sponsor = Service.query.get(4)\n    microlocation = Service.query.get(5)\n\n    # For ORGANIZER\n    # All four permissions set to True\n    services = [track, session, speaker, sponsor, microlocation]\n    roles = [attend, regist]\n    for service in services:\n        perm, _ = get_or_create(Permission, role=orgr, service=service)\n        db.session.add(perm)\n\n    # For COORGANIZER\n    for service in services:\n        perm, _ = get_or_create(Permission, role=coorgr, service=service)\n        perm.can_create, perm.can_delete = False, False\n        db.session.add(perm)\n\n    # For TRACK_ORGANIZER\n    for service in services:\n        perm, _ = get_or_create(Permission, role=track_orgr, service=service)\n        if not service == track:\n            perm.can_create, perm.can_update, perm.can_delete = False, False, False\n        db.session.add(perm)\n\n    # For MODERATOR\n    for service in services:\n        perm, _ = get_or_create(Permission, role=mod, service=service)\n        perm.can_create, perm.can_update, perm.can_delete = False, False, False\n        db.session.add(perm)\n\n    # For ATTENDEE and REGISTRAR\n    services = [track, session, speaker, sponsor, microlocation]\n    roles = [attend, regist]\n    for role in roles:\n        for service in services:\n            perm, _ = get_or_create(Permission, role=role, service=service)\n            perm.can_create, perm.can_update, perm.can_delete = False, False, False\n            db.session.add(perm)\n\n\ndef create_custom_sys_roles():\n    role, _ = get_or_create(CustomSysRole, name='Sales Admin')\n    db.session.add(role)\n    role, _ = get_or_create(CustomSysRole, name='Marketer')\n    db.session.add(role)\n\n\ndef create_panel_permissions():\n    sales_admin = CustomSysRole.query.filter_by(name='Sales Admin').first()\n    perm, _ = get_or_create(PanelPermission, panel_name=SALES, role=sales_admin)\n    db.session.add(perm)\n    marketer = CustomSysRole.query.filter_by(name='Marketer').first()\n    perm, _ = get_or_create(PanelPermission, panel_name=SALES, role=marketer)\n    db.session.add(perm)\n\n\ndef create_user_permissions():\n    # Publish Event\n    user_perm, _ = get_or_create(UserPermission, name='publish_event',\n                                 description='Publish event (make event live)')\n    user_perm.verified_user = True\n    db.session.add(user_perm)\n\n    # Create Event\n    user_perm, _ = get_or_create(UserPermission, name='create_event',\n                                 description='Create event')\n    user_perm.verified_user, user_perm.unverified_user = True, False\n    db.session.add(user_perm)\n\n\ndef create_admin_message_settings():\n    default_mails = [\"Next Event\",\n                     \"Session Schedule Change\",\n                     \"User email\",\n                     \"Invitation For Papers\",\n                     \"After Event\",\n                     \"Ticket(s) Purchased\",\n                     \"Session Accept or Reject\",\n                     \"Event Published\",\n                     \"Event Export Failed\",\n                     \"Event Exported\",\n                     \"Event Role Invitation\",\n                     \"New Session Proposal\"]\n    for mail in MAILS:\n        if mail in default_mails:\n            get_or_create(MessageSettings, action=mail, mail_status=True,\n                          notification_status=True, user_control_status=True)\n        else:\n            get_or_create(\n                MessageSettings, action=mail, mail_status=False,\n                notification_status=False, user_control_status=False\n            )\n\n\ndef populate():\n    \"\"\"\n    Create defined Roles, Services and Permissions.\n    \"\"\"\n    print('Creating roles...')\n    create_roles()\n    print('Creating services...')\n    create_services()\n    print('Creating permissions...')\n    create_permissions()\n    print('Creating custom system roles...')\n    create_custom_sys_roles()\n    print('Creating admin panel permissions...')\n    create_panel_permissions()\n    print('Creating user permissions...')\n    create_user_permissions()\n    print('Creating settings...')\n    create_settings()\n    print('Creating modules...')\n    create_modules()\n    print('Creating event image size...')\n    create_event_image_sizes()\n    print('Creating speaker image size...')\n    create_speaker_image_sizes()\n    print('Creating Event Topics...')\n    create_event_topics()\n    print('Creating Event Types...')\n    create_event_types()\n    print('Creating Event Locations...')\n    create_event_locations()\n    print('Creating admin message settings...')\n    create_admin_message_settings()\n\n\ndef populate_without_print():\n    \"\"\"\n    Create defined Roles, Services and Permissions.\n    \"\"\"\n    create_roles()\n    create_services()\n    create_permissions()\n    create_custom_sys_roles()\n    create_panel_permissions()\n    create_user_permissions()\n    create_settings()\n    create_modules()\n    create_event_image_sizes()\n    create_speaker_image_sizes()\n    create_event_topics()\n    create_event_types()\n    create_event_locations()\n    create_admin_message_settings()\n\n    db.session.commit()\n\n\nif __name__ == '__main__':\n    with current_app.app_context():\n        populate()\n", "path": "populate_db.py"}]}