Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Use nested namespaces for weight URLs

Roland Geider32c214f47bab
diff --git a/wger/core/templates/mobile/index.html b/wger/core/templates/mobile/index.html
index 09268ecba..81a0c01ce 100644
--- a/wger/core/templates/mobile/index.html
+++ b/wger/core/templates/mobile/index.html
@@ -219,7 +219,7 @@ its default duration in your settings.{% endblocktrans %}
{% endif %}
</div>
<div class="col-xs-6" style="padding-left: 7px;">
- <a href="{% url 'weight-overview' %}" class="btn btn-default btn-block">
+ <a href="{% url 'weight:overview' %}" class="btn btn-default btn-block">
<img src="{% static 'images/icons/statistics.svg' %}"
width="32"
height="32"
diff --git a/wger/core/templates/mobile/navigation.html b/wger/core/templates/mobile/navigation.html
index ec7c7dda4..557cf9d0b 100644
--- a/wger/core/templates/mobile/navigation.html
+++ b/wger/core/templates/mobile/navigation.html
@@ -74,7 +74,7 @@
{# #}
<li class="dropdown">
- <a href="{% url 'weight-overview' %}"
+ <a href="{% url 'weight:overview' %}"
class="dropdown-toggle"
data-toggle="dropdown"
rel="nofollow">
@@ -83,8 +83,8 @@
{% if active_tab == 'weight' %}</strong>{% endif %}
</a>
<ul class="dropdown-menu">
- <li><a href="{% url 'weight-overview' %}" rel="nofollow">{% trans "Weight overview" %}</a></li>
- <li><a href="{% url 'weight-add' %}" rel="nofollow">{% trans "Add weight entry" %}</a></li>
+ <li><a href="{% url 'weight:overview' %}" rel="nofollow">{% trans "Weight overview" %}</a></li>
+ <li><a href="{% url 'weight:add' %}" rel="nofollow">{% trans "Add weight entry" %}</a></li>
</ul>
</li>
diff --git a/wger/core/templates/navigation.html b/wger/core/templates/navigation.html
index ff4e1825e..b9a955345 100644
--- a/wger/core/templates/navigation.html
+++ b/wger/core/templates/navigation.html
@@ -67,13 +67,13 @@
{# #}
<li class="dropdown{% if active_tab == 'weight' %} active{% endif %}">
- <a href="{% url 'weight-overview' %}"
+ <a href="{% url 'weight:overview' %}"
class="dropdown-toggle"
data-toggle="dropdown"
rel="nofollow">{% trans "Weight" %} <b class="caret"></b></a>
<ul class="dropdown-menu">
- <li><a href="{% url 'weight-overview' %}" rel="nofollow">{% trans "Weight overview" %}</a></li>
- <li><a href="{% url 'weight-add' %}" rel="nofollow">{% trans "Add weight entry" %}</a></li>
+ <li><a href="{% url 'weight:overview' %}" rel="nofollow">{% trans "Weight overview" %}</a></li>
+ <li><a href="{% url 'weight:add' %}" rel="nofollow">{% trans "Add weight entry" %}</a></li>
</ul>
</li>
diff --git a/wger/core/templates/user/overview.html b/wger/core/templates/user/overview.html
index bd7d11ec9..891864acf 100644
--- a/wger/core/templates/user/overview.html
+++ b/wger/core/templates/user/overview.html
@@ -126,7 +126,7 @@
</tbody>
</table>
{% if perms.gym.gym_trainer %}
-<a href="{{trainer_login}}?next={% url 'weight-overview' %}" class="btn btn-default btn-sm">{% trans "Weight overview" %}</a>
+<a href="{{trainer_login}}?next={% url 'weight:overview' %}" class="btn btn-default btn-sm">{% trans "Weight overview" %}</a>
{% endif %}
diff --git a/wger/core/tests/test_index.py b/wger/core/tests/test_index.py
index 9ff179070..38109c2a2 100644
--- a/wger/core/tests/test_index.py
+++ b/wger/core/tests/test_index.py
@@ -77,7 +77,7 @@ class DashboardTestCase(WorkoutManagerTestCase):
#
# 3. Add a weight entry
#
- self.client.post(reverse('weight-add'),
+ self.client.post(reverse('weight:add'),
{'weight': 100,
'creation_date': '2012-01-01',
'user': 1},)
diff --git a/wger/core/tests/test_temporary_users.py b/wger/core/tests/test_temporary_users.py
index 4ca190552..d28d4d212 100644
--- a/wger/core/tests/test_temporary_users.py
+++ b/wger/core/tests/test_temporary_users.py
@@ -130,7 +130,7 @@ class DemoUserTestCase(WorkoutManagerTestCase):
self.assertEqual(self.count_temp_users(), 3)
self.user_logout()
- self.client.get(reverse('weight-overview'))
+ self.client.get(reverse('weight:overview'))
self.assertEqual(self.count_temp_users(), 4)
self.user_logout()
diff --git a/wger/urls.py b/wger/urls.py
index cd7b2fdcf..dde39198d 100644
--- a/wger/urls.py
+++ b/wger/urls.py
@@ -134,7 +134,7 @@ urlpatterns = i18n_patterns('',
url(r'^', include('wger.core.urls', namespace='core', app_name='core')),
url(r'workout/', include('wger.manager.urls', namespace='manager')),
url(r'exercise/', include('wger.exercises.urls', namespace='exercise')),
- url(r'weight/', include('wger.weight.urls')),
+ url(r'weight/', include('wger.weight.urls', namespace='weight')),
url(r'nutrition/', include('wger.nutrition.urls', namespace='nutrition')),
url(r'software/', include('wger.software.urls', namespace='software', app_name='software')),
url(r'config/', include('wger.config.urls', namespace='config', app_name='config')),
diff --git a/wger/weight/templates/weight_overview.html b/wger/weight/templates/weight_overview.html
index 2fe0c2c49..90cd38da6 100644
--- a/wger/weight/templates/weight_overview.html
+++ b/wger/weight/templates/weight_overview.html
@@ -38,7 +38,7 @@ $(document).ready(function () {
<div id="weight_diagram"></div>
<p>
-<a href="{% url 'weight-add' %}"
+<a href="{% url 'weight:add' %}"
{% auto_link_css flavour "wger-modal-dialog" %}
id="add-weight-entry">{% trans "Add weight entry" %}</a>
</p>
@@ -63,7 +63,7 @@ on the background resets it.
<h3>{% trans "Options" %}</h3>
<p>
- <a href="{% url 'wger.weight.views.export_csv' %}"
+ <a href="{% url 'weight:export-csv' %}"
target="_blank"
{% auto_link_css flavour %}>
<img src="{% static 'images/icons/save.svg' %}"
@@ -76,7 +76,7 @@ on the background resets it.
</p>
<p>
- <a href="{% url 'weight-import-csv' %}" {% auto_link_css flavour %}>
+ <a href="{% url 'weight:import-csv' %}" {% auto_link_css flavour %}>
<img src="{% static 'images/icons/csv-table.svg' %}"
width="32"
height="32"
diff --git a/wger/weight/tests/test_csv_export.py b/wger/weight/tests/test_csv_export.py
index be7969c6c..8cb9c5e2b 100644
--- a/wger/weight/tests/test_csv_export.py
+++ b/wger/weight/tests/test_csv_export.py
@@ -30,7 +30,7 @@ class WeightCsvExportTestCase(WorkoutManagerTestCase):
'''
Helper function to test the CSV export
'''
- response = self.client.get(reverse('wger.weight.views.export_csv'))
+ response = self.client.get(reverse('weight:export-csv'))
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-Type'], 'text/csv')
diff --git a/wger/weight/tests/test_csv_import.py b/wger/weight/tests/test_csv_import.py
index 9d4404fb9..a1c2f41b4 100644
--- a/wger/weight/tests/test_csv_import.py
+++ b/wger/weight/tests/test_csv_import.py
@@ -31,7 +31,7 @@ class WeightCsvImportTestCase(WorkoutManagerTestCase):
'''
Helper function to test the CSV import
'''
- response = self.client.get(reverse('weight-import-csv'))
+ response = self.client.get(reverse('weight:import-csv'))
self.assertEqual(response.status_code, 200)
# Do a direct post request
@@ -46,7 +46,7 @@ class WeightCsvImportTestCase(WorkoutManagerTestCase):
19.02.10 71 222
26.02.10 71,9 222
19.03.10 72 222'''
- response = self.client.post(reverse('weight-import-csv'),
+ response = self.client.post(reverse('weight:import-csv'),
{'stage': 1,
'csv_input': csv_input,
'date_format': '%d.%m.%y'})
@@ -57,7 +57,7 @@ class WeightCsvImportTestCase(WorkoutManagerTestCase):
hash_value = response.context['hash_value']
# 2nd. step
- response = self.client.post(reverse('weight-import-csv'),
+ response = self.client.post(reverse('weight:import-csv'),
{'stage': 2,
'hash': hash_value,
'csv_input': csv_input,
diff --git a/wger/weight/tests/test_entry.py b/wger/weight/tests/test_entry.py
index 85c50c3d1..77478d5b9 100644
--- a/wger/weight/tests/test_entry.py
+++ b/wger/weight/tests/test_entry.py
@@ -30,7 +30,7 @@ class AddWeightEntryTestCase(WorkoutManagerAddTestCase):
'''
object_class = WeightEntry
- url = 'weight-add'
+ url = 'weight:add'
user_fail = False
data = {'weight': decimal.Decimal(81.1).quantize(TWOPLACES),
'creation_date': datetime.date(2013, 2, 1),
@@ -43,7 +43,7 @@ class EditWeightEntryTestCase(WorkoutManagerEditTestCase):
'''
object_class = WeightEntry
- url = 'weight-edit'
+ url = 'weight:edit'
pk = 1
data = {'weight': 100,
'creation_date': datetime.date(2013, 2, 1),
diff --git a/wger/weight/tests/test_overview.py b/wger/weight/tests/test_overview.py
index 6afacf790..e86041392 100644
--- a/wger/weight/tests/test_overview.py
+++ b/wger/weight/tests/test_overview.py
@@ -30,7 +30,7 @@ class WeightOverviewTestCase(WorkoutManagerTestCase):
'''
Helper function to test the weight overview page
'''
- response = self.client.get(reverse('weight-overview'))
+ response = self.client.get(reverse('weight:overview'))
self.assertEqual(response.status_code, 200)
def test_weight_overview_loged_in(self):
@@ -50,7 +50,7 @@ class WeightExportCsvTestCase(WorkoutManagerTestCase):
'''
Helper function to test exporting the saved weight entries as a CSV file
'''
- response = self.client.get(reverse('wger.weight.views.export_csv'))
+ response = self.client.get(reverse('weight:export-csv'))
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-Type'], 'text/csv')
diff --git a/wger/weight/urls.py b/wger/weight/urls.py
index 37c4805a7..3449f80f6 100644
--- a/wger/weight/urls.py
+++ b/wger/weight/urls.py
@@ -19,26 +19,29 @@ 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 import views
-urlpatterns = patterns('wger.weight.views',
+
+urlpatterns = patterns('',
url(r'^add/$',
- login_required(WeightAddView.as_view()),
- name='weight-add'),
+ login_required(views.WeightAddView.as_view()),
+ name='add'),
url(r'^(?P<pk>\d+)/edit/$',
- login_required(WeightUpdateView.as_view()),
- name='weight-edit'),
+ login_required(views.WeightUpdateView.as_view()),
+ name='edit'),
- url(r'^export-csv/$', 'export_csv'),
+ url(r'^export-csv/$',
+ views.export_csv,
+ name='export-csv'),
url(r'^import-csv/$',
- login_required(WeightCsvImportFormPreview(WeightCsvImportForm)),
- name='weight-import-csv'),
+ login_required(views.WeightCsvImportFormPreview(WeightCsvImportForm)),
+ name='import-csv'),
url(r'^overview/$',
- 'overview',
- name='weight-overview'),
- url(r'^api/get_weight_data/$', 'get_weight_data'),
+ views.overview,
+ name='overview'),
+ url(r'^api/get_weight_data/$', # JS
+ views.get_weight_data,
+ name='weight-data'),
)
diff --git a/wger/weight/views.py b/wger/weight/views.py
index d8e28ede7..2b96dc4ce 100644
--- a/wger/weight/views.py
+++ b/wger/weight/views.py
@@ -51,8 +51,8 @@ class WeightAddView(WgerFormMixin, CreateView):
model = WeightEntry
form_class = WeightForm
title = ugettext_lazy('Add weight entry')
- form_action = reverse_lazy('weight-add')
- success_url = reverse_lazy('weight-overview')
+ form_action = reverse_lazy('weight:add')
+ success_url = reverse_lazy('weight:overview')
def get_initial(self):
'''
@@ -78,11 +78,11 @@ class WeightUpdateView(WgerFormMixin, UpdateView):
'''
model = WeightEntry
form_class = WeightForm
- success_url = reverse_lazy('weight-overview')
+ success_url = reverse_lazy('weight:overview')
def get_context_data(self, **kwargs):
context = super(WeightUpdateView, self).get_context_data(**kwargs)
- context['form_action'] = reverse('weight-edit', kwargs={'pk': self.object.id})
+ context['form_action'] = reverse('weight:edit', kwargs={'pk': self.object.id})
context['title'] = _('Edit weight entry for the %s') % self.object.creation_date
return context
@@ -182,7 +182,7 @@ class WeightCsvImportFormPreview(FormPreview):
return {'form': form,
'stage_field': self.unused_name('stage'),
'state': self.state,
- 'form_action': reverse('weight-import-csv')}
+ 'form_action': reverse('weight:import-csv')}
def process_preview(self, request, form, context):
context['weight_list'], context['error_list'] = helpers.parse_weight_csv(request,
@@ -192,4 +192,4 @@ class WeightCsvImportFormPreview(FormPreview):
def done(self, request, cleaned_data):
weight_list, error_list = helpers.parse_weight_csv(request, cleaned_data)
WeightEntry.objects.bulk_create(weight_list)
- return HttpResponseRedirect(reverse('weight-overview'))
+ return HttpResponseRedirect(reverse('weight:overview'))