def setUp(self): db.create_all() db.session.add(Client(name='Client A')) db.session.add(Client(name='Client B')) db.session.add(Client(name='Client C')) db.session.add(ProductArea(name='Policies')) db.session.add(ProductArea(name='Billings')) db.session.add(ProductArea(name='Claims')) db.session.add(ProductArea(name='Reports')) featureRequest = FeatureRequest(title='First Title', description='First Description', target_date=datetime.strptime( '2019/05/24', '%Y/%m/%d'), client_priority=1, client_id=3, product_area_id=2) db.session.add(featureRequest) featureRequest = FeatureRequest(title='Second Title', description='Second Description', target_date=datetime.strptime( '2019/05/31', '%Y/%m/%d'), client_priority=1, client_id=2, product_area_id=3) db.session.add(featureRequest) featureRequest = FeatureRequest(title='Third Title', description='Third Description', target_date=datetime.strptime( '2019/06/15', '%Y/%m/%d'), client_priority=1, client_id=1, product_area_id=1) db.session.add(featureRequest) db.session.commit()
def complete(id): feature_request = FeatureRequest.query.get(id) client = feature_request.client priority = feature_request.priority feature_request.priority = 0 FeatureRequest.adjust_priorities(client, priority, -1) db.session.commit() return jsonify({'success': True})
def delete(id): feature_request = FeatureRequest.query.get(id) client = feature_request.client priority = feature_request.priority db.session.delete(feature_request) if priority > 0: # Adjust priorities only for active records FeatureRequest.adjust_priorities(client, priority, -1) db.session.commit() return jsonify({'success': True})
def feature_request(): form = FeatureRequestForm() if form.validate_on_submit(): # clamp priority to one plus highest high = highest_priority(form.client.data) if form.priority.data >= high: form.priority.data = high + 1 # if lower than top move the rest up refit_client_priorities(form.priority.data, form.client.data) # insert f = FeatureRequest(title=form.title.data, description=form.description.data, client_id=form.client.data, priority=form.priority.data, target_date=form.target_date.data, product_area=form.product_area.data) db.session.add(f) db.session.commit() client = db.session.query(Client).filter( Client.id == int(form.client.data)).first().name flash('"{}" feature created for "{}".'.format(form.title.data, client)) return redirect(url_for('feature_request')) return render_template('feature_request.html', title='Feature Request creation form', form=form, links=links, root_url=SUBDIR)
def create_feature_request(): if request.method == 'POST': if request.json: feature_request = FeatureRequest(**request.json) db.session.add(feature_request) db.session.commit() return jsonify(feature_request), 201 abort(400)
def test_db_add_feature_request(self): feature_request = FeatureRequest() feature_request.title = 'Does adding a request work?' feature_request.priority = 1 feature_request.client_id = 1 feature_request.product_area = 'Billing' feature_request.target_date = datetime.strptime( '2018-06-20', "%Y-%m-%d").date() self.db.session.add(feature_request)
def delete_feature_request(feature_request_id): feature_request = FeatureRequest.query.filter( FeatureRequest.id == feature_request_id).first() db.session.delete(feature_request) db.session.commit() # Should re-prioritize... result = reprioritize_feature_requests( feature_request.client_id, feature_request.priority, (FeatureRequest.nextPriorityByClient(feature_request.client_id) - 1), False) return jsonify(feature_requests=result)
def create_feature_request(): # Grab the highest priority (for this client). initial_priority = FeatureRequest.nextPriorityByClient( request.json['client_id']) feature_request = FeatureRequest( title=request.json['title'], product_area=request.json['product_area'], target_date=datetime.strptime(request.json['target_date'], "%Y-%m-%d").date(), description=(request.json['description'] if 'description' in request.json.keys() else ""), priority=initial_priority, client_id=request.json['client_id']) db.session.add(feature_request) db.session.commit() id = feature_request.id # We'll return all records with adjusted priority. return jsonify(feature_requests=reprioritize_feature_requests( request.json['client_id'], initial_priority, request.json['priority']))
def createFeatueRequest(req): """Saves A Feature Request To The DB""" featureRequest = FeatureRequest(title=req['title'], description=req['description'], target_date=req['target_date'], client_priority=req['client_priority'], client_id=req['client'], product_area_id=req['product_area']) db.session.add(featureRequest) db.session.commit() # Refresh The Inserted Request To Get Its ID Back db.session.refresh(featureRequest) requestId = featureRequest.serializeModel['requestId'] updateClientPriority(req['client'], req['client_priority'], requestId) return req
def new_feature_request(): request = FeatureRequest( title='Lorem Ipsum', description=( 'And lead, praseodymium and platinum, plutonium,' 'Palladium, promethium, potassium, polonium,' 'And tantalum, technetium, titanium, tellurium,' 'And cadmium and calcium and chromium and curium.' 'There\'s sulfur, californium and fermium, berkelium,' 'And also mendelevium, einsteinium, nobelium,' 'And argon, krypton, neon, radon, xenon, zinc and rhodium,' 'And chlorine, carbon, cobalt, copper, tungsten, tin and sodium.' 'These are the only ones of which the news has come to Harvard,' 'And there may be many others but they haven\'t been discovered.'), client=Clients.client_one, client_priority=1, available_on=datetime.now() + timedelta(days=30), product_area=ProductAreas.billing, requested_by=1) return request
def index(): form = AddUpdateForm() if request.method == 'POST': if form.validate_on_submit(): if form.id.data < 1: # Insert Mode update_priority = True FeatureRequest.adjust_priorities(form.client.data, form.priority.data, 1) feature_request = FeatureRequest( priority=form.priority.data, title=form.title.data, description=form.description.data, target_date=form.target_date.data, client=form.client.data, product_area=form.product_area.data ) db.session.add(feature_request) else: # Update mode feature_request = FeatureRequest.query.get(form.id.data) current_priority = feature_request.priority update_priority = True if current_priority != form.priority.data else False feature_request.title = form.title.data feature_request.description = form.description.data feature_request.target_date = form.target_date.data feature_request.client = form.client.data feature_request.product_area = form.product_area.data if update_priority: feature_request.set_priority(form.priority.data) db.session.commit() return jsonify({'success': True, 'update_priority': update_priority}) else: return jsonify({'success': False, 'errors': form.errors}) # GET method data_choices = { 'clients': CLIENT_CHOICES, 'product_areas': PRODUCT_AREA_CHOICES } return render_template('index.html', form=form, data_choices=data_choices)
def feature_requests(): if request.method == 'POST': title = str(request.form['title']) description = str(request.form['description']) if "client" in request.form and request.form['client'] != "": client = Client(name=request.form['client']) db.session.add(client) db.session.commit() client_id = client.id else: client_id = request.form['client_id'] if "product_area" in request.form and request.form[ 'product_area'] != "": product_area = ProductArea(name=request.form['product_area']) db.session.add(product_area) db.session.commit() product_area_id = product_area.id else: product_area_id = request.form['product_area_id'] target_date = str(request.form['target_date']) priority = int(request.form['priority']) feature_request = FeatureRequest(title=title, description=description, client_id=client_id, target_date=target_date, priority=priority, product_area_id=product_area_id) db.session.add(feature_request) priority_to_update = priority feat_requests_to_update_count = FeatureRequest.query.filter_by( client_id=client_id, priority=priority_to_update).count() while feat_requests_to_update_count > 1: feat_requests_to_update = FeatureRequest.query.filter_by( client_id=client_id, priority=priority_to_update).order_by('id').first() feat_requests_to_update.priority = feat_requests_to_update.priority + 1 priority_to_update = priority_to_update + 1 feat_requests_to_update_count = FeatureRequest.query.filter_by( client_id=client_id, priority=priority_to_update).count() db.session.commit() response = jsonify({ 'id': feature_request.id, 'title': feature_request.title, 'description': feature_request.description, 'client_id': feature_request.client_id, 'client': feature_request.client.name, 'target_date': feature_request.target_date, 'product_area_id': feature_request.product_area_id, 'product_area': feature_request.product_area.name, 'priority': feature_request.priority }) response.status_code = 201 return response else: feature_requests = FeatureRequest.query.all() results = [] for item in feature_requests: results.append({ 'id': item.id, 'title': item.title, 'description': item.description, 'client_id': item.client_id, 'target_date': item.target_date, 'client': item.client.name, 'product_area_id': item.product_area_id, 'product_area': item.product_area.name, 'priority': item.priority }) response = jsonify(results) response.status_code = 200 return response
def init_database(): # Create the database and the database table db.create_all() # Insert user data user1 = User(email='*****@*****.**', plain_password='******') user2 = User(email='*****@*****.**', plain_password='******') db.session.add(user1) db.session.add(user2) # Insert feature request request1 = FeatureRequest( title='Lorem Ipsum', description= ('In publishing and graphic design, lorem ipsum is a' ' placeholder text used to demonstrate the visual form of a document' ' without relying on meaningful content. Replacing the actual content' ' with placeholder text allows designers to design the form of the' ' content before the content '), client=Clients.client_one, client_priority=1, available_on=datetime.now() + timedelta(days=30), product_area=ProductAreas.billing, requested_by=1) request2 = FeatureRequest( title='The Knight who say ni', description=('There\'s antimony, arsenic, aluminum, selenium,' 'And hydrogen and oxygen and nitrogen and rhenium,' 'And nickel, neodymium, neptunium, germanium,' 'And iron, americium, ruthenium, uranium,' 'Europium, zirconium, lutetium, vanadium,' 'And lanthanum and osmium and astatine and radium,' 'And gold, protactinium and indium and gallium,' 'And iodine and thorium and thulium and thallium. '), client=Clients.client_three, client_priority=4, available_on=datetime.now() + timedelta(days=4), product_area=ProductAreas.claims, requested_by=2) request3 = FeatureRequest( title='Stan Lee', description=('There\'s yttrium, ytterbium, actinium, rubidium,' 'And boron, gadolinium, niobium, iridium,' 'There\'s strontium and silicon and silver and samarium,' 'And bismuth, bromine, lithium, beryllium, and barium.' 'There\'s holmium and helium and hafnium and erbium,' 'And phosphorus and francium and fluorine and terbium,' 'And manganese and mercury, molybdenum, magnesium,' 'Dysprosium and scandium and cerium and cesium.'), client=Clients.client_three, client_priority=1, available_on=datetime.now() + timedelta(days=54), product_area=ProductAreas.claims, requested_by=1) db.session.add(request1) db.session.add(request2) db.session.add(request3) # Commit the changes to the DB db.session.commit() yield db db.drop_all()
app = create_app() app.app_context().push() with app.app_context(): db.create_all() db.session.add(Client(name='Client A')) db.session.add(Client(name='Client B')) db.session.add(Client(name='Client C')) db.session.add(ProductArea(name='Policies')) db.session.add(ProductArea(name='Billings')) db.session.add(ProductArea(name='Claims')) db.session.add(ProductArea(name='Reports')) featureRequest = FeatureRequest( title='First Title', description='First Description', target_date=datetime.strptime('2019/05/24', '%Y/%m/%d'), client_priority=1, client_id=3, product_area_id=2 ) db.session.add(featureRequest) featureRequest = FeatureRequest( title='Second Title', description='Second Description', target_date=datetime.strptime('2019/05/31', '%Y/%m/%d'), client_priority=1, client_id=2, product_area_id=3 ) db.session.add(featureRequest) featureRequest = FeatureRequest(
clientB = Client('Client B') clientC = Client('Client C') clientD = Client('Client D') db.session.add(clientA) db.session.add(clientB) db.session.add(clientC) db.session.add(clientD) policies = ProductArea('Policies') claims = ProductArea('Claims') billing = ProductArea('Billing') reports = ProductArea('Reports') db.session.add(policies) db.session.add(claims) db.session.add(billing) db.session.add(reports) feat_req = FeatureRequest('This is a title', 'This is not the description you are looking for', 1, 1, 1, 1, '2019-06-01', 'www.wired.com', None, False) feat_req2 = FeatureRequest('This is another title', 'Another description', 1, 2, 1, 1, '2019-06-01', 'www.google.com', None, False) feat_req3 = FeatureRequest('Great title', 'Greater description', 1, 3, 1, 1, '2019-06-01', 'www.nytimes.com', None, False) db.session.add(feat_req) db.session.add(feat_req2) db.session.add(feat_req3) db.session.commit()
def feature_requests(): if request.method == "POST": if not dummy_loguin(''): response = {'message': 'You need loguin!'} return make_response(jsonify(response)), 301 title = request.data.get('title', False) description = str(request.data.get('description', "")) product_area = request.data.get('product_area', False) client_id = request.data.get('client_id', False) client_priority = int(request.data.get('client_priority', 1)) try: date_target = datetime.strptime( request.data.get('date_target', ''), '%Y-%m-%d') except ValueError as error: date_target = None if title and product_area and client_id and date_target: # fr = FeatureRequest.query.filter_by(client_id=client_id, client_priority=client_priority).first() # # if fr is not None: # response = jsonify({ # 'message': 'Exists priority {} for client "{}" '.format(client_priority, DUMMY_CLIENT_MAP[client_id]) # }) # return make_response(response),402 fr = FeatureRequest(title=str(title)) fr.description = description fr.product_area = str(product_area) fr.client_id = int(client_id) fr.client_priority = int(client_priority) fr.date_target = date_target fr.save() priority_to_update = client_priority features_to_update_count = FeatureRequest.query.filter_by( client_id=client_id, client_priority=priority_to_update).count() while features_to_update_count > 1: feature_to_update = FeatureRequest.query.filter_by( client_id=client_id, client_priority=priority_to_update).order_by( 'id').first() feature_to_update.client_priority = feature_to_update.client_priority + 1 priority_to_update = priority_to_update + 1 feature_to_update.save() features_to_update_count = FeatureRequest.query.filter_by( client_id=client_id, client_priority=priority_to_update).count() response = jsonify({ 'id': fr.id, 'title': fr.title, 'description': fr.description, 'product_area': fr.product_area, 'client_id': fr.client_id, 'client_priority': fr.client_priority, 'date_target': fr.date_target, }) r = make_response(response) r.headers.add('Access-Control-Allow-Origin', '*') return r, 201 else: response = jsonify({ 'message': 'Error, need some parameters', 'title': title, 'description': description, 'product_area': product_area, 'client_id': client_id, 'client_priority': client_priority, 'date_target': date_target, }) r = make_response(response) r.headers.add('Access-Control-Allow-Origin', '*') return r, 401 if request.method == "GET": # GET # get all the feature_requests results = [] all_fr = FeatureRequest.query.all() for fr in all_fr: obj = { 'id': fr.id, 'title': fr.title, 'description': fr.description, 'product_area': fr.product_area, 'client_id': fr.client_id, 'client_priority': fr.client_priority, 'date_target': fr.date_target.strftime('%Y-%m-%d'), } results.append(obj) r = make_response(jsonify(results)) r.headers.add('Access-Control-Allow-Origin', '*') return r, 200 else: response = {'message': 'Error, please contact administrator'} r = make_response(jsonify(response)) r.headers.add('Access-Control-Allow-Origin', '*') return r, 401