Ejemplo n.º 1
0
 def collection_post(self):
     """
     ---
     post:
       security:
         - Bearer: [write]
         - Basic: [write]
       tags:
         - "v1"
       summary: "create a lecture"
       operationId: "lecture_collection_post"
       produces:
         - "application/json"
       consumes:
         - "application/json"
       parameters:
       - in: "body"
         name: "body"
         description: ""
         required: true
         schema:
           $ref: "#/definitions/Lecture"
       responses:
         200:
           description: successfull creation of a lecture
           schema:
             type: object
             properties:
               result:
                 type: string
                 example: ok
               created:
                 $ref: "#/definitions/CollectionLecture"
         400:
           description: HTTPBadRequest (Example uses A bad attribute)
           schema:
             type: object
             properties:
               result:
                 type: string
                 example: error
               error:
                 type: array
                 example: [{'description': {'name': ['Missing data for required field.'], 'test123': ['Unknown field.']}, 'name': 'fail', 'location': 'body'}]
     """
     schema = models.LectureSchema()
     schema.context['session'] = self.request.db
     try:
         result = schema.load(self.request.json_body)
     except ValidationError as e:
         self.request.errors.add('body', 'fail', e.messages)
         return {}
     except JSONDecodeError:
         self.request.errors.add('body', 'fail', 'Invalid JSON')
         return {}
     else:
         lecture = models.Lecture(**result)
         self.db.add(lecture)
         self.db.commit()
         return {'result': 'ok', 'created': schema.dump(lecture)}
Ejemplo n.º 2
0
 def __call__(self):
     form = LectureAdd(self.request)
     if self.request.method == 'POST' and form.processPostData(self.request.POST):
         lecture = models.Lecture()
         lecture.assistants.append(self.request.user)
         form.obj = lecture
         form.saveValues()
         self.request.db.add(lecture)
         self.request.db.commit()
         return HTTPFound(self.request.route_url('lecture_edit', lecture_id = lecture.id))
     return {'form': form}