Skip to content

Commit 93702e5

Browse files
committed
Fixed linting in project
1 parent f688416 commit 93702e5

File tree

8 files changed

+64
-37
lines changed

8 files changed

+64
-37
lines changed

yaus/settings.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@
3838
"django.contrib.messages",
3939
"django.contrib.staticfiles",
4040
"rest_framework",
41-
'drf_yasg',
42-
43-
"yaus"
41+
"drf_yasg",
42+
"yaus",
4443
]
4544

4645
MIDDLEWARE = [
@@ -127,10 +126,10 @@
127126
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
128127

129128
REST_FRAMEWORK = {
130-
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
131-
'PAGE_SIZE': 10,
132-
'DEFAULT_RENDERER_CLASSES': [
133-
'rest_framework.renderers.JSONRenderer',
134-
'rest_framework.renderers.BrowsableAPIRenderer',
135-
]
129+
"DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
130+
"PAGE_SIZE": 10,
131+
"DEFAULT_RENDERER_CLASSES": [
132+
"rest_framework.renderers.JSONRenderer",
133+
"rest_framework.renderers.BrowsableAPIRenderer",
134+
],
136135
}

yaus/shortener/models/shortlink.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
class ShortLink(models.Model):
1212
original_url = models.CharField(max_length=512)
13-
passcode = models.CharField(max_length=64, blank=True, default='')
14-
salt = models.CharField(max_length=64, blank=True, default='')
13+
passcode = models.CharField(max_length=64, blank=True, default="")
14+
salt = models.CharField(max_length=64, blank=True, default="")
1515
redirect_string = models.CharField(max_length=8)
1616
usage_count = models.IntegerField(default=0)
1717

yaus/shortener/serializers/serializers.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
class UserSerializer(serializers.HyperlinkedModelSerializer):
66
class Meta:
77
model = User
8-
fields = ['url', 'username', 'email', 'groups']
8+
fields = ["url", "username", "email", "groups"]
99

1010

1111
class GroupSerializer(serializers.HyperlinkedModelSerializer):
1212
class Meta:
1313
model = Group
14-
fields = ['url', 'name']
14+
fields = ["url", "name"]

yaus/shortener/serializers/shortlink_serializer.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,15 @@ class ShortLinkSerializer(serializers.ModelSerializer):
1212

1313
class Meta:
1414
model = ShortLink
15-
fields = ['id', 'original_url', 'passcode', 'redirect_string', 'owner', 'usage_count']
16-
read_only_fields = ['id', 'redirect_string', 'usage_count']
15+
fields = [
16+
"id",
17+
"original_url",
18+
"passcode",
19+
"redirect_string",
20+
"owner",
21+
"usage_count",
22+
]
23+
read_only_fields = ["id", "redirect_string", "usage_count"]
1724

1825
def validate(self, attrs):
1926
user = self.context["request"].user
@@ -24,7 +31,7 @@ def validate(self, attrs):
2431

2532
def create(self, validated_data):
2633
shortlink = ShortLink(**validated_data)
27-
if validated_data.get('passcode'):
34+
if validated_data.get("passcode"):
2835
shortlink.encode_fields()
2936
shortlink.redirect_string = Utils.generate_redirect_string()
3037
shortlink.save()

yaus/shortener/views/redirect_viewset.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,29 @@ class RedirectViewSet(GenericViewSet):
1515
method="GET",
1616
manual_parameters=[
1717
openapi.Parameter(
18-
'passcode',
18+
"passcode",
1919
openapi.IN_QUERY,
2020
type=openapi.TYPE_STRING,
2121
)
2222
],
2323
)
24-
@api_view(['GET'])
24+
@api_view(["GET"])
2525
@renderer_classes([JSONRenderer])
2626
def redirect_to(self, redirect_string):
2727
shortlink = ShortLink.objects.filter(redirect_string=redirect_string).first()
2828
if shortlink is None:
2929
return Response({}, status=status.HTTP_404_NOT_FOUND)
3030

31-
if shortlink.passcode is '':
31+
if shortlink.passcode is "":
3232
shortlink.increase_usage_count()
33-
return Response({'url': shortlink.original_url}, status=status.HTTP_200_OK)
33+
return Response({"url": shortlink.original_url}, status=status.HTTP_200_OK)
3434

