Skip to content

Commit

Permalink
Test under django 1.6, fix some errors and remove deprecated functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandgeider committed Nov 10, 2013
1 parent a5a7075 commit 8bd0937
Show file tree
Hide file tree
Showing 26 changed files with 58 additions and 49 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Django==1.5.5
Django==1.6
django-browserid==0.9
django-recaptcha
reportlab
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
'versiontools >= 1.6',
],
install_requires=[
'django >= 1.5.5',
'django >= 1.6',
'reportlab',
'django-browserid == 0.9',
'django-recaptcha',
Expand Down
2 changes: 1 addition & 1 deletion wger/exercises/templates/mobile/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ <h3>{% trans "Search" %}</h3>

<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"
Expand Down
2 changes: 1 addition & 1 deletion wger/exercises/templates/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
{% 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"
Expand Down
2 changes: 1 addition & 1 deletion wger/exercises/views/exercises.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def dispatch(self, request, *args, **kwargs):
'''
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)
Expand Down
2 changes: 1 addition & 1 deletion wger/manager/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions wger/manager/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 4 additions & 2 deletions wger/manager/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions wger/manager/templates/mobile/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ <h3>{% trans "Exercises" %}</h3>
<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 %}

Expand Down Expand Up @@ -127,7 +127,7 @@ <h3>{% trans "Options" %}</h3>
<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" %}
Expand All @@ -151,7 +151,7 @@ <h3>{% trans "Options" %}</h3>
</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>
Expand All @@ -167,7 +167,7 @@ <h3>{% trans "Options" %}</h3>
{# #}
{# 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>
Expand Down
4 changes: 2 additions & 2 deletions wger/manager/templates/mobile/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -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."%}
Expand All @@ -75,7 +75,7 @@ <h1>wger</h1>
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"
Expand Down
4 changes: 2 additions & 2 deletions wger/manager/templates/navigation.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down Expand Up @@ -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">
Expand Down
4 changes: 2 additions & 2 deletions wger/manager/templates/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -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 %}
Expand Down
10 changes: 5 additions & 5 deletions wger/manager/tests/test_preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def preferences(self):

# 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)
Expand All @@ -53,7 +53,7 @@ def preferences(self):
#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]')
Expand All @@ -65,7 +65,7 @@ def preferences(self):

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, '')
Expand Down Expand Up @@ -99,7 +99,7 @@ def preferences(self):
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]')
Expand All @@ -114,7 +114,7 @@ def preferences(self):
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]')
Expand Down
2 changes: 1 addition & 1 deletion wger/manager/tests/test_temporary_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_demo_data(self):
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)
Expand Down
2 changes: 1 addition & 1 deletion wger/manager/views/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
4 changes: 2 additions & 2 deletions wger/manager/views/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -169,7 +169,7 @@ def get_form_class(self):
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
Expand Down
10 changes: 5 additions & 5 deletions wger/manager/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'))

Expand Down Expand Up @@ -115,15 +115,15 @@ 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
if form.is_valid():
form.save()
redirect = True
else:
form = UserPreferencesForm(instance=request.user.get_profile())
form = UserPreferencesForm(instance=request.user.userprofile)

# Process the email form
#
Expand Down Expand Up @@ -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()

Expand All @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion wger/nutrition/templates/ingredient/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h3>{% trans "Search" %}</h3>
</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' %}">
Expand Down
2 changes: 1 addition & 1 deletion wger/nutrition/templates/mobile/ingredient/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h3>{% trans "Search" %}</h3>
</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">
Expand Down
2 changes: 1 addition & 1 deletion wger/nutrition/views/ingredient.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def dispatch(self, request, *args, **kwargs):
'''
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)

Expand Down
13 changes: 6 additions & 7 deletions wger/settings_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down Expand Up @@ -53,12 +54,9 @@
# 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',
Expand Down Expand Up @@ -286,8 +284,9 @@
}
}

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
Expand Down
2 changes: 1 addition & 1 deletion wger/software/templates/contribute.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ <h3>{% trans "Submit exercises" %}</h3>
<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>
Expand Down
Loading

0 comments on commit 8bd0937

Please sign in to comment.