Skip to content

Commit

Permalink
fix eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
magsyg committed Sep 14, 2023
1 parent 9090bc7 commit e473bf4
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 55 deletions.
113 changes: 87 additions & 26 deletions backend/samfundet/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand All @@ -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']
Expand All @@ -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 = []
Expand Down Expand Up @@ -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 = []
Expand All @@ -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 = []
Expand All @@ -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__']
Expand Down Expand Up @@ -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 = []
Expand All @@ -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__']
Expand Down Expand Up @@ -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__']
Expand All @@ -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__']
Expand All @@ -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__']
Expand All @@ -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__']
Expand All @@ -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__']
Expand All @@ -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']
Expand Down Expand Up @@ -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']
Expand Down
14 changes: 6 additions & 8 deletions backend/samfundet/models/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
16 changes: 1 addition & 15 deletions backend/samfundet/models/utils/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

3 changes: 2 additions & 1 deletion backend/samfundet/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion backend/samfundet/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Components/Footer/Footer.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
component: Footer,
} as ComponentMeta<typeof Footer>;

const Template: ComponentStory<typeof Footer> = function (args) {
const Template: ComponentStory<typeof Footer> = function () {
return <Footer />;
};

Expand Down
1 change: 0 additions & 1 deletion frontend/src/Components/ProtectedRoute/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Navigate, useLocation } from 'react-router-dom';
import { useAuthContext } from '~/AuthContext';
import { hasPerm } from '~/utils';
import { ROUTES } from '~/routes';
import { PERM } from '~/permissions';
import { ElementType } from 'react';

type ProtectedRouteProps = {
Expand Down
1 change: 0 additions & 1 deletion frontend/src/Pages/LoginPage/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Alert, Page } from '~/Components';
import { SamfForm } from '~/Forms/SamfForm';
import { SamfFormField } from '~/Forms/SamfFormField';
import { getUser, login } from '~/api';

import { STATUS } from '~/http_status_codes';
import { KEY } from '~/i18n/constants';
import { ROUTES } from '~/routes';
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/Pages/SignUpPage/SignUpPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ export function SignUpPage() {
}, [user, navigate]);

function handleRegistration(formData: Record<string, string>) {
register(formData['username'], formData['email'], formData['phone_number'], formData['firstname'], formData['lastname'], formData['password'])
register(
formData['username'],
formData['email'],
formData['phone_number'],
formData['firstname'],
formData['lastname'],
formData['password'],
)
.then((status) => {
if (status === STATUS.HTTP_202_ACCEPTED) {
getUser().then((user) => {
Expand Down

0 comments on commit e473bf4

Please sign in to comment.