Self hosted FLOSS fitness/workout, nutrition and weight tracker
Cleanup views file for weight app
Roland Geider1ff3fa919342
diff --git a/wger/weight/forms.py b/wger/weight/forms.pynew file mode 100644index 000000000..5ba556162--- /dev/null+++ b/wger/weight/forms.py@@ -0,0 +1,49 @@+# -*- coding: utf-8 -*-++# This file is part of wger Workout Manager.+#+# wger Workout Manager is free software: you can redistribute it and/or modify+# it under the terms of the GNU Affero General Public License as published by+# the Free Software Foundation, either version 3 of the License, or+# (at your option) any later version.+#+# wger Workout Manager is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU Affero General Public License++from django import forms+from django.forms import Form, CharField, Textarea, ModelForm, DateField, widgets+from django.utils.translation import ugettext as _++from wger.utils.constants import DATE_FORMATS+from wger.utils.widgets import Html5DateInput+from wger.weight.models import WeightEntry+++CSV_DATE_FORMAT = (('%d.%m.%Y', 'DD.MM.YYYY (30.01.2012)'),+ ('%d.%m.%y', 'DD.MM.YY (30.01.12)'),+ ('%Y-%m-%d', 'YYYY-MM-DD (2012-01-30)'),+ ('%y-%m-%d', 'YY-MM-DD (12-01-30)'),+ ('%m/%d/%Y', 'MM/DD/YYYY (01/30/2012)'),+ ('%m/%d/%y', 'MM/DD/YY (01/30/12)'),)+++class WeightCsvImportForm(Form):+ '''+ A helper form with only a textarea+ '''+ csv_input = CharField(widget=Textarea, label=_('Input'))+ date_format = forms.ChoiceField(choices=CSV_DATE_FORMAT, label=_('Date format'))+++class WeightForm(ModelForm):+ creation_date = DateField(input_formats=DATE_FORMATS, widget=Html5DateInput())++ class Meta:+ model = WeightEntry+ widgets = {+ 'user': widgets.HiddenInput(),+ }diff --git a/wger/weight/urls.py b/wger/weight/urls.pyindex 857b9feae..37c4805a7 100644--- a/wger/weight/urls.py+++ b/wger/weight/urls.py@@ -18,13 +18,12 @@from django.conf.urls import patterns, urlfrom django.contrib.auth.decorators import login_required+from wger.weight.forms import WeightCsvImportFormfrom wger.weight.views import WeightAddViewfrom wger.weight.views import WeightUpdateViewfrom wger.weight.views import WeightCsvImportFormPreview-from wger.weight.views import WeightCsvImportFormurlpatterns = patterns('wger.weight.views',-url(r'^add/$',login_required(WeightAddView.as_view()),name='weight-add'),@@ -42,6 +41,4 @@ urlpatterns = patterns('wger.weight.views','overview',name='weight-overview'),url(r'^api/get_weight_data/$', 'get_weight_data'),--)diff --git a/wger/weight/views.py b/wger/weight/views.pyindex 05d4fa04f..d8e28ede7 100644--- a/wger/weight/views.py+++ b/wger/weight/views.py@@ -21,12 +21,6 @@ import datetimefrom django.shortcuts import renderfrom django.http import HttpResponsefrom django.http import HttpResponseRedirect-from django.forms import ModelForm-from django.forms import DateField-from django.forms import CharField-from django.forms import Textarea-from django.forms import Form-from django import formsfrom django.core.urlresolvers import reversefrom django.core.urlresolvers import reverse_lazyfrom django.contrib.auth.decorators import login_required@@ -38,30 +32,18 @@ from django.db.models import Minfrom django.db.models import Maxfrom django.views.generic import CreateViewfrom django.views.generic import UpdateView-from django.forms import widgetsfrom rest_framework.response import Responsefrom rest_framework.decorators import api_view+from wger.weight.forms import WeightFormfrom wger.weight.models import WeightEntryfrom wger.weight import helpersfrom wger.utils.generic_views import WgerFormMixin-from wger.utils.constants import DATE_FORMATS-from wger.utils.widgets import Html5DateInputlogger = logging.getLogger('wger.custom')-class WeightForm(ModelForm):- creation_date = DateField(input_formats=DATE_FORMATS, widget=Html5DateInput())-- class Meta:- model = WeightEntry- widgets = {- 'user': widgets.HiddenInput(),- }--class WeightAddView(WgerFormMixin, CreateView):'''Generic view to add a new weight entry@@ -188,22 +170,6 @@ def get_weight_data(request):return Response(chart_data)-CSV_DATE_FORMAT = (('%d.%m.%Y', 'DD.MM.YYYY (30.01.2012)'),- ('%d.%m.%y', 'DD.MM.YY (30.01.12)'),- ('%Y-%m-%d', 'YYYY-MM-DD (2012-01-30)'),- ('%y-%m-%d', 'YY-MM-DD (12-01-30)'),- ('%m/%d/%Y', 'MM/DD/YYYY (01/30/2012)'),- ('%m/%d/%y', 'MM/DD/YY (01/30/12)'),)---class WeightCsvImportForm(Form):- '''- A helper form with only a textarea- '''- csv_input = CharField(widget=Textarea, label=_('Input'))- date_format = forms.ChoiceField(choices=CSV_DATE_FORMAT, label=_('Date format'))--class WeightCsvImportFormPreview(FormPreview):preview_template = 'import_csv_preview.html'form_template = 'import_csv_form.html'