Skip to content

Commit

Permalink
Initial formatting with ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandgeider committed Jan 27, 2024
1 parent bb0d989 commit 6fdeb96
Show file tree
Hide file tree
Showing 360 changed files with 2,845 additions and 3,560 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/formatter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4

- name: Get dependencies
run: pip install ruff isort

- name: Format the code
run: ruff format

Expand Down
20 changes: 16 additions & 4 deletions extras/scripts/filter-fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,23 @@ def filter_dump(model_list, filename):
filter_dump(('exercises.muscle',), 'muscles.json')
filter_dump(('exercises.exercisecategory',), 'categories.json')
filter_dump(('exercises.exerciseimage',), 'exercise-images.json')
filter_dump(('exercises.exercisebase', 'exercises.variation',), 'exercise-base-data.json')
filter_dump(
('exercises.exercise', 'exercises.exercisecomment', 'exercises.alias'),
'translations.json')
filter_dump(('exercises.equipment', 'exercises.equipment',), 'equipment.json')
(
'exercises.exercisebase',
'exercises.variation',
),
'exercise-base-data.json',
)
filter_dump(
('exercises.exercise', 'exercises.exercisecomment', 'exercises.alias'), 'translations.json'
)
filter_dump(
(
'exercises.equipment',
'exercises.equipment',
),
'equipment.json',
)

#
# Gym
Expand Down
1 change: 1 addition & 0 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
setup_django_environment,
)


if __name__ == '__main__':
# If user passed the settings flag ignore the default wger settings
if not any('--settings' in s for s in sys.argv):
Expand Down
4 changes: 2 additions & 2 deletions wger/celery_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from celery import Celery


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
app = Celery("wger")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
app = Celery('wger')

# read config from Django settings, the CELERY namespace would make celery
# config keys has `CELERY` prefix
Expand Down
2 changes: 1 addition & 1 deletion wger/config/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class ConfigConfig(AppConfig):
name = 'wger.config'
verbose_name = "Config"
verbose_name = 'Config'

def ready(self):
import wger.config.signals
28 changes: 13 additions & 15 deletions wger/config/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Migration(migrations.Migration):

dependencies = [
('gym', '0001_initial'),
('core', '0001_initial'),
Expand All @@ -18,23 +17,22 @@ class Migration(migrations.Migration):
'id',
models.AutoField(
verbose_name='ID', serialize=False, auto_created=True, primary_key=True
)
),
),
(
'default_gym',
models.ForeignKey(
blank=True,
to='gym.Gym',
help_text=
'Select the default gym for this installation. This will assign all new registered users to this gym and update all existing users without a gym.',
help_text='Select the default gym for this installation. This will assign all new registered users to this gym and update all existing users without a gym.',
null=True,
verbose_name='Default gym',
on_delete=models.CASCADE
)
on_delete=models.CASCADE,
),
),
],
options={},
bases=(models.Model, ),
bases=(models.Model,),
),
migrations.CreateModel(
name='LanguageConfig',
Expand All @@ -43,15 +41,15 @@ class Migration(migrations.Migration):
'id',
models.AutoField(
verbose_name='ID', serialize=False, auto_created=True, primary_key=True
)
),
),
(
'item',
models.CharField(
max_length=2,
editable=False,
choices=[(b'1', 'Exercises'), (b'2', 'Ingredients')]
)
choices=[(b'1', 'Exercises'), (b'2', 'Ingredients')],
),
),
('show', models.BooleanField(default=1)),
(
Expand All @@ -60,22 +58,22 @@ class Migration(migrations.Migration):
related_name='language_source',
editable=False,
to='core.Language',
on_delete=models.CASCADE
)
on_delete=models.CASCADE,
),
),
(
'language_target',
models.ForeignKey(
related_name='language_target',
editable=False,
to='core.Language',
on_delete=models.CASCADE
)
on_delete=models.CASCADE,
),
),
],
options={
'ordering': ['item', 'language_target'],
},
bases=(models.Model, ),
bases=(models.Model,),
),
]
5 changes: 3 additions & 2 deletions wger/config/migrations/0002_auto_20190618_1617.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class Migration(migrations.Migration):

