Skip to content

Commit

Permalink
[Chore] Norm the backend code using pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
zakarm committed Apr 25, 2024
1 parent 1d25849 commit b0f7d15
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 30 deletions.
4 changes: 3 additions & 1 deletion app/back-end/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ disable=missing-docstring,
invalid-name,
too-few-public-methods,
abstract-method,
arguments-renamed
arguments-renamed,
too-many-locals
too-many-branches

[FORMAT]
max-line-length=120
Expand Down
2 changes: 2 additions & 0 deletions app/back-end/authentication/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,5 @@ def validate(self, data):
raise serializers.ValidationError("Failed to fetch user data from 42")
except IntegrityError as e:
raise serializers.ValidationError("Email already exists") from e
else :
return None
24 changes: 20 additions & 4 deletions app/back-end/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,30 @@ def get(self, request, platform):
if platform == 'github':
CLIENT_ID = settings.GITHUB_CLIENT_ID
REDIRECT_URI = settings.GITHUB_REDIRECT_URI
return redirect(f'https://github.com/login/oauth/authorize?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope=user:email')
url = (
f'https://github.com/login/oauth/authorize?client_id={CLIENT_ID}'
f'&redirect_uri={REDIRECT_URI}&scope=user:email'
)
return redirect(url)
elif platform == 'google':
CLIENT_ID = settings.GOOGLE_CLIENT_ID
REDIRECT_URI = settings.GOOGLE_REDIRECT_URI
SCOPE = "https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email"
return redirect(f'https://accounts.google.com/o/oauth2/v2/auth?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope={urllib.parse.quote(SCOPE)}&response_type=code')
SCOPE = (
"https://www.googleapis.com/auth/userinfo.profile"
" https://www.googleapis.com/auth/userinfo.email"
)
url = (
f'https://accounts.google.com/o/oauth2/v2/auth?client_id={CLIENT_ID}'
f'&redirect_uri={REDIRECT_URI}&scope={urllib.parse.quote(SCOPE)}&response_type=code'
)
return redirect(url)
elif platform == '42':
CLIENT_ID = settings.FORTYTWO_CLIENT_ID
REDIRECT_URI = settings.FORTYTWO_REDIRECT_URI
SCOPE = "public"
return redirect(f'https://api.intra.42.fr/oauth/authorize?client_id={CLIENT_ID}&redirect_uri={REDIRECT_URI}&scope={SCOPE}&response_type=code')
url = (
f'https://api.intra.42.fr/oauth/authorize?client_id={CLIENT_ID}'
f'&redirect_uri={REDIRECT_URI}&scope={SCOPE}&response_type=code'
)
return redirect(url)
return None
2 changes: 1 addition & 1 deletion app/back-end/dashboards/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ def get_monthly_stats(self, obj):

def to_representation(self, instance):
data = super().to_representation(instance)
return data
return data
24 changes: 0 additions & 24 deletions app/back-end/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.db import models


class Achievements(models.Model):
achievement_id = models.AutoField(primary_key=True)
achiev_name = models.CharField(max_length=45)
Expand All @@ -9,7 +8,6 @@ class Meta:
managed = False
db_table = 'Achievements'


class Friendship(models.Model):
freindship_id = models.AutoField(primary_key=True)
user_from = models.ForeignKey('Users', models.DO_NOTHING,
Expand All @@ -22,25 +20,6 @@ class Meta:
managed = False
db_table = 'Friendship'


class Matches(models.Model):
match_id = models.AutoField(primary_key=True)
user_one = models.ForeignKey('Users', models.DO_NOTHING, db_column='user_one')
user_two = models.ForeignKey('Users', models.DO_NOTHING,
db_column='user_two',
related_name='matches_user_two_set')
score_user_one = models.IntegerField()
score_user_two = models.IntegerField()
match_start = models.DateField()
match_end = models.DateField()
tackle_user_one = models.IntegerField()
tackle_user_two = models.IntegerField()

class Meta:
managed = False
db_table = 'Matches'


class Messages(models.Model):
user_one = models.OneToOneField('Users', models.DO_NOTHING,
db_column='user_one', primary_key=True)
Expand All @@ -50,7 +29,6 @@ class Messages(models.Model):
message_content = models.CharField(max_length=512)
message_date = models.DateField()
message_direction = models.CharField(max_length=20)

class Meta:
managed = False
db_table = 'Messages'
Expand All @@ -65,7 +43,6 @@ class Meta:
db_table = 'UserAchievements'
unique_together = (('user', 'achivement'),)


class Users(models.Model):
user_id = models.AutoField(primary_key=True)
first_name = models.CharField(max_length=20)
Expand All @@ -82,7 +59,6 @@ class Users(models.Model):
country = models.CharField(max_length=60)
city = models.CharField(max_length=60)
password = models.CharField(max_length=200)

class Meta:
managed = False
db_table = 'Users'

0 comments on commit b0f7d15

Please sign in to comment.