We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Modules API gives 404 at localhost
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-server

**Current behavior:**
<!-- Describe how the bug manifests. -->

Currently, neither GET  nor PATCH is working in `/v1/modules`
**Expected behavior:**
<!-- Describe what the behavior would be without the bug. -->

It should work.
**Steps to reproduce:**
<!-- If you are able to illustrate the bug or feature request with an example, please provide steps to reproduce -->

**Related code:**

```
insert any relevant code here else remove this section
```

**Other information:**
<!-- List any other information that is relevant to your issue. Stack traces, related issues, suggestions on how to fix, Stack Overflow links, forum links, etc. -->

**System information:** 

<!-- Add information about the system your facing this bug on. If you think this is irrelevant or if it's a UI bug or a feature request, please remove this section -->

```
Your operating system
```

```
output of `python --version`
```
**Wanna work on this issue**

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `app/api/modules.py`
Content:
```
1 from flask_rest_jsonapi import ResourceDetail
2 
3 from app.api.bootstrap import api
4 from app.api.schema.modules import ModuleSchema
5 from app.models import db
6 from app.models.module import Module
7 
8 
9 class ModuleDetail(ResourceDetail):
10     """
11     module detail by id
12     """
13     def before_get(self, args, kwargs):
14         """
15         before get method to get the resource id for fetching details
16         :param args:
17         :param kwargs:
18         :return:
19         """
20         kwargs['id'] = 1
21 
22     decorators = (api.has_permission('is_admin', methods="PATCH", id="1"),)
23     methods = ['GET', 'PATCH']
24     schema = ModuleSchema
25     data_layer = {'session': db.session,
26                   'model': Module}
27
```

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 
28 # User Permissions
29 from app.models.user_permission import UserPermission
30 SALES = 'sales'
31 
32 
33 def create_roles():
34     get_or_create(Role, name=ORGANIZER, title_name='Organizer')
35     get_or_create(Role, name=COORGANIZER, title_name='Co-organizer')
36     get_or_create(Role, name=TRACK_ORGANIZER, title_name='Track Organizer')
37     get_or_create(Role, name=MODERATOR, title_name='Moderator')
38     get_or_create(Role, name=ATTENDEE, title_name='Attendee')
39     get_or_create(Role, name=REGISTRAR, title_name='Registrar')
40 
41 
42 def create_services():
43     track = Track.get_service_name()
44     session = Session.get_service_name()
45     speaker = Speaker.get_service_name()
46     sponsor = Sponsor.get_service_name()
47     microlocation = Microlocation.get_service_name()
48 
49     get_or_create(Service, name=track)
50     get_or_create(Service, name=session)
51     get_or_create(Service, name=speaker)
52     get_or_create(Service, name=sponsor)
53     get_or_create(Service, name=microlocation)
54 
55 
56 def create_settings():
57     get_or_create(Setting, app_name='Open Event')
58 
59 
60 def create_permissions():
61     orgr = Role.query.get(1)
62     coorgr = Role.query.get(2)
63     track_orgr = Role.query.get(3)
64     mod = Role.query.get(4)
65 
66     track = Service.query.get(1)
67     session = Service.query.get(2)
68     speaker = Service.query.get(3)
69     sponsor = Service.query.get(4)
70     microlocation = Service.query.get(5)
71 
72     # For ORGANIZER
73     # All four permissions set to True
74     get_or_create(Permission, role=orgr, service=track)
75     get_or_create(Permission, role=orgr, service=session)
76     get_or_create(Permission, role=orgr, service=speaker)
77     get_or_create(Permission, role=orgr, service=sponsor)
78     get_or_create(Permission, role=orgr, service=microlocation)
79 
80     # For COORGANIZER
81     perm, _ = get_or_create(Permission, role=coorgr, service=track)
82     perm.can_create, perm.can_delete = False, False
83     db.session.add(perm)
84 
85     perm, _ = get_or_create(Permission, role=coorgr, service=session)
86     perm.can_create, perm.can_delete = False, False
87     db.session.add(perm)
88 
89     perm, _ = get_or_create(Permission, role=coorgr, service=speaker)
90     perm.can_create, perm.can_delete = False, False
91     db.session.add(perm)
92 
93     perm, _ = get_or_create(Permission, role=coorgr, service=sponsor)
94     perm.can_create, perm.can_delete = False, False
95     db.session.add(perm)
96 
97     perm, _ = get_or_create(Permission, role=coorgr, service=microlocation)
98     perm.can_create, perm.can_delete = False, False
99     db.session.add(perm)
100 
101     # For TRACK_ORGANIZER
102     perm, _ = get_or_create(Permission, role=track_orgr, service=track)
103     db.session.add(perm)
104 
105     # For MODERATOR
106     perm, _ = get_or_create(Permission, role=mod, service=track)
107     perm.can_create, perm.can_update, perm.can_delete = False, False, False
108     db.session.add(perm)
109 
110 
111 def create_custom_sys_roles():
112     role, _ = get_or_create(CustomSysRole, name='Sales Admin')
113     db.session.add(role)
114     role, _ = get_or_create(CustomSysRole, name='Marketer')
115     db.session.add(role)
116 
117 
118 def create_panel_permissions():
119     sales_admin = CustomSysRole.query.filter_by(name='Sales Admin').first()
120     perm, _ = get_or_create(PanelPermission, panel_name=SALES, role=sales_admin)
121     db.session.add(perm)
122     marketer = CustomSysRole.query.filter_by(name='Marketer').first()
123     perm, _ = get_or_create(PanelPermission, panel_name=SALES, role=marketer)
124     db.session.add(perm)
125 
126 
127 def create_user_permissions():
128     # Publish Event
129     user_perm, _ = get_or_create(UserPermission, name='publish_event',
130                                  description='Publish event (make event live)')
131     user_perm.verified_user = True
132     db.session.add(user_perm)
133 
134     # Create Event
135     user_perm, _ = get_or_create(UserPermission, name='create_event',
136                                  description='Create event')
137     user_perm.verified_user, user_perm.unverified_user = True, True
138     db.session.add(user_perm)
139 
140 
141 def create_admin_message_settings():
142     default_mails = ["Next Event",
143                      "Session Schedule Change",
144                      "User email",
145                      "Invitation For Papers",
146                      "After Event",
147                      "Ticket(s) Purchased",
148                      "Session Accept or Reject",
149                      "Event Published",
150                      "Event Export Failed",
151                      "Event Exported",
152                      "Event Role Invitation",
153                      "New Session Proposal"]
154     for mail in MAILS:
155         if mail in default_mails:
156             get_or_create(MessageSettings, action=mail, mail_status=1, notification_status=1, user_control_status=1)
157         else:
158             get_or_create(MessageSettings, action=mail, mail_status=0, notification_status=0, user_control_status=0)
159 
160 
161 def populate():
162     """
163     Create defined Roles, Services and Permissions.
164     """
165     print('Creating roles...')
166     create_roles()
167     print('Creating services...')
168     create_services()
169     print('Creating permissions...')
170     create_permissions()
171     print('Creating custom system roles...')
172     create_custom_sys_roles()
173     print('Creating admin panel permissions...')
174     create_panel_permissions()
175     print('Creating user permissions...')
176     create_user_permissions()
177     print('Creating settings...')
178     create_settings()
179     print('Creating admin message settings...')
180     create_admin_message_settings()
181 
182 
183 def populate_without_print():
184     """
185     Create defined Roles, Services and Permissions.
186     """
187     create_roles()
188     create_services()
189     create_permissions()
190     create_custom_sys_roles()
191     create_panel_permissions()
192     create_user_permissions()
193     create_admin_message_settings()
194 
195     db.session.commit()
196 
197 
198 if __name__ == '__main__':
199     with current_app.app_context():
200         populate()
201
```
--- 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/app/api/modules.py b/app/api/modules.py
--- a/app/api/modules.py
+++ b/app/api/modules.py
@@ -10,6 +10,7 @@
     """
     module detail by id
     """
+
     def before_get(self, args, kwargs):
         """
         before get method to get the resource id for fetching details
@@ -19,7 +20,7 @@
         """
         kwargs['id'] = 1
 
-    decorators = (api.has_permission('is_admin', methods="PATCH", id="1"),)
+    decorators = (api.has_permission('is_admin', methods='PATCH', id='1'),)
     methods = ['GET', 'PATCH']
     schema = ModuleSchema
     data_layer = {'session': db.session,
diff --git a/populate_db.py b/populate_db.py
--- a/populate_db.py
+++ b/populate_db.py
@@ -24,6 +24,7 @@
 from app.models.custom_system_role import CustomSysRole
 
 from app.models.setting import Setting
+from app.models.module import Module
 
 # User Permissions
 from app.models.user_permission import UserPermission
@@ -57,6 +58,10 @@
     get_or_create(Setting, app_name='Open Event')
 
 
+def create_modules():
+    get_or_create(Module, donation_include=False)
+
+
 def create_permissions():
     orgr = Role.query.get(1)
     coorgr = Role.query.get(2)
@@ -176,6 +181,8 @@
     create_user_permissions()
     print('Creating settings...')
     create_settings()
+    print('Creating modules...')
+    create_modules()
     print('Creating admin message settings...')
     create_admin_message_settings()

{"golden_diff": "diff --git a/app/api/modules.py b/app/api/modules.py\n--- a/app/api/modules.py\n+++ b/app/api/modules.py\n@@ -10,6 +10,7 @@\n     \"\"\"\n     module detail by id\n     \"\"\"\n+\n     def before_get(self, args, kwargs):\n         \"\"\"\n         before get method to get the resource id for fetching details\n@@ -19,7 +20,7 @@\n         \"\"\"\n         kwargs['id'] = 1\n \n-    decorators = (api.has_permission('is_admin', methods=\"PATCH\", id=\"1\"),)\n+    decorators = (api.has_permission('is_admin', methods='PATCH', id='1'),)\n     methods = ['GET', 'PATCH']\n     schema = ModuleSchema\n     data_layer = {'session': db.session,\ndiff --git a/populate_db.py b/populate_db.py\n--- a/populate_db.py\n+++ b/populate_db.py\n@@ -24,6 +24,7 @@\n from app.models.custom_system_role import CustomSysRole\n \n from app.models.setting import Setting\n+from app.models.module import Module\n \n # User Permissions\n from app.models.user_permission import UserPermission\n@@ -57,6 +58,10 @@\n     get_or_create(Setting, app_name='Open Event')\n \n \n+def create_modules():\n+    get_or_create(Module, donation_include=False)\n+\n+\n def create_permissions():\n     orgr = Role.query.get(1)\n     coorgr = Role.query.get(2)\n@@ -176,6 +181,8 @@\n     create_user_permissions()\n     print('Creating settings...')\n     create_settings()\n+    print('Creating modules...')\n+    create_modules()\n     print('Creating admin message settings...')\n     create_admin_message_settings()\n", "issue": "Modules API gives 404 at localhost\n**I'm submitting a ...**  (check one with \"x\")\r\n- [x] bug report\r\n- [ ] feature request\r\n- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-server\r\n\r\n**Current behavior:**\r\n<!-- Describe how the bug manifests. -->\r\n\r\nCurrently, neither GET  nor PATCH is working in `/v1/modules`\r\n**Expected behavior:**\r\n<!-- Describe what the behavior would be without the bug. -->\r\n\r\nIt should work.\r\n**Steps to reproduce:**\r\n<!-- If you are able to illustrate the bug or feature request with an example, please provide steps to reproduce -->\r\n\r\n**Related code:**\r\n\r\n```\r\ninsert any relevant code here else remove this section\r\n```\r\n\r\n**Other information:**\r\n<!-- List any other information that is relevant to your issue. Stack traces, related issues, suggestions on how to fix, Stack Overflow links, forum links, etc. -->\r\n\r\n**System information:** \r\n\r\n<!-- Add information about the system your facing this bug on. If you think this is irrelevant or if it's a UI bug or a feature request, please remove this section -->\r\n\r\n```\r\nYour operating system\r\n```\r\n\r\n```\r\noutput of `python --version`\r\n```\r\n**Wanna work on this issue**\n", "before_files": [{"content": "from flask_rest_jsonapi import ResourceDetail\n\nfrom app.api.bootstrap import api\nfrom app.api.schema.modules import ModuleSchema\nfrom app.models import db\nfrom app.models.module import Module\n\n\nclass ModuleDetail(ResourceDetail):\n    \"\"\"\n    module detail by id\n    \"\"\"\n    def before_get(self, args, kwargs):\n        \"\"\"\n        before get method to get the resource id for fetching details\n        :param args:\n        :param kwargs:\n        :return:\n        \"\"\"\n        kwargs['id'] = 1\n\n    decorators = (api.has_permission('is_admin', methods=\"PATCH\", id=\"1\"),)\n    methods = ['GET', 'PATCH']\n    schema = ModuleSchema\n    data_layer = {'session': db.session,\n                  'model': Module}\n", "path": "app/api/modules.py"}, {"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\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_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\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    get_or_create(Permission, role=orgr, service=track)\n    get_or_create(Permission, role=orgr, service=session)\n    get_or_create(Permission, role=orgr, service=speaker)\n    get_or_create(Permission, role=orgr, service=sponsor)\n    get_or_create(Permission, role=orgr, service=microlocation)\n\n    # For COORGANIZER\n    perm, _ = get_or_create(Permission, role=coorgr, service=track)\n    perm.can_create, perm.can_delete = False, False\n    db.session.add(perm)\n\n    perm, _ = get_or_create(Permission, role=coorgr, service=session)\n    perm.can_create, perm.can_delete = False, False\n    db.session.add(perm)\n\n    perm, _ = get_or_create(Permission, role=coorgr, service=speaker)\n    perm.can_create, perm.can_delete = False, False\n    db.session.add(perm)\n\n    perm, _ = get_or_create(Permission, role=coorgr, service=sponsor)\n    perm.can_create, perm.can_delete = False, False\n    db.session.add(perm)\n\n    perm, _ = get_or_create(Permission, role=coorgr, service=microlocation)\n    perm.can_create, perm.can_delete = False, False\n    db.session.add(perm)\n\n    # For TRACK_ORGANIZER\n    perm, _ = get_or_create(Permission, role=track_orgr, service=track)\n    db.session.add(perm)\n\n    # For MODERATOR\n    perm, _ = get_or_create(Permission, role=mod, service=track)\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, True\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=1, notification_status=1, user_control_status=1)\n        else:\n            get_or_create(MessageSettings, action=mail, mail_status=0, notification_status=0, user_control_status=0)\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 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_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 flask_rest_jsonapi import ResourceDetail\n\nfrom app.api.bootstrap import api\nfrom app.api.schema.modules import ModuleSchema\nfrom app.models import db\nfrom app.models.module import Module\n\n\nclass ModuleDetail(ResourceDetail):\n    \"\"\"\n    module detail by id\n    \"\"\"\n\n    def before_get(self, args, kwargs):\n        \"\"\"\n        before get method to get the resource id for fetching details\n        :param args:\n        :param kwargs:\n        :return:\n        \"\"\"\n        kwargs['id'] = 1\n\n    decorators = (api.has_permission('is_admin', methods='PATCH', id='1'),)\n    methods = ['GET', 'PATCH']\n    schema = ModuleSchema\n    data_layer = {'session': db.session,\n                  'model': Module}\n", "path": "app/api/modules.py"}, {"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.module import Module\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_modules():\n    get_or_create(Module, donation_include=False)\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\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    get_or_create(Permission, role=orgr, service=track)\n    get_or_create(Permission, role=orgr, service=session)\n    get_or_create(Permission, role=orgr, service=speaker)\n    get_or_create(Permission, role=orgr, service=sponsor)\n    get_or_create(Permission, role=orgr, service=microlocation)\n\n    # For COORGANIZER\n    perm, _ = get_or_create(Permission, role=coorgr, service=track)\n    perm.can_create, perm.can_delete = False, False\n    db.session.add(perm)\n\n    perm, _ = get_or_create(Permission, role=coorgr, service=session)\n    perm.can_create, perm.can_delete = False, False\n    db.session.add(perm)\n\n    perm, _ = get_or_create(Permission, role=coorgr, service=speaker)\n    perm.can_create, perm.can_delete = False, False\n    db.session.add(perm)\n\n    perm, _ = get_or_create(Permission, role=coorgr, service=sponsor)\n    perm.can_create, perm.can_delete = False, False\n    db.session.add(perm)\n\n    perm, _ = get_or_create(Permission, role=coorgr, service=microlocation)\n    perm.can_create, perm.can_delete = False, False\n    db.session.add(perm)\n\n    # For TRACK_ORGANIZER\n    perm, _ = get_or_create(Permission, role=track_orgr, service=track)\n    db.session.add(perm)\n\n    # For MODERATOR\n    perm, _ = get_or_create(Permission, role=mod, service=track)\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, True\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=1, notification_status=1, user_control_status=1)\n        else:\n            get_or_create(MessageSettings, action=mail, mail_status=0, notification_status=0, user_control_status=0)\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 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_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"}]}