35-
passcode = self.query_params.get('passcode')
35+
passcode = self.query_params.get("passcode")
3636
if shortlink.passcode and passcode is None:
37-
return Response({'error': 'No passcode provided'}, status=status.HTTP_400_BAD_REQUEST)
37+
return Response(
38+
{"error": "No passcode provided"}, status=status.HTTP_400_BAD_REQUEST
39+
)
3840

3941
original_url = shortlink.decode_url(passcode)
4042
shortlink.increase_usage_count()
41-
return Response({'url': original_url}, status=status.HTTP_200_OK)
43+
return Response({"url": original_url}, status=status.HTTP_200_OK)
+12-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
from rest_framework import viewsets
2-
from rest_framework.mixins import CreateModelMixin, RetrieveModelMixin, ListModelMixin, DestroyModelMixin
2+
from rest_framework.mixins import (
3+
CreateModelMixin,
4+
RetrieveModelMixin,
5+
ListModelMixin,
6+
DestroyModelMixin,
7+
)
38

49
from yaus.shortener.models.shortlink import ShortLink
510
from yaus.shortener.serializers.shortlink_serializer import ShortLinkSerializer
611

712

8-
class ShortlinkViewSet(viewsets.GenericViewSet, CreateModelMixin, ListModelMixin, DestroyModelMixin):
13+
class ShortlinkViewSet(
14+
viewsets.GenericViewSet, CreateModelMixin, ListModelMixin, DestroyModelMixin
15+
):
916
queryset = ShortLink.objects.all()
1017
serializer_class = ShortLinkSerializer
1118

1219
def get_queryset(self):
1320
if self.request.user.is_authenticated:
14-
return ShortLink.objects.filter(owner=self.request.user, deleted_at__isnull=True).order_by("id")
21+
return ShortLink.objects.filter(
22+
owner=self.request.user, deleted_at__isnull=True
23+
).order_by("id")
1524
return []

yaus/shortener/views/views.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ class UserViewSet(viewsets.ModelViewSet):
77
"""
88
API endpoint that allows users to be viewed or edited.
99
"""
10-
queryset = User.objects.all().order_by('-date_joined')
10+
11+
queryset = User.objects.all().order_by("-date_joined")
1112
serializer_class = UserSerializer
1213
permission_classes = [permissions.AllowAny]
1314

@@ -19,6 +20,7 @@ class GroupViewSet(viewsets.ModelViewSet):
1920
"""
2021
API endpoint that allows groups to be viewed or edited.
2122
"""
22-
queryset = Group.objects.all().order_by('name')
23+
24+
queryset = Group.objects.all().order_by("name")
2325
serializer_class = GroupSerializer
2426
permission_classes = [permissions.IsAuthenticated]

yaus/urls.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,34 @@
88
schema_view = get_schema_view(
99
openapi.Info(
1010
title="Snippets API",
11-
default_version='v1',
11+
default_version="v1",
1212
description="Test description",
1313
terms_of_service="https://www.google.com/policies/terms/",
1414
contact=openapi.Contact(email="[email protected]"),
1515
license=openapi.License(name="BSD License"),
1616
),
1717
public=True,
18-
permission_classes=([permissions.AllowAny,]),
18+
permission_classes=(
19+
[
20+
permissions.AllowAny,
21+
]
22+
),
1923
)
2024

2125

2226
router = routers.DefaultRouter()
23-
router.register(r'users', views.UserViewSet)
24-
router.register(r'shortener', views.ShortlinkViewSet)
27+
router.register(r"users", views.UserViewSet)
28+
router.register(r"shortener", views.ShortlinkViewSet)
2529

2630
# Wire up our API using automatic URL routing.
2731
# Additionally, we include login URLs for the browsable API.
2832
urlpatterns = [
29-
path('swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
30-
path('', include(router.urls)),
31-
path('api-auth/', include('rest_framework.urls', namespace='rest_framework')),
32-
path('r/<slug:redirect_string>', views.RedirectViewSet.redirect_to)
33-
]
33+
path(
34+
"swagger/",
35+
schema_view.with_ui("swagger", cache_timeout=0),
36+
name="schema-swagger-ui",
37+
),
38+
path("", include(router.urls)),
39+
path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
40+
path("r/<slug:redirect_string>", views.RedirectViewSet.redirect_to),
41+
]

0 commit comments

Comments
 (0)