forked from fossasia/open-event-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_types.py
More file actions
137 lines (117 loc) · 3.53 KB
/
session_types.py
File metadata and controls
137 lines (117 loc) · 3.53 KB
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
from flask_rest_jsonapi import ResourceDetail, ResourceList, ResourceRelationship
from app.api.bootstrap import api
from app.api.helpers.db import safe_query_kwargs
from app.api.helpers.errors import ForbiddenError
from app.api.helpers.permission_manager import has_access
from app.api.helpers.query import event_query
from app.api.helpers.utilities import require_relationship
from app.api.schema.session_types import SessionTypeSchema
from app.models import db
from app.models.session import Session
from app.models.session_type import SessionType
class SessionTypeListPost(ResourceList):
"""
List and create sessions
"""
def before_post(self, args, kwargs, data):
"""
before post method to check for required relationship and proper permission
:param args:
:param kwargs:
:param data:
:return:
"""
require_relationship(['event'], data)
if not has_access('is_coorganizer', event_id=data['event']):
raise ForbiddenError({'source': ''}, 'Co-organizer access is required.')
methods = [
'POST',
]
schema = SessionTypeSchema
data_layer = {'session': db.session, 'model': SessionType}
class SessionTypeList(ResourceList):
"""
List sessions
"""
def query(self, view_kwargs):
"""
query method for Session Type List
:param view_kwargs:
:return:
"""
query_ = self.session.query(SessionType)
query_ = event_query(query_, view_kwargs)
return query_
view_kwargs = True
methods = [
'GET',
]
schema = SessionTypeSchema
data_layer = {
'session': db.session,
'model': SessionType,
'methods': {'query': query,},
}
class SessionTypeDetail(ResourceDetail):
"""
Detail about a single session type by id
"""
def before_get_object(self, view_kwargs):
"""
before get method for session type detail
:param data:
:param view_kwargs:
:return:
"""
if view_kwargs.get('session_id'):
session = safe_query_kwargs(Session, view_kwargs, 'session_id')
if session.session_type_id:
view_kwargs['id'] = session.session_type_id
else:
view_kwargs['id'] = None
decorators = (
api.has_permission(
'is_coorganizer',
methods="PATCH,DELETE",
fetch="event_id",
fetch_as="event_id",
model=SessionType,
),
)
schema = SessionTypeSchema
data_layer = {
'session': db.session,
'model': SessionType,
'methods': {'before_get_object': before_get_object},
}
class SessionTypeRelationshipRequired(ResourceRelationship):
"""
SessionType Relationship
"""
methods = ['GET', 'PATCH']
decorators = (
api.has_permission(
'is_coorganizer',
methods="PATCH",
fetch="event_id",
fetch_as="event_id",
model=SessionType,
),
)
schema = SessionTypeSchema
data_layer = {'session': db.session, 'model': SessionType}
class SessionTypeRelationshipOptional(ResourceRelationship):
"""
SessionType Relationship
"""
decorators = (
api.has_permission(
'is_coorganizer',
methods="PATCH,DELETE",
fetch="event_id",
fetch_as="event_id",
model=SessionType,
),
)
schema = SessionTypeSchema
data_layer = {'session': db.session, 'model': SessionType}