dependencies = [
('config', '0001_initial'),
]
Expand All @@ -18,7 +17,9 @@ class Migration(migrations.Migration):
choices=[
('1', 'Exercises'),
('2', 'Ingredients'),
], editable=False, max_length=2
],
editable=False,
max_length=2,
),
),
]
5 changes: 3 additions & 2 deletions wger/config/migrations/0003_delete_languageconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@


class Migration(migrations.Migration):

dependencies = [
('config', '0002_auto_20190618_1617'),
]

operations = [
migrations.DeleteModel(name='LanguageConfig', ),
migrations.DeleteModel(
name='LanguageConfig',
),
]
5 changes: 2 additions & 3 deletions wger/config/models/gym_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class GymConfig(models.Model):
),
null=True,
blank=True,
on_delete=models.CASCADE
on_delete=models.CASCADE,
)
"""
Default gym for the wger installation
Expand All @@ -62,14 +62,13 @@ def __str__(self):
"""
Return a more human-readable representation
"""
return "Default gym {0}".format(self.default_gym)
return 'Default gym {0}'.format(self.default_gym)

def save(self, *args, **kwargs):
"""
Perform additional tasks
"""
if self.default_gym:

# All users that have no gym set in the profile are edited
UserProfile.objects.filter(gym=None).update(gym=self.default_gym)

Expand Down
1 change: 0 additions & 1 deletion wger/config/tests/test_custom_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class GymNameHeaderTestCase(WgerTestCase):
"""

def check_header(self, gym=None):

response = self.client.get(reverse('core:dashboard'))
self.assertEqual(response.context['custom_header'], gym)

Expand Down
2 changes: 1 addition & 1 deletion wger/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
urlpatterns = [
path(
'gym-config/',
include((patterns_gym_config, 'gym_config'), namespace="gym_config"),
include((patterns_gym_config, 'gym_config'), namespace='gym_config'),
),
]
1 change: 1 addition & 0 deletions wger/config/views/gym_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class GymConfigUpdateView(WgerFormMixin, UpdateView):
"""
Generic view to edit the gym config table
"""

model = GymConfig
fields = ['default_gym']
permission_required = 'config.change_gymconfig'
Expand Down
4 changes: 2 additions & 2 deletions wger/core/api/endpoints.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
LANGUAGE_ENDPOINT = "language"
LICENSE_ENDPOINT = "license"
LANGUAGE_ENDPOINT = 'language'
LICENSE_ENDPOINT = 'license'
20 changes: 11 additions & 9 deletions wger/core/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class UserprofileSerializer(serializers.ModelSerializer):
Workout session serializer
"""

email = serializers.EmailField(source="user.email", read_only=True)
username = serializers.EmailField(source="user.username", read_only=True)
date_joined = serializers.EmailField(source="user.date_joined", read_only=True)
email = serializers.EmailField(source='user.email', read_only=True)
username = serializers.EmailField(source='user.username', read_only=True)
date_joined = serializers.EmailField(source='user.date_joined', read_only=True)

class Meta:
model = UserProfile
Expand Down Expand Up @@ -86,7 +86,8 @@ class Meta:


class UserLoginSerializer(serializers.ModelSerializer):
""" Serializer to map to User model in relation to api user"""
"""Serializer to map to User model in relation to api user"""

email = serializers.CharField(required=False)
username = serializers.CharField(required=False)
password = serializers.CharField(required=True, min_length=8)
Expand All @@ -102,9 +103,9 @@ def __init__(self, request: HttpRequest = None, instance=None, data=empty, **kwa
super().__init__(instance, data, **kwargs)

def validate(self, data):
email = data.get("email", None)
username = data.get("username", None)
password = data.get("password", None)
email = data.get('email', None)
username = data.get('username', None)
password = data.get('password', None)

if email is None and username is None:
raise serializers.ValidationError('Please provide an "email" or a "username"')
Expand All @@ -122,9 +123,10 @@ def validate(self, data):

class UserRegistrationSerializer(serializers.ModelSerializer):
email = serializers.EmailField(
required=False, validators=[
required=False,
validators=[
UniqueValidator(queryset=User.objects.all()),
]
],
)
username = serializers.CharField(
required=True,
Expand Down
Loading

0 comments on commit 6fdeb96

Please sign in to comment.