def category(cat): form = CategorySummaryForm() info_requester = InfoRequestHandler(current_user.id) file_info = info_requester.get_file_details() if not file_info: return redirect(url_for('upload_file')) # someday need to abstract this if not info_requester.is_category_included(category=cat): flash('category is no longer in the dataset') return redirect(request.referrer) # few categories will have existing state if request.method == 'POST': if form.change_state.data: info_requester.set_category_current_state(cat, form.state_radio_button.data) elif form.delete_prev_states_button.data: info_requester.delete_category_states(cat) redirect(url_for('category', cat=cat)) form.state_radio_button.choices = [(s.id, s.state) for s in (info_requester.get_state_lookups() or [])] form.state_radio_button.default = info_requester.get_current_state_id(cat) or 0 form.prev_states.choices = [(index, str(s.StateLookup.state) + ' @ ' + str(s.CategoryState.timestamp)) for s in (info_requester.get_category_state_info(cat))] form.process() return render_template('category_summary.html', form=form, file_info=[file_info[0], file_info[1]], title=cat + ' summary', today=date.today(), category=cat, frequency=info_requester.get_frequency(cat), spending_summary_info=info_requester.get_cat_summary_spending_info(list_of_categories=[cat]), metadata=info_requester.get_category_metadata_list(categories=[cat]), items=info_requester.get_items_for(category=cat))
def state_admin(): form = StateAdminForm() info_requester = InfoRequestHandler(current_user.id) file_info = info_requester.get_file_details() if not file_info: return redirect(url_for('upload_file')) # someday need to abstract this if request.method == 'POST': if form.new_state.data: info_requester.add_lookup_state(state=form.new_state.data, desc=form.new_state_description.data) elif form.delete.data: info_requester.delete_lookup_states([int(form.states.data)]) redirect(url_for('state_admin')) form.states.choices = [(s.id, str(s.id) + ': ' + s.state) for s in (info_requester.get_state_lookups() or [])] return render_template('state_admin.html', title='files...', form=form, file_info=file_info, categories_by_state=info_requester.get_categories_by_current_state())