forked from fossasia/open-event-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
populate_db.py
445 lines (388 loc) · 13.4 KB
/
populate_db.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
from app.api.helpers.db import get_or_create
# Admin message settings
from app.api.helpers.system_mails import MailType
from app.instance import current_app
from app.models import db
# Custom Placeholder
from app.models.custom_placeholder import CustomPlaceholder
from app.models.custom_system_role import CustomSysRole
# EventLocation
from app.models.event_location import EventLocation
# EventSubTopic
from app.models.event_sub_topic import EventSubTopic
# EventTopic
from app.models.event_topic import EventTopic
# EventType
from app.models.event_type import EventType
from app.models.image_size import ImageSizes
from app.models.message_setting import MessageSettings
from app.models.microlocation import Microlocation
from app.models.notification import NotificationType
from app.models.notification_setting import NotificationSettings
# Admin Panel Permissions
from app.models.panel_permission import PanelPermission
from app.models.permission import Permission
# Event Role-Service Permissions
from app.models.role import Role
from app.models.service import Service
from app.models.session import Session
from app.models.setting import Setting
from app.models.speaker import Speaker
from app.models.sponsor import Sponsor
from app.models.track import Track
from app.models.user import MODERATOR, REGISTRAR, TRACK_ORGANIZER
# User Permissions
from app.models.user_permission import UserPermission
from app.models.video_channel import VideoChannel
SALES = 'sales'
ADMIN = 'admin'
EVENTS = 'events'
SESSIONS = 'sessions'
USERS = 'users'
PERMISSIONS = 'permissions'
MESSAGES = 'messages'
REPORTS = 'reports'
SETTINGS = 'settings'
CONTENT = 'content'
def create_roles():
get_or_create(Role, name=Role.ORGANIZER, defaults=dict(title_name='Organizer'))
get_or_create(Role, name=Role.COORGANIZER, defaults=dict(title_name='Co-Organizer'))
get_or_create(Role, name=Role.OWNER, defaults=dict(title_name='Owner'))
# Deprecated
get_or_create(Role, name=TRACK_ORGANIZER, defaults=dict(title_name='Track Organizer'))
get_or_create(Role, name=MODERATOR, defaults=dict(title_name='Moderator'))
get_or_create(Role, name=REGISTRAR, defaults=dict(title_name='Registrar'))
def create_services():
track = Track.get_service_name()
session = Session.get_service_name()
speaker = Speaker.get_service_name()
sponsor = Sponsor.get_service_name()
microlocation = Microlocation.get_service_name()
get_or_create(Service, name=track)
get_or_create(Service, name=session)
get_or_create(Service, name=speaker)
get_or_create(Service, name=sponsor)
get_or_create(Service, name=microlocation)
def create_settings():
get_or_create(Setting, app_name='Open Event')
def create_event_image_sizes():
get_or_create(
ImageSizes,
type='event-image',
full_width=1300,
full_height=500,
full_aspect=True,
full_quality=80,
icon_width=75,
icon_height=30,
icon_aspect=True,
icon_quality=80,
thumbnail_width=500,
thumbnail_height=200,
thumbnail_aspect=True,
thumbnail_quality=80,
logo_width=500,
logo_height=200,
)
def create_speaker_image_sizes():
get_or_create(
ImageSizes,
type='speaker-image',
icon_size_width_height=35,
icon_size_quality=80,
small_size_width_height=50,
small_size_quality=80,
thumbnail_size_width_height=500,
thumbnail_quality=80,
)
def create_event_topics():
event_topic = [
'Health & Wellness',
'Home & Lifestyle',
'Charity & Causes',
'Other',
'Religion & Spirituality',
'Community & Culture',
'Government & Politics',
'Government & Politics',
'Auto, Boat & Air',
'Travel & Outdoor',
'Hobbies & Special Interest',
'Sports & Fitness',
'Business & Professional',
'Music',
'Seasonal & Holiday',
'Film, Media & Entertainment',
'Family & Education',
'Science & Technology',
'Performing & Visual Arts',
'Food & Drink',
'Family & Education',
]
for topic in event_topic:
get_or_create(EventTopic, name=topic)
def create_event_sub_topics():
event_sub_topic = {
"Film, Media & Entertainment": ["Comedy", "Gaming", "Anime"],
"Community & Culture": ["City/Town", "Other", "LGBT"],
"Home & Lifestyle": ["Dating", "Home & Garden"],
"Sports & Fitness": ["Volleyball", "Other"],
"Health & Wellness": ["Yoga", "Medical"],
"Food & Drink": ["Other", "Food", "Beer"],
"Other": ["Avatar", "Logo"],
"Science & Technology": [
"Robotics",
"Other",
"High Tech",
"Science",
"Social Media",
"Medicine",
"Mobile",
"Biotech",
],
"Music": [
"Cultural",
"Pop",
"Top 40",
"EDM / Electronic",
"R&B",
"Other",
"Classical",
],
"Performing & Visual Arts": ["Craft", "Comedy", "Fine Art", "Orchestra"],
"Family & Education": ["Education", "Baby", "Reunion"],
"Business & Professional": [
"Career",
"Startups & Small Business",
"Educators",
"Design",
"Finance",
],
"Charity & Causes": ["Education", "Other", "Environment"],
"Hobbies & Special Interest": ["Other", "Anime/Comics"],
"Seasonal & Holiday": ["Easter", "Other"],
"Auto, Boat & Air": ["Auto", "Air"],
"Religion & Spirituality": ["Mysticism and Occult"],
"Government & Politics": ["Non-partisan"],
}
eventopics = db.session.query(EventTopic).all()
for keysub_topic in event_sub_topic:
for subtopic in event_sub_topic[keysub_topic]:
get_or_create(
EventSubTopic,
name=subtopic,
event_topic_id=next(x for x in eventopics if x.name == keysub_topic).id,
)
def create_event_types():
event_type = [
'Camp, Treat & Retreat',
'Dinner or Gala',
'Other',
'Concert or Performance',
'Conference',
'Seminar or Talk',
'Convention',
'Festival or Fair',
'Tour',
'Screening',
'Game or Competition',
'Party or Social Gathering',
'Race or Endurance Event',
'Meeting or Networking Event',
'Attraction',
'Class, Training, or Workshop',
'Appearance or Signing',
'Tournament',
'Rally',
]
for type_ in event_type:
get_or_create(EventType, name=type_)
def create_event_locations():
event_location = ['India', 'Singapore', 'Berlin', 'New York', 'Hong Kong']
for loc_ in event_location:
get_or_create(EventLocation, name=loc_)
def create_permissions():
ownr = Role.query.filter_by(name=Role.OWNER).first()
orgr = Role.query.filter_by(name=Role.ORGANIZER).first()
coorgr = Role.query.filter_by(name=Role.COORGANIZER).first()
track_orgr = Role.query.filter_by(name=TRACK_ORGANIZER).first()
mod = Role.query.filter_by(name=MODERATOR).first()
regist = Role.query.filter_by(name=REGISTRAR).first()
track = Service.query.filter_by(name=Track.get_service_name()).first()
session = Service.query.filter_by(name=Session.get_service_name()).first()
speaker = Service.query.filter_by(name=Speaker.get_service_name()).first()
sponsor = Service.query.filter_by(name=Sponsor.get_service_name()).first()
microlocation = Service.query.filter_by(name=Microlocation.get_service_name()).first()
# For ORGANIZER and OWNER
# All four permissions set to True
services = [track, session, speaker, sponsor, microlocation]
for service in services:
perm, _ = get_or_create(Permission, role=ownr, service=service)
db.session.add(perm)
for service in services:
perm, _ = get_or_create(Permission, role=orgr, service=service)
db.session.add(perm)
# For COORGANIZER
for service in services:
perm, _ = get_or_create(Permission, role=coorgr, service=service)
perm.can_create, perm.can_delete = False, False
db.session.add(perm)
# For TRACK_ORGANIZER
for service in services:
perm, _ = get_or_create(Permission, role=track_orgr, service=service)
if not service == track:
perm.can_create, perm.can_update, perm.can_delete = False, False, False
db.session.add(perm)
# For MODERATOR
for service in services:
perm, _ = get_or_create(Permission, role=mod, service=service)
perm.can_create, perm.can_update, perm.can_delete = False, False, False
db.session.add(perm)
# For REGISTRAR
services = [track, session, speaker, sponsor, microlocation]
for service in services:
perm, _ = get_or_create(Permission, role=regist, service=service)
perm.can_create, perm.can_update, perm.can_delete = False, False, False
db.session.add(perm)
def create_custom_sys_roles():
role, _ = get_or_create(CustomSysRole, name='Sales Admin')
db.session.add(role)
role, _ = get_or_create(CustomSysRole, name='Marketer')
db.session.add(role)
def create_panels():
panels = [
SALES,
ADMIN,
EVENTS,
SESSIONS,
USERS,
PERMISSIONS,
MESSAGES,
REPORTS,
SETTINGS,
CONTENT,
]
for panel in panels:
perm, _ = get_or_create(PanelPermission, panel_name=panel)
db.session.add(perm)
def create_panel_permissions():
sales_panel, _ = get_or_create(PanelPermission, panel_name=SALES)
sales_admin, _ = get_or_create(CustomSysRole, name='Sales Admin')
marketer, _ = get_or_create(CustomSysRole, name='Marketer')
sales_panel.custom_system_roles.append(sales_admin)
sales_panel.custom_system_roles.append(marketer)
def create_user_permissions():
# Publish Event
user_perm, _ = get_or_create(
UserPermission,
name='publish_event',
description='Publish event (make event live)',
)
user_perm.verified_user = True
db.session.add(user_perm)
# Create Event
user_perm, _ = get_or_create(
UserPermission, name='create_event', description='Create event'
)
user_perm.verified_user, user_perm.unverified_user = True, False
db.session.add(user_perm)
def create_admin_message_settings():
for mail in MailType.entries():
get_or_create(MessageSettings, action=mail, defaults=dict(enabled=True))
for notification in NotificationType.entries():
get_or_create(
NotificationSettings, type=notification, defaults=dict(enabled=True)
)
def create_custom_placeholders():
custom_placeholder, _ = get_or_create(
CustomPlaceholder,
name='Hills',
original_image_url='https://www.w3schools.com/html/pic_mountain.jpg',
event_sub_topic_id=1,
)
db.session.add(custom_placeholder)
def populate():
"""
Create defined Roles, Services and Permissions.
"""
print('Creating roles...')
create_roles()
print('Creating services...')
create_services()
print('Creating permissions...')
create_permissions()
print('Creating custom system roles...')
create_custom_sys_roles()
print('Creating panels...')
create_panels()
print('Creating admin panel permissions...')
create_panel_permissions()
print('Creating user permissions...')
create_user_permissions()
print('Creating settings...')
create_settings()
print('Creating event image size...')
create_event_image_sizes()
print('Creating speaker image size...')
create_speaker_image_sizes()
print('Creating Event Topics...')
create_event_topics()
print('Creating Event SubTopics...')
create_event_sub_topics()
print('Creating Event Types...')
create_event_types()
print('Creating Event Locations...')
create_event_locations()
print('Creating admin message settings...')
create_admin_message_settings()
print('Creating custom placeholders...')
create_custom_placeholders()
get_or_create(
VideoChannel,
provider='jitsi',
name='Jitsi Meet',
defaults={'url': 'https://meet.jit.si', 'api_url': 'https://api.jitsi.net'},
)
get_or_create(
VideoChannel,
provider='youtube',
name='YouTube',
defaults={
'url': 'https://youtube.com',
'api_url': 'https://www.googleapis.com/youtube/v3',
},
)
get_or_create(
VideoChannel,
provider='vimeo',
name='Vimeo',
defaults={'url': 'https://vimeo.com', 'api_url': 'https://api.vimeo.com'},
)
get_or_create(
VideoChannel,
provider='3cx',
name='3CX',
defaults={'url': 'https://www.3cx.com/'},
)
get_or_create(
VideoChannel,
provider='chatmosphere',
name='Chatmosphere',
defaults={'url': 'https://app.chatmosphere.cc/'},
)
get_or_create(
VideoChannel,
provider='libre',
name='Libre Work',
defaults={'url': 'https://2d.freiland-potsdam.de/'},
)
get_or_create(
VideoChannel,
provider='youtube_privacy',
name='YouTube Privacy',
defaults={'url': 'https://youtube-nocookie.com'},
)
db.session.commit()
if __name__ == '__main__':
with current_app.app_context():
populate()