Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Test under django 1.6, fix some errors and remove deprecated functions

Roland Geider8bd09377e9af
diff --git a/.travis.yml b/.travis.yml
index fc5a85708..98b26df7a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -7,14 +7,18 @@ python:
# Manually define here the combinations of django and db versions to test
env:
-# - DJANGO_VERSION=1.4.9 DB=mysql
- - DJANGO_VERSION=1.4.9 DB=postgresql
- - DJANGO_VERSION=1.4.9 DB=sqlite
+# - DJANGO_VERSION=1.4.10 DB=mysql
+ - DJANGO_VERSION=1.4.10 DB=postgresql
+ - DJANGO_VERSION=1.4.10 DB=sqlite
# - DJANGO_VERSION=1.5.5 DB=mysql
- DJANGO_VERSION=1.5.5 DB=postgresql
- DJANGO_VERSION=1.5.5 DB=sqlite
+# - DJANGO_VERSION=1.6 DB=mysql
+ - DJANGO_VERSION=1.6 DB=postgresql
+ - DJANGO_VERSION=1.6 DB=sqlite
+
# Install the application
install:
- pip install -q Django==$DJANGO_VERSION --use-mirrors
diff --git a/requirements.txt b/requirements.txt
index 8a8e3be58..4e748fc8c 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,4 @@
-Django==1.5.5
+Django==1.6
django-browserid==0.9
django-recaptcha
reportlab
diff --git a/setup.py b/setup.py
index 4dee41948..0bd59a425 100644
--- a/setup.py
+++ b/setup.py
@@ -43,7 +43,7 @@ setup(
'versiontools >= 1.6',
],
install_requires=[
- 'django >= 1.5.5',
+ 'django >= 1.6',
'reportlab',
'django-browserid == 0.9',
'django-recaptcha',
diff --git a/wger/exercises/templates/mobile/overview.html b/wger/exercises/templates/mobile/overview.html
index ab75a32b2..56bb2dc69 100644
--- a/wger/exercises/templates/mobile/overview.html
+++ b/wger/exercises/templates/mobile/overview.html
@@ -67,7 +67,7 @@
<h3>{% trans "Add new exercise" %}</h3>
<p>
- {% if user.is_authenticated and not user.get_profile.is_temporary %}
+ {% if user.is_authenticated and not user.userprofile.is_temporary %}
<a href="{% url 'exercise-add' %}" data-role="button">
<img src="{% static 'images/icons/new.svg' %}"
width="32"
diff --git a/wger/exercises/templates/overview.html b/wger/exercises/templates/overview.html
index f6c1be134..6f2e41e09 100644
--- a/wger/exercises/templates/overview.html
+++ b/wger/exercises/templates/overview.html
@@ -111,7 +111,7 @@ $(document).ready(function() {
{% block sidebar %}
<h3>{% trans "Add new exercise" %}</h3>
<p>
- {% if user.is_authenticated and not user.get_profile.is_temporary %}
+ {% if user.is_authenticated and not user.userprofile.is_temporary %}
<a href="{% url 'exercise-add' %}">
<img src="{% static 'images/icons/new.svg' %}"
width="32"
diff --git a/wger/exercises/views/exercises.py b/wger/exercises/views/exercises.py
index 164ade9e4..5a9b9de5c 100644
--- a/wger/exercises/views/exercises.py
+++ b/wger/exercises/views/exercises.py
@@ -242,7 +242,7 @@ class ExerciseAddView(ExercisesEditAddView, CreateView, WgerPermissionMixin):
'''
Demo users can't submit exercises
'''
- if request.user.get_profile().is_temporary:
+ if request.user.userprofile.is_temporary:
return HttpResponseForbidden()
return super(ExerciseAddView, self).dispatch(request, *args, **kwargs)
diff --git a/wger/manager/demo.py b/wger/manager/demo.py
index 82a04fe45..f8a644aa5 100644
--- a/wger/manager/demo.py
+++ b/wger/manager/demo.py
@@ -54,7 +54,7 @@ def create_temporary_user():
user = User.objects.create_user(username, email, password)
user.save()
- user_profile = user.get_profile()
+ user_profile = user.userprofile
user_profile.is_temporary = True
user_profile.age = 25
user_profile.height = 175
diff --git a/wger/manager/forms.py b/wger/manager/forms.py
index df2278f74..352300157 100644
--- a/wger/manager/forms.py
+++ b/wger/manager/forms.py
@@ -58,6 +58,10 @@ class UserEmailForm(ModelForm):
help_text=_("Only needed to reset your password in case you forget it."),
required=False)
+ class Meta:
+ model = Django_User
+ fields = ('email', )
+
def clean_email(self):
# Email must be unique systemwide
email = self.cleaned_data["email"]
diff --git a/wger/manager/models.py b/wger/manager/models.py
index 06b5c3df9..f43965ae0 100644
--- a/wger/manager/models.py
+++ b/wger/manager/models.py
@@ -573,7 +573,8 @@ class UserProfile(models.Model):
# Show exercise comments on workout view
show_comments = models.BooleanField(verbose_name=_('Show exercise comments'),
help_text=_('Check to show exercise comments on the '
- 'workout view'))
+ 'workout view'),
+ default=True)
# Also show ingredients in english while composing a nutritional plan
# (obviously this is only meaningful if the user has a language other than english)
@@ -582,7 +583,8 @@ class UserProfile(models.Model):
help_text=_('''Check to also show ingredients in English while creating
a nutritional plan. These ingredients are extracted from a list provided
by the US Department of Agriculture. It is extremely complete, with around
-7000 entries, but can be somewhat overwhelming and make the search difficult.'''))
+7000 entries, but can be somewhat overwhelming and make the search difficult.'''),
+ default=True)
#
# User statistics
diff --git a/wger/manager/templates/mobile/navigation.html b/wger/manager/templates/mobile/navigation.html
index d4851a459..e45ca7694 100644
--- a/wger/manager/templates/mobile/navigation.html
+++ b/wger/manager/templates/mobile/navigation.html
@@ -55,7 +55,7 @@
<ul data-role="listview" data-divider-theme="a">
<li><a href="{% url 'wger.exercises.views.exercises.overview' %}">{% trans "Exercises" %}</a></li>
<li><a href="{% url 'muscle-overview' %}" data-ajax="false">{% trans "Muscle overview" %}</a></li>
- {% if user.is_authenticated and not user.get_profile.is_temporary %}
+ {% if user.is_authenticated and not user.userprofile.is_temporary %}
<li><a href="{% url 'exercise-add' %}" data-ajax="false">{% trans "Add new exercise" %}</a></li>
{% endif %}
@@ -127,7 +127,7 @@
<ul data-role="listview">
{# Preferences #}
- {% if user.is_authenticated and not user.get_profile.is_temporary %}
+ {% if user.is_authenticated and not user.userprofile.is_temporary %}
<li>
<a href="{% url 'wger.manager.views.user.preferences' %}">
{% trans "Preferences" %}
@@ -151,7 +151,7 @@
</li>
{# Logout #}
- {% if user.is_authenticated and not user.get_profile.is_temporary %}
+ {% if user.is_authenticated and not user.userprofile.is_temporary %}
<li>
<a href="{% url 'logout' %}" data-ajax="false" class="browserid-logout">{% trans "Logout" %}</a>
</li>
@@ -167,7 +167,7 @@
{# #}
{# Login tab #}
{# #}
-{% if not user.is_authenticated or user.get_profile.is_temporary %}
+{% if not user.is_authenticated or user.userprofile.is_temporary %}
<!--
<h4 style="margin-bottom:0px;">{% trans "Options" %}</h4>
diff --git a/wger/manager/templates/mobile/template.html b/wger/manager/templates/mobile/template.html
index 3010fdde0..b43f1225c 100644
--- a/wger/manager/templates/mobile/template.html
+++ b/wger/manager/templates/mobile/template.html
@@ -52,7 +52,7 @@
<div data-role="page" id="page-{{request_full_path|slugify}}" data-url="{{request_full_path}}">
{% block scripts %}{% endblock %}
- {% if not user.is_authenticated or user.get_profile.is_temporary %}
+ {% if not user.is_authenticated or user.userprofile.is_temporary %}
<div data-role="popup" data-overlay-theme="a" id="popupGuestUser" class="ui-content">
<h3>{% trans "Info" %}</h3>
{% trans "You are using a guest account, data entered will be deleted after a week."%}
@@ -75,7 +75,7 @@
data-theme="a"
data-icon="bars"
data-iconshadow="false">{% trans "Menu" %}</a>
- {% if not user.is_authenticated or user.get_profile.is_temporary %}
+ {% if not user.is_authenticated or user.userprofile.is_temporary %}
<a href="#popupGuestUser"
class="ui-icon-nodisc"
data-rel="popup"
diff --git a/wger/manager/templates/navigation.html b/wger/manager/templates/navigation.html
index 93aef1eb1..8eaa58b29 100644
--- a/wger/manager/templates/navigation.html
+++ b/wger/manager/templates/navigation.html
@@ -42,7 +42,7 @@
<ul class="dropdown-menu">
<li><a href="{% url 'wger.exercises.views.exercises.overview' %}">{% trans "Exercises" %}</a></li>
<li><a href="{% url 'muscle-overview' %}">{% trans "Muscle overview" %}</a></li>
- {% if user.is_authenticated and not user.get_profile.is_temporary %}
+ {% if user.is_authenticated and not user.userprofile.is_temporary %}
<li><a href="{% url 'exercise-add' %}">{% trans "Add new exercise" %}</a><li>
{% endif %}
@@ -133,7 +133,7 @@
{# #}
{# Options tab #}
{# #}
- {% if not user.is_authenticated or user.get_profile.is_temporary %}
+ {% if not user.is_authenticated or user.userprofile.is_temporary %}
<ul class="nav pull-right">
<li class="divider-vertical"></li>
<li class="dropdown">
diff --git a/wger/manager/templates/template.html b/wger/manager/templates/template.html
index 1c06daa86..7664d6341 100644
--- a/wger/manager/templates/template.html
+++ b/wger/manager/templates/template.html
@@ -72,7 +72,7 @@
<header>
<div class="float-right" style="margin-right:1em;margin-top:0em;">
- {% if user.is_authenticated and not user.get_profile.is_temporary %}
+ {% if user.is_authenticated and not user.userprofile.is_temporary %}
<a href="{% url 'wger.manager.views.user.preferences' %}">
{% if user.email %}
{{user.email}}
@@ -124,7 +124,7 @@
<div id="current-url" data-current-url="{{request_full_path}}"></div>
<div id="current-language" data-current-language="{{language.short_name}}"></div>
- {% if not user.is_authenticated or user.get_profile.is_temporary %}
+ {% if not user.is_authenticated or user.userprofile.is_temporary %}
<div class="abox ainfo" style="padding:0.6em; margin: 0em 0em 1em 0em;text-align:center;font-size:95%;">
{% trans "You are using a guest account, data entered will be deleted after a week."%}
{% if not has_demo_data %}
diff --git a/wger/manager/tests/test_preferences.py b/wger/manager/tests/test_preferences.py
index 2d4914239..e7edd7ce6 100644
--- a/wger/manager/tests/test_preferences.py
+++ b/wger/manager/tests/test_preferences.py
@@ -38,7 +38,7 @@ class PreferencesTestCase(WorkoutManagerTestCase):
# Fetch the preferences page
response = self.client.get(reverse('preferences'))
- profile = response.context['user'].get_profile()
+ profile = response.context['user'].userprofile
self.assertFalse(profile.show_comments)
self.assertEqual(response.status_code, 200)
@@ -53,7 +53,7 @@ class PreferencesTestCase(WorkoutManagerTestCase):
#print response
self.assertEqual(response.status_code, 302)
response = self.client.get(reverse('preferences'))
- profile = response.context['user'].get_profile()
+ profile = response.context['user'].userprofile
#self.assertTrue(profile.show_comments)
self.assertTrue(profile.show_english_ingredients)
self.assertEqual(response.context['user'].email, '[email protected]')
@@ -65,7 +65,7 @@ class PreferencesTestCase(WorkoutManagerTestCase):
self.assertEqual(response.status_code, 302)
response = self.client.get(reverse('preferences'))
- profile = response.context['user'].get_profile()
+ profile = response.context['user'].userprofile
self.assertFalse(profile.show_comments)
self.assertTrue(profile.show_english_ingredients)
self.assertEqual(response.context['user'].email, '')
@@ -99,7 +99,7 @@ class AjaxPreferencesTestCase(WorkoutManagerTestCase):
self.assertEqual(response.status_code, 200)
response = self.client.get(reverse('preferences'))
- profile = response.context['user'].get_profile()
+ profile = response.context['user'].userprofile
self.assertTrue(profile.show_comments)
self.assertFalse(profile.show_english_ingredients)
self.assertEqual(response.context['user'].email, '[email protected]')
@@ -114,7 +114,7 @@ class AjaxPreferencesTestCase(WorkoutManagerTestCase):
self.assertEqual(response.status_code, 200)
response = self.client.get(reverse('preferences'))
- profile = response.context['user'].get_profile()
+ profile = response.context['user'].userprofile
self.assertTrue(profile.show_comments)
self.assertTrue(profile.show_english_ingredients)
self.assertEqual(response.context['user'].email, '[email protected]')
diff --git a/wger/manager/tests/test_temporary_users.py b/wger/manager/tests/test_temporary_users.py
index af8323613..e7016d28d 100644
--- a/wger/manager/tests/test_temporary_users.py
+++ b/wger/manager/tests/test_temporary_users.py
@@ -53,7 +53,7 @@ class DemoUserTestCase(WorkoutManagerTestCase):
self.client.get(reverse('dashboard'))
self.assertEqual(self.count_temp_users(), 2)
user = User.objects.get(pk=4)
- self.assertEqual(user.get_profile().is_temporary, True)
+ self.assertEqual(user.userprofile.is_temporary, True)
self.assertEqual(Workout.objects.filter(user=user).count(), 0)
create_demo_entries(user)
diff --git a/wger/manager/views/log.py b/wger/manager/views/log.py
index f0e92542b..e435b0d32 100644
--- a/wger/manager/views/log.py
+++ b/wger/manager/views/log.py
@@ -114,7 +114,7 @@ def add(request, pk):
# Define the formset here because now we know the value to pass to 'extra'
WorkoutLogFormSet = modelformset_factory(WorkoutLog,
form=WorkoutLogForm,
- exclude=('date'),
+ exclude=('date',),
extra = total_sets)
# Process the request
if request.method == 'POST':
diff --git a/wger/manager/views/misc.py b/wger/manager/views/misc.py
index 88e8175aa..00cac3436 100644
--- a/wger/manager/views/misc.py
+++ b/wger/manager/views/misc.py
@@ -62,7 +62,7 @@ def demo_entries(request):
'''
Creates a set of sample entries for guest users
'''
- if (((not request.user.is_authenticated() or request.user.get_profile().is_temporary)
+ if (((not request.user.is_authenticated() or request.user.userprofile.is_temporary)
and not request.session['has_demo_data'])):
# If we reach this from a page that has no user created by the
# middleware, do that now
@@ -169,7 +169,7 @@ class FeedbackClass(FormView):
Load the correct feedback form depending on the user
(either with reCaptcha field or not)
'''
- if self.request.user.get_profile().is_temporary:
+ if self.request.user.userprofile.is_temporary:
return forms.FeedbackAnonymousForm
else:
return forms.FeedbackRegisteredForm
diff --git a/wger/manager/views/user.py b/wger/manager/views/user.py
index 40e793501..6e5e95f4f 100644
--- a/wger/manager/views/user.py
+++ b/wger/manager/views/user.py
@@ -56,7 +56,7 @@ def logout(request):
'''
user = request.user
django_logout(request)
- if user.is_authenticated() and user.get_profile().is_temporary:
+ if user.is_authenticated() and user.userprofile.is_temporary:
user.delete()
return HttpResponseRedirect(reverse('login'))
@@ -115,7 +115,7 @@ def preferences(request):
# Process the preferences form
if request.method == 'POST':
- form = UserPreferencesForm(data=request.POST, instance=request.user.get_profile())
+ form = UserPreferencesForm(data=request.POST, instance=request.user.userprofile)
form.user = request.user
# Save the data if it validates
@@ -123,7 +123,7 @@ def preferences(request):
form.save()
redirect = True
else:
- form = UserPreferencesForm(instance=request.user.get_profile())
+ form = UserPreferencesForm(instance=request.user.userprofile)
# Process the email form
#
@@ -165,7 +165,7 @@ def api_user_preferences(request):
if request.GET.get('do') == 'set_show-comments':
new_value = int(request.GET.get('show'))
- profile = request.user.get_profile()
+ profile = request.user.userprofile
profile.show_comments = new_value
profile.save()
@@ -175,7 +175,7 @@ def api_user_preferences(request):
elif request.GET.get('do') == 'set_english-ingredients':
new_value = int(request.GET.get('show'))
- profile = request.user.get_profile()
+ profile = request.user.userprofile
profile.show_english_ingredients = new_value
profile.save()
diff --git a/wger/nutrition/templates/ingredient/overview.html b/wger/nutrition/templates/ingredient/overview.html
index ebee71876..9d9fdbfb2 100644
--- a/wger/nutrition/templates/ingredient/overview.html
+++ b/wger/nutrition/templates/ingredient/overview.html
@@ -69,7 +69,7 @@ $(document).ready(function() {
</form>
</div>
-{% if user.is_authenticated and not user.get_profile.is_temporary %}
+{% if user.is_authenticated and not user.userprofile.is_temporary %}
<h3>{% trans "Add ingredient" %}</h3>
<p>
<a href="{% url 'ingredient-add' %}">
diff --git a/wger/nutrition/templates/mobile/ingredient/overview.html b/wger/nutrition/templates/mobile/ingredient/overview.html
index d57b44289..e204e8410 100644
--- a/wger/nutrition/templates/mobile/ingredient/overview.html
+++ b/wger/nutrition/templates/mobile/ingredient/overview.html
@@ -69,7 +69,7 @@ $(document).ready(function() {
</form>
</div>
-{% if user.is_authenticated and not user.get_profile.is_temporary %}
+{% if user.is_authenticated and not user.userprofile.is_temporary %}
<h3>{% trans "Add ingredient" %}</h3>
<p>
<a href="{% url 'ingredient-add' %}" data-role="button">
diff --git a/wger/nutrition/views/ingredient.py b/wger/nutrition/views/ingredient.py
index 273c88cc4..56bd87e28 100644
--- a/wger/nutrition/views/ingredient.py
+++ b/wger/nutrition/views/ingredient.py
@@ -161,7 +161,7 @@ class IngredientCreateView(WgerFormMixin, CreateView):
'''
Demo users can't submit ingredients
'''
- if request.user.get_profile().is_temporary:
+ if request.user.userprofile.is_temporary:
return HttpResponseForbidden()
return super(IngredientCreateView, self).dispatch(request, *args, **kwargs)
diff --git a/wger/settings_global.py b/wger/settings_global.py
index dd4eba517..30f9e33b0 100644
--- a/wger/settings_global.py
+++ b/wger/settings_global.py
@@ -15,12 +15,13 @@
# You should have received a copy of the GNU Affero General Public License
import os
+import django
from wger.main import fs2unicode
'''
This file contains the global settings that don't need to be changed by the user
For a full list of options, visit:
- https://docs.djangoproject.com/en/1.4/ref/settings/#std:setting-LANGUAGES
+ https://docs.djangoproject.com/en/dev/ref/settings/
'''
SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
@@ -53,12 +54,9 @@ EMAIL_SUBJECT_PREFIX = '[wger] '
# Login-URL
LOGIN_URL = '/user/login'
-# Redirect here after sucessfull login
+# Redirect here after successful login
LOGIN_REDIRECT_URL = '/'
-# Model for the user profile
-AUTH_PROFILE_MODULE = 'manager.UserProfile'
-
# Set the context processors
TEMPLATE_CONTEXT_PROCESSORS = (
'wger.utils.context_processor.processor',
@@ -286,8 +284,9 @@ LOGGING = {
}
}
-TEST_RUNNER = 'discover_runner.DiscoverRunner'
-TEST_DISCOVER_TOP_LEVEL = os.path.dirname(os.path.dirname(__file__))
+if django.VERSION[:2] < (1, 6):
+ TEST_RUNNER = 'discover_runner.DiscoverRunner'
+ TEST_DISCOVER_TOP_LEVEL = os.path.dirname(os.path.dirname(__file__))
# Force SSL to communicate with reCaptcha's servers
RECAPTCHA_USE_SSL = True
diff --git a/wger/software/templates/contribute.html b/wger/software/templates/contribute.html
index bd1ead1c6..19d9174ad 100644
--- a/wger/software/templates/contribute.html
+++ b/wger/software/templates/contribute.html
@@ -71,7 +71,7 @@ like much, but is incredibly important!{% endblocktrans %}</p>
<p>{% blocktrans %}Submit those cool exercises that you absolutely
love and do every week but are not in the list yet. If you think some description
is too short or some other detail is missing or could be improved, tell!{% endblocktrans %}</p>
- {% if user.is_authenticated and not user.get_profile.is_temporary %}
+ {% if user.is_authenticated and not user.userprofile.is_temporary %}
<a class="btn " href="{% url 'exercise-add' %}">{% trans "Add exercise" %} »</a>
{% else %}
<a class="btn disabled" href="#">{% trans "Only registered users can do this" %} »</a>
diff --git a/wger/software/templates/mobile/contribute.html b/wger/software/templates/mobile/contribute.html
index 63552d6ae..26f62bf44 100644
--- a/wger/software/templates/mobile/contribute.html
+++ b/wger/software/templates/mobile/contribute.html
@@ -59,7 +59,7 @@ like much, but is incredibly important!{% endblocktrans %}</p>
<p>{% blocktrans %}Submit those cool exercises that you absolutely
love and do every week but are not in the list yet. If you think some description
is too short or some other detail is missing or could be improved, tell!{% endblocktrans %}</p>
- {% if user.is_authenticated and not user.get_profile.is_temporary %}
+ {% if user.is_authenticated and not user.userprofile.is_temporary %}
<a data-role="button" href="{% url 'exercise-add' %}">{% trans "Add exercise" %} »</a>
{% else %}
<a data-role="button" class="ui-disabled" href="#">{% trans "Only registered users can do this" %} »</a>
diff --git a/wger/utils/language.py b/wger/utils/language.py
index 21581d990..5260d17dc 100644
--- a/wger/utils/language.py
+++ b/wger/utils/language.py
@@ -99,7 +99,7 @@ def load_ingredient_languages(request):
# Only registered users have a profile
if request.user.is_authenticated():
- profile = request.user.get_profile()
+ profile = request.user.userprofile
show_english = profile.show_english_ingredients
# If the user's language is not english and has the preference, add english to the list
diff --git a/wger/utils/pdf.py b/wger/utils/pdf.py
index ac90fb64d..b4ea8f14a 100644
--- a/wger/utils/pdf.py
+++ b/wger/utils/pdf.py
@@ -66,7 +66,7 @@ def load_ingredient_languages(request):
# Only registered users have a profile
if request.user.is_authenticated():
- profile = request.user.get_profile()
+ profile = request.user.userprofile
show_english = profile.show_english_ingredients
# If the user's language is not english and has the preference, add english to the list