def calculate_activities(request): ''' Calculates the calories needed by additional physical activities ''' data = [] form = PhysicalActivitiesForm(data=request.POST, instance=request.user.userprofile) if form.is_valid(): form.save() # Calculate the activities factor and the total calories factor = request.user.userprofile.calculate_activities() total = request.user.userprofile.calculate_basal_metabolic_rate( ) * factor result = { 'activities': '{0:.0f}'.format(total), 'factor': '{0:.2f}'.format(factor) } data = json.dumps(result) else: logger.debug(form.errors) # Return the results to the client return HttpResponse(data, 'application/json')
def view(request): """ The basal metabolic rate detail page """ form_data = {'age': request.user.userprofile.age, 'height': request.user.userprofile.height, 'gender': request.user.userprofile.gender, 'weight': request.user.userprofile.weight} context = {'form': BmrForm(initial=form_data), 'form_activities': PhysicalActivitiesForm(instance=request.user.userprofile), 'form_calories': DailyCaloriesForm(instance=request.user.userprofile)} return render(request, 'rate/form.html', context)
def view(request): ''' The basal metabolic rate detail page ''' form_data = {'age': request.user.userprofile.age, 'height': request.user.userprofile.height, 'gender': request.user.userprofile.gender, 'weight': request.user.userprofile.weight} context = {} context['form'] = BmrForm(initial=form_data) context['form_activities'] = PhysicalActivitiesForm(instance=request.user.userprofile) context['form_calories'] = DailyCaloriesForm(instance=request.user.userprofile) return render(request, 'rate/form.html', context)