def get(self): """ Return Sections """ if 'campus' not in dir(g.client): abort(400, error='You must have campus') return { 'sections': [s for s in Section.objects(campus=g.client.campus)] }
def post(self): """ Add Section """ data = request.json c = Campus.objects.get_or_404(id=data['campus']) if Section.objects(name=data['name'], campus=c).count() > 0: abort(400, error='Name already exist') s = Section(campus=c, year=data['year'], name=data['name']) s.save() return s