settings.py 5.75 KB
Newer Older
1
2
3
4
"""Data Model and General Configuration of Eve.

Check out [the Eve docs for configuration](http://python-eve.org/config.html)
if you are unsure about some of the settings.
5
6
7

Several validation rules are still missing, they are marked with TODO in the
schema directly.
8
"""
adietmue's avatar
adietmue committed
9

10
11
12
from os import environ


adietmue's avatar
adietmue committed
13
14
15
# AMIVAPI URL and Admin Group
AMIVAPI_URL = "https://amiv-api.ethz.ch"
ADMIN_GROUP_NAME = 'PVK Admins'
16
17

# DB
18
MONGO_HOST = environ.get('MONGO_HOST', 'localhost')
19
20
21
22
23
MONGO_PORT = 27017
MONGO_USERNAME = 'pvkuser'
MONGO_PASSWORD = 'pvkpass'
MONGO_DBNAME = 'pvk'

adietmue's avatar
adietmue committed
24

25
RESOURCE_METHODS = ['GET', 'POST']
adietmue's avatar
adietmue committed
26
27
ITEM_METHODS = ['GET', 'PATCH', 'DELETE']

28

adietmue's avatar
adietmue committed
29
30
# ISO 8601 time format instead of rfc1123
DATE_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
31

adietmue's avatar
adietmue committed
32

33
# A schema for required start/end time tuple
34
TIMESPAN_SCHEMA = {
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
    'type': 'dict',
    'schema': {
        'start': {
            'type': 'datetime',
            'nullable': False,
            'required': True,
        },
        'end': {
            'type': 'datetime',
            'nullable': False,
            'required': True,
        },
    },
}


51
52
53
54
# Same as Eve, but include 403
STANDARD_ERRORS = [400, 401, 403, 404, 405, 406, 409, 410, 412, 422, 428]


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Resources
DOMAIN = {
    'lectures': {
        'schema': {
            'title': {
                'type': 'string',
                'maxlength': 100,
                'unique': True,
                'required': True,
                'nullable': False,
                'empty': False,
            },
            'department': {
                'type': 'string',
                'allowed': ['itet', 'mavt'],
                'required': True,
                'nullable': False,
            },
            'year': {
                'type': 'integer',
                'min': 1,
                'max': 3,
                'required': True
            },
79
80
81
82
83
84
85
86
87
88
89
90
            'assistants': {
                # List of nethz of assistants
                'type': 'list',
                'schema': {
                    'type': 'string',
                    'maxlength': 10,
                    'empty': False,
                    'nullable': False,
                }
                # TODO: Not the same nethz twice
                # TODO: nethz is enough?
            }
91
92
93
94
95
96
97
98
99
100
101
102
        },
    },

    'courses': {
        'schema': {
            'lecture': {
                'type': 'objectid',
                'data_relation': {
                    'resource': 'lectures',
                    'field': '_id',
                    'embeddable': True
                },
103
                'not_patchable': True,  # Course is tied to lecture
104
105
            },
            'assistant': {
106
107
                'type': 'string'
                # TODO: Assistant needs to exist for lecture
108
109
            },

110
            'signup': TIMESPAN_SCHEMA,
111
112
113

            'datetimes': {
                'type': 'list',
114
115
                'schema': TIMESPAN_SCHEMA,
                # TODO: Timeslots must not overlap
116
117
118
119
120
121
122
123
            },
            'room': {
                'type': 'string',
                'maxlength': 100,
                'unique': True,
                'required': True,
                'nullable': False,
                'empty': False,
124
                # TODO: Room must be empty for time slot
125
126
127
128
129
130
131
132
133
134
135
            },
            'spots': {
                'type': 'integer',
                'min': 1,
                'required': True,
                'nullable': False
            }
        },
    },

    'signups': {
136
137
        # Signup for a user to a course

138
139
140
141
142
143
144
        'schema': {
            'nethz': {
                'type': 'string',
                'maxlength': 10,
                'empty': False,
                'nullable': False,
                'required': True,
adietmue's avatar
adietmue committed
145
                'only_own_nethz': True,
146
                'not_patchable': True,  # Signup is tied to user
147
148
149
150
151
152
153
154
            },
            'course': {
                'type': 'objectid',
                'data_relation': {
                    'resource': 'courses',
                    'field': '_id',
                    'embeddable': True
                },
adietmue's avatar
adietmue committed
155
                'unique_combination': ['nethz'],
156
                # TODO: No overlapping courses
157
158
159
            },
            'status': {
                'type': 'string',
160
                'allowed': ['waiting', 'reserved', 'accepted'],
161
162
163
                'readonly': True,
            },
        },
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
    },

    'selections': {
        # Easy way for users to safe their selections before signup is open
        # List of selected courses per user

        'schema': {
            'nethz': {
                'type': 'string',
                'maxlength': 10,
                'empty': False,
                'nullable': False,
                'required': True,
                'only_own_nethz': True,
                'unique': True,
            },
            'courses': {
                'type': 'list',
                'schema': {
                    'type': 'objectid',
                    'data_relation': {
                        'resource': 'courses',
                        'field': '_id',
                        'embeddable': True
                    },
                    # TODO: No duplicate entries
                    # TODO: No entries that are already reserved
                },
            },
        },
    },

    'payments': {
        # Dummy endpoint for payments.
        # TODO: Implement as soon as PSP is known.

        'schema': {
            'signups': {
                'type': 'list',
                'schema': {
                    'type': 'objectid',
                    'data_relation': {
                        'resource': 'signups',
                        'field': '_id',
                        'embeddable': True
                    },
                    # TODO: No duplicate entries
                },
                'required': True,
                'nullable': False,
            }
        }
216
217
    }
}