Ejemplo n.º 1
0
class TemplateSession(Resource):
    def __init__(self):
        self.templateService = TemplateService()

    def get(self, tpl_key):
        aTplSession = self.templateService.getTemplateSessionByKey(tpl_key)
        return aTplSession, 200

    def delete(self, tpl_key):
        """
        When remove one survey session the related survey templates will be remove too.
        It's allowed only if no forms uses the template.
        """
        if self.templateService.removeTemplateByKey(tpl_key) == 1:
            return {'status': 'ok'}, 200
        else:
            return {'status': 'no found'}, 404

    def put(self, tpl_key):
        """
        The update of template session is disallowed to the key, only to the other properties.
        """
        args = parser.parse_args()
        document = json.loads(args['template_session'])
        document['key'] = tpl_key
        if self.templateService.updateTemplateSessionByKey(tpl_key,
                                                           document) == 1:
            return {'status': 'ok'}, 200
        else:
            return {'status': 'no found'}, 404
Ejemplo n.º 2
0
class TemplateSessionList(Resource):
    def __init__(self):
        self.templateService = TemplateService()

    def get(self):
        """
        Return all templates sessions of survey stored in the server
        """
        templates = self.templateService.getAllSessions()
        if templates == False:
            return {'status': 'no found'}, 404
        else:
            return templates, 200

    def post(self):
        """
        Receive a survey template and store in the server
        """
        # check if the post request has the survey template document
        if 'template_session' not in request.form:
            # No template_session
            error_msg = 'Error in TemplateSessionList class when trying test the template_session from request. Return HTTP:500'
            logWriter(os.path.abspath(os.curdir) + LOG_PATH).write(error_msg)
            return {'status': 'parse error'}, 500
        template_session = request.form['template_session']
        if template_session == '':
            error_msg = 'Error in TemplateSessionList class when trying read the template_session. Return HTTP:500'
            logWriter(os.path.abspath(os.curdir) + LOG_PATH).write(error_msg)
            return {'status': 'missing document'}, 500
        if self.templateService.addSession(template_session):
            return {'status': 'ok'}, 200
        else:
            return {'status': 'store error'}, 500
Ejemplo n.º 3
0
 def __init__(self):
     self.templateService = TemplateService()