Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add more files to 'weight' application

Roland Geiderd6e74ab09468
diff --git a/weight/admin.py b/weight/admin.py
new file mode 100644
index 000000000..9f726b1e2
--- /dev/null
+++ b/weight/admin.py
@@ -0,0 +1,20 @@
+# This file is part of Workout Manager.
+#
+# 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.
+#
+# 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 weight.models import WeightEntry
+
+from django.contrib import admin
+
+
+admin.site.register(WeightEntry)
diff --git a/weight/models.py b/weight/models.py
index 71a836239..6ca687498 100644
--- a/weight/models.py
+++ b/weight/models.py
@@ -1,3 +1,30 @@
+# This file is part of Workout Manager.
+#
+# 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.
+#
+# 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
+# along with Workout Manager. If not, see <http://www.gnu.org/licenses/>.
+
from django.db import models
-# Create your models here.
+from django.utils.translation import ugettext as _
+
+class WeightEntry(models.Model):
+ """Model for a weight point
+ """
+ creation_date = models.DateField(_('Creation date'))
+ weight = models.FloatField(_('Weight'))
+
+
+ def __unicode__(self):
+ """Return a more human-readable representation
+ """
+ return "%s: %s kg" % (self.creation_date, self.weight)
diff --git a/weight/templates/edit.html b/weight/templates/edit.html
new file mode 100644
index 000000000..233afa142
--- /dev/null
+++ b/weight/templates/edit.html
@@ -0,0 +1,45 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+<!--
+ Title
+-->
+{% block title %}{% trans "Exercise details" %}{% endblock %}
+
+
+<!--
+ Main Content
+-->
+{% block content %}
+
+<h2>{% if exercise.id %}
+ {% trans "Edit" %} {{ exercise.name }}
+ {% else %}
+ {% trans "New exercise" %}
+ {% endif %}
+</h2>
+
+
+<form action="/weight/add/{% if weight.id %}{{ weigth.id }}{% endif %}"
+ method="post"
+ class="ym-form">
+{% csrf_token %}
+{{ weight_form.non_field_errors }}
+<table>
+ {% include "form_snippet.html" with field=weight_form.weight %}
+ {% include "form_snippet.html" with field=weight_form.creation_date %}
+ <tr>
+ <td><input type="submit" value="{% trans "Save" %}" /></td>
+ <td></td>
+ </tr>
+</table>
+</form>
+
+
+{% endblock %}
+
+
+<!--
+ Side bar
+-->
+{% block sidebar %}{% endblock %}
\ No newline at end of file
diff --git a/weight/templates/overview.html b/weight/templates/overview.html
new file mode 100644
index 000000000..6ea67f012
--- /dev/null
+++ b/weight/templates/overview.html
@@ -0,0 +1,34 @@
+{% extends "base.html" %}
+{% load i18n %}
+
+<!--
+ Title
+-->
+{% block title %}{% trans "Exercise details" %}{% endblock %}
+
+
+<!--
+ Main Content
+-->
+{% block content %}
+
+<h2>{% if exercise.id %}
+ {% trans "Edit" %} {{ exercise.name }}
+ {% else %}
+ {% trans "New exercise" %}
+ {% endif %}
+</h2>
+
+
+{% for entry in weights %}
+{{ entry }}
+{% endfor %}
+
+
+{% endblock %}
+
+
+<!--
+ Side bar
+-->
+{% block sidebar %}{% endblock %}
\ No newline at end of file
diff --git a/weight/urls.py b/weight/urls.py
new file mode 100644
index 000000000..d6c99e885
--- /dev/null
+++ b/weight/urls.py
@@ -0,0 +1,7 @@
+from django.conf.urls import patterns, include, url
+
+urlpatterns = patterns('weight.views',
+ url(r'^weight/add/(?P<id>\d*)$', 'add'),
+ url(r'^weight/overview/$', 'overview'),
+
+)
diff --git a/weight/views.py b/weight/views.py
index 60f00ef0e..706e7b1d8 100644
--- a/weight/views.py
+++ b/weight/views.py
@@ -1 +1,67 @@
-# Create your views here.
+# This file is part of Workout Manager.
+#
+# 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.
+#
+# 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
+
+import datetime
+
+from django.shortcuts import render_to_response
+from django.shortcuts import get_object_or_404
+from django.http import HttpResponseRedirect
+from django.forms import ModelForm
+from django.core.context_processors import csrf
+
+from weight.models import WeightEntry
+
+class WeightForm(ModelForm):
+ class Meta:
+ model = WeightEntry
+
+def add(request, id=None):
+ """Add a weight entry
+ """
+
+ template_data = {}
+ template_data.update(csrf(request))
+
+ # Load weight
+ if id:
+ weight = get_object_or_404(WeightEntry, pk=id)
+ else:
+ weight = WeightEntry()
+ template_data['weight'] = weight
+
+ # Process request
+ if request.method == 'POST':
+ weight_form = WeightForm(request.POST, instance=weight)
+
+ # If the data is valid, save and redirect
+ if weight_form.is_valid():
+ weight = weight_form.save(commit=False)
+
+ weight.save()
+
+ return HttpResponseRedirect('/weight/overview/')
+ else:
+ weight_form = WeightForm()
+ template_data['weight_form'] = weight_form
+
+ return render_to_response('edit.html', template_data)
+
+def overview(request):
+ """Shows an overview of weight data
+ """
+ template_data = {}
+
+ template_data['weights'] = WeightEntry.objects.all()
+
+ return render_to_response('overview.html', template_data)
\ No newline at end of file
diff --git a/workout_manager/urls.py b/workout_manager/urls.py
index 30137a486..1f79a5d69 100644
--- a/workout_manager/urls.py
+++ b/workout_manager/urls.py
@@ -6,4 +6,5 @@ admin.autodiscover()
urlpatterns = patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^', include('manager.urls')),
+ url(r'^', include('weight.urls')),
)
\ No newline at end of file