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 summary_tag_categories(summary_tag): info_requester = InfoRequestHandler(current_user.id) file_info = info_requester.get_file_details() categories_for_summary_tag = info_requester.get_categories(summary_tag=summary_tag) return render_template('summary_tag_categories.html', title='summary of categories for ' + summary_tag, file_info=[file_info[0], file_info[1]], summary_tag=summary_tag, metadata=info_requester.get_category_metadata_list(categories=categories_for_summary_tag))
def frequency_categories(frequency): # form = Form() info_requester = InfoRequestHandler(current_user.id) file_info = info_requester.get_file_details() categories_for_frequency = info_requester.get_categories(category_type='expense', frequency=frequency) return render_template('frequency_categories.html', title='summary of categories for ' + frequency, file_info=[file_info[0], file_info[1]], frequency=frequency, metadata=info_requester.get_category_metadata_list(categories=categories_for_frequency))
def categories(): 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 return render_template('categories.html', file_info=[file_info[0], file_info[1]], title='Categories', today=date.today(), metadata=info_requester.get_category_metadata_list())