def update_total(request): ''' Calculates the total calories TODO: this really should be moved to an API so we can just update this setting in the user profile ''' data = [] form = DailyCaloriesForm(data=request.POST, instance=request.user.userprofile) if form.is_valid(): form.save() # Save the total calories request.user.userprofile.calories = form.cleaned_data['calories'] request.user.userprofile.save() 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)