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 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)