Example #1
0
 def get(self, form_id, photo_id):
     dir = os.path.join(app.config['UPLOAD_FOLDER'], form_id)
     filename = photo_id + '.jpg'
     # trying read picture from disk and send to client
     try:
         if os.path.isfile(dir + '/' + filename):
             return send_from_directory(dir, filename, as_attachment=False)
         else:
             abort(404)
     except Exception as error:
         error_msg = 'Error in Photo class when trying load picture({0}) from disk. Return HTTP:404'.format(
             photo_id)
         logWriter(os.path.abspath(os.curdir) + LOG_PATH).write(error_msg)
         error_msg = str(error)
         logWriter(os.path.abspath(os.curdir) + LOG_PATH).write(error_msg)
         return 404
Example #2
0
 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
Example #3
0
 def post(self):
     """
     Receive a survey composed by survey bady and a survey meta and store in the server
     """
     # check if the post request has the survey document and survey meta
     if 'survey_document' not in request.form or 'survey_meta' not in request.form:
         # No survey_document or survey_meta
         error_msg = 'Error in SurveyList class when trying test the survey_document and survey_meta from request. Return HTTP:500'
         logWriter(os.path.abspath(os.curdir) + LOG_PATH).write(error_msg)
         return {'status': 'parse error'}, 500
     survey_document = request.form['survey_document']
     survey_meta = request.form['survey_meta']
     if survey_document == '' or survey_meta == '':
         error_msg = 'Error in SurveyList class when trying read the survey_document and survey_meta. Return HTTP:500'
         logWriter(os.path.abspath(os.curdir) + LOG_PATH).write(error_msg)
         return {'status': 'missing document'}, 500
     if self.surveyService.addSurveyAndMeta(survey_document, survey_meta):
         return {'status': 'ok'}, 200
     else:
         return {'status': 'store error'}, 500
Example #4
0
 def post(self):
     # check if the post request has the file part
     if 'data' not in request.files or 'form_id' not in request.form:
         # No file part
         error_msg = 'Error in Photo class when trying test the file part from request. Return HTTP:500'
         logWriter(os.path.abspath(os.curdir) + LOG_PATH).write(error_msg)
         return {'status': 'parse error'}, 500
     file = request.files['data']
     form_id = request.form['form_id']
     # if user does not select file, browser also
     # submit an empty part without filename
     if file.filename == '' or form_id == '':
         error_msg = 'Error in Photo class when trying read the filename. Return HTTP:500'
         logWriter(os.path.abspath(os.curdir) + LOG_PATH).write(error_msg)
         return {'status': 'parse error'}, 500
     if file and self.allowed_file(file.filename):
         filename = secure_filename(file.filename)
         if not os.path.isdir(app.config['UPLOAD_FOLDER'] + '/' + form_id):
             os.mkdir(app.config['UPLOAD_FOLDER'] + '/' + form_id)
         file.save(
             os.path.join(app.config['UPLOAD_FOLDER'] + '/' + form_id,
                          filename))
         return {'status': 'completed'}, 201