From e473bf44e5b24fbecf5646e0cf8f9093150301fe Mon Sep 17 00:00:00 2001 From: magsyg Date: Thu, 14 Sep 2023 19:38:47 +0200 Subject: [PATCH] fix eslint errors --- backend/samfundet/admin.py | 113 ++++++++++++++---- backend/samfundet/models/general.py | 14 +-- backend/samfundet/models/utils/fields.py | 16 +-- backend/samfundet/serializers.py | 3 +- backend/samfundet/views.py | 1 - .../src/Components/Footer/Footer.stories.tsx | 2 +- .../ProtectedRoute/ProtectedRoute.tsx | 1 - frontend/src/Pages/LoginPage/LoginPage.tsx | 1 - frontend/src/Pages/SignUpPage/SignUpPage.tsx | 9 +- 9 files changed, 105 insertions(+), 55 deletions(-) diff --git a/backend/samfundet/admin.py b/backend/samfundet/admin.py index e55cf8016..50906a5d2 100644 --- a/backend/samfundet/admin.py +++ b/backend/samfundet/admin.py @@ -11,7 +11,8 @@ CustomGuardedModelAdmin, ) from .models.event import (Event, EventGroup, EventRegistration) -from .models.recruitment import (Recruitment, RecruitmentPosition, RecruitmentAdmission) +from .models.recruitment import (Recruitment, RecruitmentPosition, + RecruitmentAdmission) from .models.general import ( Tag, User, @@ -57,13 +58,18 @@ @admin.register(User) class UserAdmin(CustomGuardedUserAdmin): - sortable_by = ['id', 'username', 'email', 'first_name', 'last_name', 'is_active', 'is_staff', 'is_superuser', 'last_login', 'date_joined', 'updated_at'] + sortable_by = [ + 'id', 'username', 'email', 'first_name', 'last_name', 'is_active', + 'is_staff', 'is_superuser', 'last_login', 'date_joined', 'updated_at' + ] list_display = [ - 'id', 'username', 'email', 'first_name', 'last_name', 'is_active', 'is_staff', 'is_superuser', 'group_memberships', 'last_login', 'date_joined', - 'updated_at' + 'id', 'username', 'email', 'first_name', 'last_name', 'is_active', + 'is_staff', 'is_superuser', 'group_memberships', 'last_login', + 'date_joined', 'updated_at' ] list_display_links = ['id', 'username'] list_select_related = True + @admin.display(empty_value='all') def group_memberships(self, obj: User) -> int: n: int = obj.groups.all().count() @@ -88,7 +94,9 @@ class PermissionAdmin(CustomGuardedModelAdmin): sortable_by = ['id', 'codename', 'content_type'] # list_filter = [] list_display = ['id', '__str__', 'codename', 'content_type'] - search_fields = ['name', 'codename', 'content_type__app_label', 'content_type__model'] + search_fields = [ + 'name', 'codename', 'content_type__app_label', 'content_type__model' + ] # filter_horizontal = [] list_display_links = ['id', '__str__'] autocomplete_fields = ['content_type'] @@ -112,7 +120,9 @@ class ContentTypeAdmin(CustomGuardedModelAdmin): class LogEntryAdmin(CustomGuardedModelAdmin): sortable_by = ['id', 'user', 'action_flag', 'object_repr', 'action_time'] list_filter = ['action_flag'] - list_display = ['id', '__str__', 'user', 'action_flag', 'object_repr', 'action_time'] + list_display = [ + 'id', '__str__', 'user', 'action_flag', 'object_repr', 'action_time' + ] _user_search_fields = UserAdmin.custom_search_fields(prefix='user') search_fields = ['id', 'object_repr', *_user_search_fields] # filter_horizontal = [] @@ -167,7 +177,9 @@ class UserPreferenceAdmin(CustomGuardedModelAdmin): # ordering = [] sortable_by = ['id', 'user', 'theme', 'created_at', 'updated_at'] list_filter = ['theme'] - list_display = ['id', '__str__', 'user', 'theme', 'created_at', 'updated_at'] + list_display = [ + 'id', '__str__', 'user', 'theme', 'created_at', 'updated_at' + ] _user_search_fields = UserAdmin.custom_search_fields(prefix='user') search_fields = ['id', 'theme', *_user_search_fields] # filter_horizontal = [] @@ -181,7 +193,9 @@ class ProfileAdmin(CustomGuardedModelAdmin): # ordering = [] sortable_by = ['id', 'user', 'nickname', 'created_at', 'updated_at'] # list_filter = [] - list_display = ['id', '__str__', 'user', 'nickname', 'created_at', 'updated_at'] + list_display = [ + 'id', '__str__', 'user', 'nickname', 'created_at', 'updated_at' + ] _user_search_fields = UserAdmin.custom_search_fields(prefix='user') search_fields = ['id', 'nickname', *_user_search_fields] # filter_horizontal = [] @@ -200,9 +214,15 @@ class EventRegistrationAdmin(CustomGuardedModelAdmin): class EventAdmin(CustomGuardedModelAdmin): # ordering = [] - sortable_by = ['id', 'title_nb', 'title_en', 'host', 'location', 'event_group', 'created_at', 'updated_at'] + sortable_by = [ + 'id', 'title_nb', 'title_en', 'host', 'location', 'event_group', + 'created_at', 'updated_at' + ] list_filter = ['event_group'] - list_display = ['id', '__str__', 'title_nb', 'title_en', 'host', 'location', 'event_group', 'publish_dt', 'start_dt', 'created_at', 'updated_at'] + list_display = [ + 'id', '__str__', 'title_nb', 'title_en', 'host', 'location', + 'event_group', 'publish_dt', 'start_dt', 'created_at', 'updated_at' + ] search_fields = ['id', 'title_nb', 'title_en', 'host', 'location'] filter_horizontal = ['editors'] list_display_links = ['id', '__str__'] @@ -252,10 +272,15 @@ class EventGroupAdmin(CustomGuardedModelAdmin): @admin.register(Venue) class VenueAdmin(CustomGuardedModelAdmin): # ordering = [] - sortable_by = ['id', 'name', 'floor', 'last_renovated', 'handicapped_approved', 'responsible_crew', 'opening', 'closing', 'created_at', 'updated_at'] + sortable_by = [ + 'id', 'name', 'floor', 'last_renovated', 'handicapped_approved', + 'responsible_crew', 'opening', 'closing', 'created_at', 'updated_at' + ] list_filter = ['handicapped_approved'] list_display = [ - 'id', '__str__', 'name', 'floor', 'last_renovated', 'handicapped_approved', 'responsible_crew', 'opening', 'closing', 'created_at', 'updated_at' + 'id', '__str__', 'name', 'floor', 'last_renovated', + 'handicapped_approved', 'responsible_crew', 'opening', 'closing', + 'created_at', 'updated_at' ] search_fields = ['id', 'name', 'responsible_crew'] # filter_horizontal = [] @@ -268,9 +293,15 @@ class VenueAdmin(CustomGuardedModelAdmin): @admin.register(Gang) class GangAdmin(CustomGuardedModelAdmin): # ordering = [] - sortable_by = ['id', 'name_nb', 'abbreviation', 'gang_type', 'created_at', 'updated_at'] + sortable_by = [ + 'id', 'name_nb', 'abbreviation', 'gang_type', 'created_at', + 'updated_at' + ] list_filter = ['gang_type'] - list_display = ['id', '__str__', 'name_nb', 'abbreviation', 'gang_type', 'created_at', 'updated_at'] + list_display = [ + 'id', '__str__', 'name_nb', 'abbreviation', 'gang_type', 'created_at', + 'updated_at' + ] search_fields = ['id', 'name_nb', 'abbreviation'] # filter_horizontal = [] list_display_links = ['id', '__str__'] @@ -320,9 +351,14 @@ class BlogPostAdmin(CustomGuardedModelAdmin): @admin.register(Table) class TableAdmin(CustomGuardedModelAdmin): # ordering = [] - sortable_by = ['id', 'name_nb', 'name_en', 'seating', 'created_at', 'updated_at'] + sortable_by = [ + 'id', 'name_nb', 'name_en', 'seating', 'created_at', 'updated_at' + ] # list_filter = [] - list_display = ['id', '__str__', 'name_nb', 'name_en', 'seating', 'created_at', 'updated_at'] + list_display = [ + 'id', '__str__', 'name_nb', 'name_en', 'seating', 'created_at', + 'updated_at' + ] search_fields = ['id', 'name_nb', 'name_en'] # filter_horizontal = [] list_display_links = ['id', '__str__'] @@ -348,7 +384,10 @@ class MenuAdmin(CustomGuardedModelAdmin): # ordering = [] sortable_by = ['id', 'name_nb', 'name_en', 'created_at', 'updated_at'] # list_filter = [] - list_display = ['id', '__str__', 'name_nb', 'name_en', 'menu_item_count', 'created_at', 'updated_at'] + list_display = [ + 'id', '__str__', 'name_nb', 'name_en', 'menu_item_count', 'created_at', + 'updated_at' + ] search_fields = ['id', 'name_nb', 'name_en'] filter_horizontal = ['menu_items'] list_display_links = ['id', '__str__'] @@ -363,9 +402,15 @@ def menu_item_count(self, obj: Menu) -> int: @admin.register(MenuItem) class MenuItemAdmin(CustomGuardedModelAdmin): # ordering = [] - sortable_by = ['id', 'name_nb', 'name_en', 'price', 'price_member', 'order', 'created_at', 'updated_at'] + sortable_by = [ + 'id', 'name_nb', 'name_en', 'price', 'price_member', 'order', + 'created_at', 'updated_at' + ] # list_filter = [] - list_display = ['id', '__str__', 'name_nb', 'name_en', 'price', 'price_member', 'order', 'created_at', 'updated_at'] + list_display = [ + 'id', '__str__', 'name_nb', 'name_en', 'price', 'price_member', + 'order', 'created_at', 'updated_at' + ] search_fields = ['id', 'name_nb', 'name_en'] filter_horizontal = ['food_preferences'] list_display_links = ['id', '__str__'] @@ -376,9 +421,14 @@ class MenuItemAdmin(CustomGuardedModelAdmin): @admin.register(FoodCategory) class FoodCategoryAdmin(CustomGuardedModelAdmin): # ordering = [] - sortable_by = ['id', 'name_nb', 'name_en', 'order', 'created_at', 'updated_at'] + sortable_by = [ + 'id', 'name_nb', 'name_en', 'order', 'created_at', 'updated_at' + ] # list_filter = [] - list_display = ['id', '__str__', 'name_nb', 'name_en', 'order', 'created_at', 'updated_at'] + list_display = [ + 'id', '__str__', 'name_nb', 'name_en', 'order', 'created_at', + 'updated_at' + ] search_fields = ['id', 'name_nb', 'name_en'] # filter_horizontal = [] list_display_links = ['id', '__str__'] @@ -391,7 +441,9 @@ class FoodPreferenceAdmin(CustomGuardedModelAdmin): # ordering = [] sortable_by = ['id', 'name_nb', 'name_en', 'created_at', 'updated_at'] # list_filter = [] - list_display = ['id', '__str__', 'name_nb', 'name_en', 'created_at', 'updated_at'] + list_display = [ + 'id', '__str__', 'name_nb', 'name_en', 'created_at', 'updated_at' + ] search_fields = ['id', 'name_nb', 'name_en'] # filter_horizontal = [] list_display_links = ['id', '__str__'] @@ -415,7 +467,10 @@ class SaksdokumentAdmin(CustomGuardedModelAdmin): class BookingAdmin(CustomGuardedModelAdmin): # ordering = [] # list_filter = [] - list_display = ['id', '__str__', 'name', 'get_duration', 'table_count', 'created_at', 'updated_at'] + list_display = [ + 'id', '__str__', 'name', 'get_duration', 'table_count', 'created_at', + 'updated_at' + ] _user_search_fields = UserAdmin.custom_search_fields(prefix='user') search_fields = ['id', 'name', *_user_search_fields] filter_horizontal = ['tables'] @@ -472,15 +527,21 @@ class KeyValueAdmin(CustomGuardedModelAdmin): @admin.register(Recruitment) class RecruitmentAdmin(CustomGuardedModelAdmin): sortable_by = [ - 'visible_from', 'actual_application_deadline', 'shown_application_deadline', 'reprioritization_deadline_for_applicant', + 'visible_from', 'actual_application_deadline', + 'shown_application_deadline', + 'reprioritization_deadline_for_applicant', 'reprioritization_deadline_for_groups', 'organization' ] list_display = [ - 'visible_from', 'actual_application_deadline', 'shown_application_deadline', 'reprioritization_deadline_for_applicant', + 'visible_from', 'actual_application_deadline', + 'shown_application_deadline', + 'reprioritization_deadline_for_applicant', 'reprioritization_deadline_for_groups', 'organization' ] search_fields = [ - 'visible_from', 'actual_application_deadline', 'shown_application_deadline', 'reprioritization_deadline_for_applicant', + 'visible_from', 'actual_application_deadline', + 'shown_application_deadline', + 'reprioritization_deadline_for_applicant', 'reprioritization_deadline_for_groups', 'organization' ] list_display_links = ['visible_from'] diff --git a/backend/samfundet/models/general.py b/backend/samfundet/models/general.py index 3e9c943ca..7933ea4c0 100644 --- a/backend/samfundet/models/general.py +++ b/backend/samfundet/models/general.py @@ -107,14 +107,12 @@ class User(AbstractUser): null=False, editable=True, ) - email = models.EmailField(_('email'), - blank=False, - null=False, - unique=True, - error_messages={ - 'unique': - _('A user with that email already exists.'), - }) + email = models.EmailField( + _('email'), + blank=False, + null=False, + unique=True, + ) class Meta: permissions = [ diff --git a/backend/samfundet/models/utils/fields.py b/backend/samfundet/models/utils/fields.py index e7d3b8ffa..0928f9c04 100644 --- a/backend/samfundet/models/utils/fields.py +++ b/backend/samfundet/models/utils/fields.py @@ -2,6 +2,7 @@ from django.core.validators import RegexValidator from rest_framework import serializers + class LowerCaseField(models.CharField): def to_python(self, value: str) -> str: @@ -20,18 +21,3 @@ def __init__(self, *args, **kwargs): ), ] super().__init__(*args, **kwargs) - - -class SerializerPhoneNumberField(serializers.CharField): - - def __init__(self, *args, **kwargs): - kwargs["max_length"] = 15 - self.validators = [ - RegexValidator( - regex= - '^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$ ', - message='Enter a valid phonenumber', - ), - ] - super().__init__(*args, **kwargs) - diff --git a/backend/samfundet/serializers.py b/backend/samfundet/serializers.py index 58afe7169..eb5a577d3 100644 --- a/backend/samfundet/serializers.py +++ b/backend/samfundet/serializers.py @@ -271,7 +271,8 @@ class RegisterSerializer(serializers.Serializer): phone_number = serializers.RegexField( label='Phonenumber', regex=r'^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$', - write_only=True) + write_only=True, + ) firstname = serializers.CharField(label='First name', write_only=True) lastname = serializers.CharField(label='Last name', write_only=True) password = serializers.CharField( diff --git a/backend/samfundet/views.py b/backend/samfundet/views.py index a9af72f2a..4ddc576d5 100644 --- a/backend/samfundet/views.py +++ b/backend/samfundet/views.py @@ -324,7 +324,6 @@ class RegisterView(APIView): def post(self, request: Request) -> Response: serializer = RegisterSerializer(data=self.request.data, context={'request': self.request}) - print(self.request.data) serializer.is_valid(raise_exception=True) user = serializer.validated_data['user'] login(request=request, user=user) diff --git a/frontend/src/Components/Footer/Footer.stories.tsx b/frontend/src/Components/Footer/Footer.stories.tsx index 44d9166a0..32e3635dd 100644 --- a/frontend/src/Components/Footer/Footer.stories.tsx +++ b/frontend/src/Components/Footer/Footer.stories.tsx @@ -7,7 +7,7 @@ export default { component: Footer, } as ComponentMeta; -const Template: ComponentStory = function (args) { +const Template: ComponentStory = function () { return