Self hosted FLOSS fitness/workout, nutrition and weight tracker
New property to get the user's address
Roland Geidera671381aa089
diff --git a/wger/core/models.py b/wger/core/models.pyindex b762678bb..afbc45de6 100644--- a/wger/core/models.py+++ b/wger/core/models.py@@ -325,6 +325,24 @@ by the US Department of Agriculture. It is extremely complete, with aroundweight = 0return weight+ @property+ def address(self):+ '''+ Return the address as saved in the current contract (user's gym)+ '''+ out = {'zip_code': '',+ 'city': '',+ 'street': '',+ 'phone': ''}+ if self.user.contract_member.exists():+ last_contract = self.user.contract_member.last()+ out['zip_code'] = last_contract.zip_code+ out['city'] = last_contract.city+ out['street'] = last_contract.street+ out['phone'] = last_contract.phone++ return out+def clean(self):'''Make sure the total amount of hours is 24diff --git a/wger/core/tests/test_preferences.py b/wger/core/tests/test_preferences.pyindex 89fc9047b..b7eeffc34 100644--- a/wger/core/tests/test_preferences.py+++ b/wger/core/tests/test_preferences.py@@ -89,6 +89,27 @@ class PreferencesTestCase(WorkoutManagerTestCase):self.assertTrue(profile.show_english_ingredients)self.assertEqual(response.context['user'].email, '')+ def test_address(self):+ '''+ Test that the address property works correctly+ '''++ # Member2 has a contract+ user = User.objects.get(username='member2')+ self.assertEqual(user.userprofile.address,+ {'phone': '01234-567890',+ 'zip_code': '00000',+ 'street': 'Gassenstr. 14',+ 'city': 'The City'})++ # Test has no contracts+ user = User.objects.get(username='test')+ self.assertEqual(user.userprofile.address,+ {'phone': '',+ 'zip_code': '',+ 'street': '',+ 'city': ''})+class UserBodyweightTestCase(WorkoutManagerTestCase):'''diff --git a/wger/gym/views/export.py b/wger/gym/views/export.pyindex dcdf4a697..d549ee678 100644--- a/wger/gym/views/export.py+++ b/wger/gym/views/export.py@@ -49,16 +49,32 @@ def users(request, gym_pk):response = HttpResponse(content_type='text/csv')writer = csv.writer(response, delimiter='\t', quoting=csv.QUOTE_ALL)writer.writerow([_('Nr.'),+ _('Gym'),_('Username'),+ _('Email'),_('First name'),_('Last name'),- _('Gym')])+ _('Gender'),+ _('Age'),+ _('ZIP code'),+ _('City'),+ _('Street'),+ _('Phone')])for user in Gym.objects.get_members(gym_pk):+ address = user.userprofile.addresswriter.writerow([user.id,+ gym.name,user.username,+ user.email,user.first_name,user.last_name,- gym.name])+ user.userprofile.get_gender_display(),+ user.userprofile.age,+ address['zip_code'],+ address['city'],+ address['street'],+ address['phone']+ ])# Send the data to the browsertoday = datetime.date.today()