-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add ruff to lint and format python code
- Loading branch information
1 parent
21525de
commit ff63a04
Showing
44 changed files
with
560 additions
and
379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,4 +32,7 @@ coverage | |
.ionide | ||
|
||
# IntelliJ | ||
.idea | ||
.idea | ||
|
||
# Ruff | ||
.ruff_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
echo "Running static tests..." | ||
pnpm run test:static | ||
echo "Done running static tests." | ||
|
||
echo "Formatting code..." | ||
pnpm run format | ||
echo "Done formatting code." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
|
||
class ApiConfig(AppConfig): | ||
name = 'api' | ||
name = "api" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
from django_filters import rest_framework as filters | ||
from backend.models.publications import Publication | ||
|
||
|
||
class PublicationFilter(filters.FilterSet): | ||
tag = filters.CharFilter(field_name='tag', lookup_expr='icontains') | ||
title = filters.CharFilter(field_name='title', lookup_expr='icontains') | ||
tag = filters.CharFilter(field_name="tag", lookup_expr="icontains") | ||
title = filters.CharFilter(field_name="title", lookup_expr="icontains") | ||
|
||
class Meta: | ||
model = Publication | ||
fields = ['title', 'tag'] | ||
fields = ["title", "tag"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +0,0 @@ | ||
from .publications import PublicationsSerializer | ||
from .subscribers import SubscribersSerializer | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,22 @@ | ||
from rest_framework import serializers | ||
from backend.models.publications import Publication | ||
|
||
|
||
class PublicationsSerializer(serializers.ModelSerializer): | ||
image = serializers.SerializerMethodField(read_only=True) | ||
|
||
def get_image(self, instance): | ||
return instance.image.url | ||
|
||
class Meta: | ||
model = Publication | ||
fields = ('title', 'slug', 'description', 'body', 'image', 'tag', 'image_description', 'created_at') | ||
model = Publication | ||
fields = ( | ||
"title", | ||
"slug", | ||
"description", | ||
"body", | ||
"image", | ||
"tag", | ||
"image_description", | ||
"created_at", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from rest_framework import serializers | ||
from backend.models.subscribers import Subscriber | ||
|
||
|
||
class SubscribersSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = Subscriber | ||
fields = ('name', 'contact_method', 'contact_info') | ||
fields = ("name", "contact_method", "contact_info") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +0,0 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
from django.urls import re_path | ||
from rest_framework.authtoken.views import obtain_auth_token | ||
from .views.subscribers import SubscribersEndpoint | ||
from .views.publications import PublicationsEndpoint, PublicationsQueryEndpoint, PaginatedPublicationsQueryEndpoint, PaginatedPublicationsEndpoint, PublicationEndpoint | ||
from .views.publications import ( | ||
PublicationsEndpoint, | ||
PublicationsQueryEndpoint, | ||
PaginatedPublicationsQueryEndpoint, | ||
PaginatedPublicationsEndpoint, | ||
PublicationEndpoint, | ||
) | ||
|
||
|
||
urlpatterns = [ | ||
re_path(r'^subscribers/$', SubscribersEndpoint.as_view() ), | ||
re_path(r'^publications/p/$', PaginatedPublicationsEndpoint.as_view() ), | ||
re_path(r'^publications/filter/$', PublicationsQueryEndpoint.as_view() ), | ||
re_path(r'^publications/p/filter/$', PaginatedPublicationsQueryEndpoint.as_view()), | ||
re_path(r'^publications/(?P<slug>[\w\-]+)/$', PublicationEndpoint.as_view()), | ||
re_path(r'^publications/$', PublicationsEndpoint.as_view() ), | ||
re_path(r'^authenticate/$', obtain_auth_token) | ||
] | ||
re_path(r"^subscribers/$", SubscribersEndpoint.as_view()), | ||
re_path(r"^publications/p/$", PaginatedPublicationsEndpoint.as_view()), | ||
re_path(r"^publications/filter/$", PublicationsQueryEndpoint.as_view()), | ||
re_path(r"^publications/p/filter/$", PaginatedPublicationsQueryEndpoint.as_view()), | ||
re_path(r"^publications/(?P<slug>[\w\-]+)/$", PublicationEndpoint.as_view()), | ||
re_path(r"^publications/$", PublicationsEndpoint.as_view()), | ||
re_path(r"^authenticate/$", obtain_auth_token), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
from backend.models.subscribers import Subscriber | ||
from api.serializers.subscribers import SubscribersSerializer | ||
from rest_framework.views import APIView | ||
from rest_framework.response import Response | ||
from rest_framework import status | ||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.permissions import IsAuthenticated | ||
|
||
|
||
class SubscribersEndpoint(APIView): | ||
""" | ||
Interface for users to send their subscription data. | ||
""" | ||
|
||
permission_classes = (IsAuthenticated,) | ||
|
||
def post(self,request): | ||
def post(self, request): | ||
serializer = SubscribersSerializer(data=request.data) | ||
|
||
if serializer.is_valid(): | ||
serializer.save() | ||
return Response(status=status.HTTP_201_CREATED) | ||
|
||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) | ||
|
||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
default_app_config = 'backend.apps.BackendConfig' | ||
default_app_config = "backend.apps.BackendConfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +0,0 @@ | ||
from .publications import PublicationAdmin | ||
from .subscribers import SubscriberAdmin | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.core.cache import cache | ||
|
||
|
||
class Command(BaseCommand): | ||
def handle(self, *args, **kwargs): | ||
cache.clear() | ||
self.stdout.write('Cleared cache\n') | ||
self.stdout.write("Cleared cache\n") |
Oops, something went wrong.