Skip to content

armgit / wger

Public Imported from GitHub
0

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.py
new file mode 100644
index 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.py
index 857b9feae..37c4805a7 100644
--- a/wger/weight/urls.py
+++ b/wger/weight/urls.py
@@ -18,13 +18,12 @@
from django.conf.urls import patterns, url
from django.contrib.auth.decorators import login_required
+from wger.weight.forms import WeightCsvImportForm
from wger.weight.views import WeightAddView
from wger.weight.views import WeightUpdateView
from wger.weight.views import WeightCsvImportFormPreview
-from wger.weight.views import WeightCsvImportForm
urlpatterns = 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.py
index 05d4fa04f..d8e28ede7 100644
--- a/wger/weight/views.py
+++ b/wger/weight/views.py
@@ -21,12 +21,6 @@ import datetime
from django.shortcuts import render
from django.http import HttpResponse
from 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 forms
from django.core.urlresolvers import reverse
from django.core.urlresolvers import reverse_lazy
from django.contrib.auth.decorators import login_required
@@ -38,30 +32,18 @@ from django.db.models import Min
from django.db.models import Max
from django.views.generic import CreateView
from django.views.generic import UpdateView
-from django.forms import widgets
from rest_framework.response import Response
from rest_framework.decorators import api_view
+from wger.weight.forms import WeightForm
from wger.weight.models import WeightEntry
from wger.weight import helpers
from wger.utils.generic_views import WgerFormMixin
-from wger.utils.constants import DATE_FORMATS
-from wger.utils.widgets import Html5DateInput
logger = 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'