def upload(): try: user = User() account = user.get_user_by_id(session['id']).as_dict() if request.method == 'GET': if 'loggedin' in session: return render_template('upload.html', account=account) username = account.get('username') user_uuid = account.get('user_uuid') user_role = account.get('user_role') form = request.form subject = form.get('subject') comment_desc = form.get('comment_desc') other_desc = form.get('other_desc') files = flask.request.files.getlist("file") if not files: raise Exception("No images found to process") img_params = { 'username': username, 'user_uuid': user_uuid, 'images': files, 'user_role': user_role, 'subject': subject, 'comment_desc': comment_desc, 'other_desc': other_desc } img_cls = Image.Image(img_params) status, status_msg = img_cls.upload_image_to_s3() if status is False: return create_json_response(ERROR, status_msg) return redirect(url_for('forum')) except Exception as e: logger.error('Failed to upload images: {}'.format(str(e))) return create_json_response(ERROR, e)
def get_comments(): try: comments_cls = comments.Comments(limit=10) status, response_obj = comments_cls.get_comments() return jsonify({"results": response_obj}), 200 except Exception as e: logger.error('Failed to upload images: {}'.format(str(e))) return create_json_response(ERROR, e)
def list_users_from_s3(self): try: users = s3_helper.list_s3_objects(config.S3_BUCKET, config.S3_IMAGE_DIR) return users except Exception as e: logger.error('Failed to get Users from S3 with error: {}'.format( str(e))) raise
def detect_image_labels(image): labels = {} try: with open(image, 'rb') as out: labels = img_rekog_client.detect_labels(Image={'Bytes': out.read()}) labels = labels.get('Labels') except Exception as e: logger.error("Failed to detect lables from image: {} with error :{}" \ .format(image, str(e))) return labels
def addcomment(): try: activity_id = request.form['activity_id'] commented_by = request.form['username'] commented_header = request.form['subject'] commented_desc = request.form['description'] comments_cls = comments.Comments(limit=10) status, response_obj = comments_cls.add_comment( commented_by, activity_id, commented_header, commented_desc) if status is False: return create_json_response(ERROR, response_obj) return create_json_response(SUCCESS, response_obj) except Exception as e: logger.error('Failed to upload images: {}'.format(str(e))) return create_json_response(ERROR, e)
def dashboard(): try: form = request.form username = form.get('username') user_role = form.get('user_role') if not username: raise Exception("No username found to process") if not user_role: raise Exception("No user_role found to process") comments_cls = comments.Comments(10) status, response_msg = comments_cls.get_dashboard_results( user_name=username, user_role=user_role) if status is False: return create_json_response(ERROR, response_msg) return jsonify({"results": response_msg}), 200 except Exception as e: logger.error('Failed to upload images: {}'.format(str(e))) return create_json_response(ERROR, e)