def feature_request_by_id_read(feature_request_id): try: feature_request = FeatureRequest(test=test_mode) feature_request = feature_request.find_by_id(feature_request_id) return jsonify(feature_request.to_dict()) except Exception, e: print e return e
def feature_requests_all_read(): try: feature_request = FeatureRequest(test=test_mode) feature_requests = feature_request.find_all() feature_requests_list = [] for feature_request in feature_requests: feature_requests_list.append(feature_request.to_dict()) return jsonify(feature_requests=feature_requests_list) except Exception, e: print e return e
def send_request(): #try: title = request.form['title'] description = request.form['description'] client = request.form['client'] clientPriority = request.form['clientPriority'] targetDate = request.form['targetDate'] productArea = request.form['productArea'] #debug kek print("title: {0}".format(title)) print("description: {0}".format(description)) print("client: {0}".format(client)) print("clientPriority: {0}".format(clientPriority)) print("targetDate: {0}".format(targetDate)) print("productArea: {0}".format(productArea)) reg = FeatureRequest(title, description, client, clientPriority, targetDate, productArea) db.session.add(reg) db.session.commit() return json.dumps({"response": ('added')}), 200, { 'ContentType': 'application/json' } """except:
def post(self): parsed_args = parser_feature.parse_args() # checking if priority exists title = parsed_args['title'] client_id = parsed_args['client_id'] client_priority = parsed_args['client_priority'] conv_target_date = datetime.strptime(parsed_args['target_date'], "%Y-%m-%d %H:%M") # current_user is not enabled during unit tests if current_user.is_authenticated: user_id = current_user.id else: user_id = 1 # priority algorithm self.checkPriorities(client_id, client_priority, title) feature_request = FeatureRequest(title=title, description=parsed_args['description'], # noqa client_id=client_id, client_priority=client_priority, product_area_id=parsed_args['product_area_id'], # noqa user_id=user_id, target_date=conv_target_date, ticket_url=parsed_args['ticket_url'], date_finished=None, is_finished=False) try: session.add(feature_request) session.commit() print("Session committed") except: session.rollback() print("Session rolled back") return feature_request, 201
def add(): """ Create feature requests handler :return: errors if any otherwise return url """ title = request.form.get("frTitle", None) description = request.form.get("frDescription", None) client_id = request.form.get("frClient", None) priority = request.form.get("frPriority", None) target_date = request.form.get("frTargetDate", None) product_area_id = request.form.get("frProduct", None) errors, priority, target_date = validate_input(title, description, priority, target_date) if errors: return jsonify(errors=errors) if is_duplicate_priority(client_id, priority): reorder_priority(priority, client_id) fr = FeatureRequest( title=title, description=description, clientId=int(client_id), priority=priority, targetDate=target_date, productAreaId=int(product_area_id), createdBy=User.query.filter_by(username="******").first().id) db.session.add(fr) db.session.commit() return jsonify(url=url_for("frapp.index"))
def post(self, fr_id=None): parser = reqparse.RequestParser() parser.add_argument('title', type=str, help='Title for this feature, must be unique') parser.add_argument('description', type=str, help='Description for this feature') parser.add_argument( 'client', type=str, help= "Client to appoint for this feature, choices defined in models.py") parser.add_argument( 'client_priority', type=int, help="Priority number for this feature (1 being the lowest)") parser.add_argument( 'target_date', type=lambda x: datetime.strptime(x, '%Y-%m-%dT%H:%M:%S'), help= "Target date for completion in the format of Y-m-dTH:M:S; i.e.: 2016-07-12T23:13:3" ) parser.add_argument( 'product_area', type=str, help="Area for target feature, choices defined in models.py") args = parser.parse_args(strict=True) if not self._valid_arguments(args): return serialize(args), 400 if not self._valid_choice_field(args['client'], FeatureRequest.CLIENTS): return serialize(args), 400 if not self._valid_choice_field(args['product_area'], FeatureRequest.PRODUCT_AREAS): return serialize(args), 400 new_feature_request = FeatureRequest( title=args['title'], description=args['description'], client=args['client'], client_priority=args['client_priority'], target_date=args['target_date'], product_area=args['product_area']) try: db.session.add(new_feature_request) db.session.commit() except exc.IntegrityError as e: return self._safe_exit_and_error(e) return serialize( db.session.query(FeatureRequest).filter_by( title=args['title']).first())
def create_first_feature_request(): """ Creates a sample feature request for showcase. """ if not db.session.query(FeatureRequest).count(): db.session.add( FeatureRequest( '1 Sample', 'A long description', 'client-a', 1, datetime(year=2017, month=5, day=29, hour=12, minute=30, second=25), 'policies')) db.session.commit()
def add_request(name, description, client, date, priority, productarea): ''' Function to insert request into database. ''' priority = int(priority) db.session.begin_nested() db.session.execute('LOCK TABLE feature_request IN ACCESS EXCLUSIVE MODE;') client_data = FeatureRequest.query.filter_by(client=client.lower()).all() all_data = FeatureRequest.query.all() client_priorities = [int(c.priority) for c in client_data] descriptions = [str(c.description) for c in all_data] sim_count = get_common_description_count(descriptions, description) # If priority is duplicated, priorities of other requests of same client are shifted ahead. Else, the priority is added to the last position if priority not in client_priorities: if len(client_priorities) == 0: priority = 1 else: priority = max(client_priorities) + 1 feat_request = FeatureRequest(name, description, client.lower(), date, priority, productarea) db.session.add(feat_request) db.session.commit() else: feat_request = FeatureRequest(name, description, client.lower(), date, priority, productarea) db.session.add(feat_request) for c in client_data: if c.priority >= priority: c.priority += 1 db.session.add(c) db.session.commit() db.session.commit() return sim_count
def submitFeatureRequest(): session = Session() feature_req_priority = int(request.form['client_priority']) feature_date = datetime.datetime.strptime(request.form['date'], '%m/%d/%Y') session.query(FeatureRequest).\ filter(FeatureRequest.client == request.form['client']).filter(FeatureRequest.client_priority >= feature_req_priority).\ update({FeatureRequest.client_priority: FeatureRequest.client_priority + 1}) # from_statement(text("Update feature_requests set client_priority = client_priority + 1 where client=:client and client_priority >= :client_priority")).\ # params(client=request.form['client'], client_priority=feature_req_priority) feature_request = FeatureRequest(title=request.form['title'], description=request.form['description'], client=request.form['client'], product_area=request.form['product_area'], client_priority=feature_req_priority, date=feature_date) session.add(feature_request) session.commit() return make_response(jsonify({"error": "Merchant ID not given"}, 404))
def new_fr(): req_data = request.get_json() title = req_data.get('title', None) description = req_data.get('description', None) client = req_data.get('client', None) client_priority = req_data.get('client_priority', None) target_date = req_data.get('target_date', None) product_area = req_data.get('product_area', None) if not title or not description or not client: res = app.response_class(response=json.dumps( {"message": "Title, description and client is required"}), status=406, mimetype='application/json') return res qr = FeatureRequest.query.filter(FeatureRequest.client == client).filter( FeatureRequest.client_priority >= client_priority).order_by( FeatureRequest.client_priority).all() # change Client Priority if needes if qr: next_prio = client_priority + 1 for i in qr: i.client_priority = next_prio next_prio += 1 fr = FeatureRequest(title=title, description=description, client=client, client_priority=client_priority, targe_date=target_date, product_area=product_area) db.session.add(fr) db.session.commit() response = app.response_class(response=json.dumps({"id": fr.id}), status=200, mimetype='application/json') return response
def feature_request(): form = FeatureReqForm() if form.validate_on_submit(): feature_req = FeatureRequest() form.populate_obj(feature_req) client_id = form.client.data priority = form.client_priority.data messages = [] if check_feature_req_with_same_priority_for_client(client_id, priority, db): messages = update_all_feature_req_with_equal_greater_priority(client_id, priority, db) db.session.add(feature_req) db.session.commit() flash('New feature request {} is added successfully with priority {}.' .format(form.title.data, form.client_priority.data)) for message in messages: flash(message) return redirect(url_for('done')) return render_template('feature.html', form=form)
def create_feature_request( self, title, description, client, client_priority, target_date, product_area ): """ :param title: :param description: :param client: :param client_priority: :param target_date: :param product_area: :return: """ request = FeatureRequest(title,description, client, client_priority, target_date, product_area) db.session.add(request) db.session.commit()
def add_feature_request(): """route to add feature request.""" feature_requests_schema = FeatureRequestSchema() json_data = request.get_json() if not json_data: return jsonify({'message': 'No input data provided'}), 400 # Validate and deserialize input data, errors = feature_requests_schema.load(json_data) if errors: return jsonify({"errors": errors}), 400 fix_client_priorities(data['client_priority']) feature_request = FeatureRequest() feature_request = _build_feature_request_data(feature_request, data) db.session.add(feature_request) db.session.commit() return jsonify({ "message": "Created new feature request.", "data": FeatureRequestSchema().dump(feature_request) }), 201
def create_dummy_feature_request(client_username): title = "Sample title" description = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent sodales efficitur convallis. " \ "Fusce blandit turpis non laoreet blandit. Fusce aliquam ipsum eget eros volutpat egestas. " \ "Fusce viverra leo id molestie molestie. Morbi sagittis orci sed felis maximus scelerisque. " \ "Etiam magna ante, sollicitudin porta euismod sed, porttitor nec felis." created_by = User.query.filter_by(username="******").first().id products = {1: "Billing", 2: "Claims", 3: "Reports"} # Create dummy feature requests for Client A client_id = User.query.filter_by(username=client_username).first().id for i in range(1, 4): db.session.add( FeatureRequest( title=title + " " + str(i), description=description, clientId=client_id, priority=i, targetDate=datetime.utcnow() + timedelta(days=10 * i), productAreaId=ProductArea.query.filter_by(name=products[i]).first().id, createdBy=created_by ) )
def _insert_feature_requests(client): client.drop_database('featkeeper') feature_request = FeatureRequest() FeatureRequestModel = feature_request.FeatureRequestModel feature_request = FeatureRequestModel({ 'title': 'Support custom themes', 'description': 'Client wants to be able to choose different colors, fonts, and layouts for each module', 'client_name': 'A', 'client_priority': 1, 'target_date': '2016-08-21', 'product_area': 'Policies', 'agent_name': 'Eleuthere', 'ticket_url': 'http://localhost:5000/' + shortuuid.ShortUUID().random(length=6) }) feature_request.save() feature_request = FeatureRequestModel({ 'title': 'CSV export', 'description': 'Client wants to be able to export their monthly payments to CSV file', 'client_name': 'A', 'client_priority': 2, 'target_date': '2016-06-01', 'product_area': 'Billing', 'agent_name': 'Jean Claude', 'ticket_url': 'http://localhost:5000/' + shortuuid.ShortUUID().random(length=6) }) feature_request.save() feature_request = FeatureRequestModel({ 'title': 'Batch excel import', 'description': 'Client wants to be able to batch import Claims from an xlsx file', 'client_name': 'A', 'client_priority': 3, 'target_date': '2016-08-25', 'product_area': 'Claims', 'agent_name': 'Jean Claude', 'ticket_url': 'http://localhost:5000/' + shortuuid.ShortUUID().random(length=6) }) feature_request.save() feature_request = FeatureRequestModel({ 'title': 'Add sales channel field', 'description': 'Client wants to be able to see the sales channel associated', 'client_name': 'B', 'client_priority': 1, 'target_date': '2016-11-21', 'product_area': 'Policies', 'agent_name': 'Eleuthere', 'ticket_url': 'http://localhost:5000/' + shortuuid.ShortUUID().random(length=6) }) feature_request.save() feature_request = FeatureRequestModel({ 'title': 'Implement claim workflow', 'description': 'Client wants to be able to create new workflows and track them for each claim', 'client_name': 'B', 'client_priority': 2, 'target_date': '2016-03-21', 'product_area': 'Claims', 'agent_name': 'Amanda', 'ticket_url': 'http://localhost:5000/' + shortuuid.ShortUUID().random(length=6) }) feature_request.save() feature_request = FeatureRequestModel({ 'title': 'Sales by product area mobile', 'description': 'Client wants to be able to see sales by product area using mobile devices', 'client_name': 'B', 'client_priority': 3, 'target_date': '2016-06-12', 'product_area': 'Reports', 'agent_name': 'Eleuthere', 'ticket_url': 'http://localhost:5000/' + shortuuid.ShortUUID().random(length=6) }) feature_request.save() feature_request = FeatureRequestModel({ 'title': 'Send e-mail on new claim', 'description': 'Client wants to be able to send e-mail to client and agent when new claims get created', 'client_name': 'C', 'client_priority': 1, 'target_date': '2016-12-10', 'product_area': 'Claims', 'agent_name': 'Jean Claude', 'ticket_url': 'http://localhost:5000/' + shortuuid.ShortUUID().random(length=6) }) feature_request.save() feature_request = FeatureRequestModel({ 'title': 'Send telegram message on new policy', 'description': 'Client wants to be able to send a telegram message to client when new policies gets created', 'client_name': 'C', 'client_priority': 2, 'target_date': '2016-06-25', 'product_area': 'Policies', 'agent_name': 'Eleuthere', 'ticket_url': 'http://localhost:5000/' + shortuuid.ShortUUID().random(length=6) }) feature_request.save() feature_request = FeatureRequestModel({ 'title': 'Add customer satisfaction survey', 'description': 'Client wants to be able to send out a survey to evaluate customer satisfaction after issuing a new claim', 'client_name': 'C', 'client_priority': 3, 'target_date': '2016-05-16', 'product_area': 'Claims', 'agent_name': 'Amanda', 'ticket_url': 'http://localhost:5000/' + shortuuid.ShortUUID().random(length=6) }) feature_request.save() feature_request = FeatureRequestModel({ 'title': 'Claims by status', 'description': 'Client wants to be able to see a report showing claims by status where he can filter', 'client_name': 'C', 'client_priority': 4, 'target_date': '2016-07-25', 'product_area': 'Reports', 'agent_name': 'Amanda', 'ticket_url': 'http://localhost:5000/' + shortuuid.ShortUUID().random(length=6) }) feature_request.save()
def feature_requests_update(feature_request_id): try: data = request.data data_dict = json.loads(data) feature_requests_dict = {} feature_request = FeatureRequest(test=test_mode) feature_request.find_by_id(feature_request_id) try: feature_request.title = data_dict['title'] except KeyError: pass try: feature_request.description = data_dict['description'] except KeyError: pass try: feature_request.client_name = data_dict['client_name'] except KeyError: pass try: feature_request.client_priority = data_dict['client_priority'] except KeyError: pass try: feature_request.target_date = data_dict['target_date'] except KeyError: pass try: feature_request.product_area = data_dict['product_area'] except KeyError: pass try: feature_request.agent_name = data_dict['agent_name'] except KeyError: pass try: feature_request.is_open = data_dict['is_open'] except KeyError: pass except Exception, e: return e
def feature_request_add(): data = request.data data_dict = json.loads(data) feature_requests_dict = {} feature_request = FeatureRequest(test=test_mode) feature_request.title = data_dict['title'] feature_request.description = data_dict['description'] feature_request.client_name = data_dict['client_name'] feature_request.client_priority = data_dict['client_priority'] feature_request.target_date = data_dict['target_date'] feature_request.product_area = data_dict['product_area'] feature_request.agent_name = data_dict['agent_name'] feature_request.save() return jsonify({ 'status': 'success', 'message': 'Feature request added', 'feature_request': feature_request.to_dict() })