Skip to content

Commit

Permalink
clean merge
Browse files Browse the repository at this point in the history
  • Loading branch information
magsyg committed Jul 7, 2024
2 parents 7430df5 + c86384c commit cb52939
Show file tree
Hide file tree
Showing 152 changed files with 3,307 additions and 3,645 deletions.
1 change: 1 addition & 0 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ name = "pypi"
"pipenv:rm" = "pipenv --rm" # Completely remove virtual environment.
"pipenv:shell" = "pipenv shell" # Opens a shell within the virtual environment.
"ruff:check" = "pipenv run ruff check ." # Run ruff check linter on project.
"ruff:apply" = "pipenv run ruff check --fix ." # Apply ruff linter on project
"ruff:format:check" = "pipenv run ruff format --check ." # Dry-run ruff format on all files in the project.
"ruff:format:apply" = "pipenv run ruff format ." # Apply ruff format on all files in the project.
"mypy:run" = "pipenv run mypy --config-file mypy.ini ."
Expand Down
6 changes: 3 additions & 3 deletions backend/database/recruitment_schema.drawio
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
<mxRectangle width="30" height="30" as="alternateBounds"/>
</mxGeometry>
</mxCell>
<mxCell id="152" value="default_admission_letter" style="shape=partialRectangle;connectable=0;fillColor=none;top=0;left=0;bottom=0;right=0;align=left;spacingLeft=6;overflow=hidden;" parent="150" vertex="1">
<mxCell id="152" value="default_application_letter" style="shape=partialRectangle;connectable=0;fillColor=none;top=0;left=0;bottom=0;right=0;align=left;spacingLeft=6;overflow=hidden;" parent="150" vertex="1">
<mxGeometry x="30" width="150" height="30" as="geometry">
<mxRectangle width="150" height="30" as="alternateBounds"/>
</mxGeometry>
Expand Down Expand Up @@ -347,7 +347,7 @@
<mxRectangle width="150" height="30" as="alternateBounds"/>
</mxGeometry>
</mxCell>
<mxCell id="173" value="RecruitmentAdmission" style="shape=table;startSize=30;container=1;collapsible=1;childLayout=tableLayout;fixedRows=1;rowLines=0;fontStyle=1;align=center;resizeLast=1;swimlaneFillColor=default;" parent="1" vertex="1">
<mxCell id="173" value="RecruitmentApplication" style="shape=table;startSize=30;container=1;collapsible=1;childLayout=tableLayout;fixedRows=1;rowLines=0;fontStyle=1;align=center;resizeLast=1;swimlaneFillColor=default;" parent="1" vertex="1">
<mxGeometry x="-15" y="800" width="180" height="300" as="geometry"/>
</mxCell>
<mxCell id="174" value="" style="shape=tableRow;horizontal=0;startSize=0;swimlaneHead=0;swimlaneBody=0;fillColor=none;collapsible=0;dropTarget=0;points=[[0,0.5],[1,0.5]];portConstraint=eastwest;top=0;left=0;right=0;bottom=1;" parent="173" vertex="1">
Expand All @@ -371,7 +371,7 @@
<mxRectangle width="30" height="30" as="alternateBounds"/>
</mxGeometry>
</mxCell>
<mxCell id="179" value="admission_text" style="shape=partialRectangle;connectable=0;fillColor=none;top=0;left=0;bottom=0;right=0;align=left;spacingLeft=6;overflow=hidden;" parent="177" vertex="1">
<mxCell id="179" value="application_text" style="shape=partialRectangle;connectable=0;fillColor=none;top=0;left=0;bottom=0;right=0;align=left;spacingLeft=6;overflow=hidden;" parent="177" vertex="1">
<mxGeometry x="30" width="150" height="30" as="geometry">
<mxRectangle width="150" height="30" as="alternateBounds"/>
</mxGeometry>
Expand Down
4 changes: 2 additions & 2 deletions backend/root/management/commands/seed_scripts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
organizations,
information_pages,
recruitment_position,
recruitment_admissions,
recruitment_applications,
recruitment_seperate_position,
recruitment_interviewavailability,
)
Expand Down Expand Up @@ -50,7 +50,7 @@
('recruitment_position', recruitment_position.seed),
('recruitment_interviewavailability', recruitment_interviewavailability.seed),
('recruitment_seperate_position', recruitment_seperate_position.seed),
('recruitment_admissions', recruitment_admissions.seed),
('recruitment_applications', recruitment_applications.seed),
# Example seed (not run unless targeted specifically)
('example', example.seed),
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def seed():
name_nb=recruitment_data['name_nb'],
name_en=recruitment_data['name_en'],
organization=org,
max_admissions=None,
max_applications=None,
visible_from=recruitment_data['visible_from'],
shown_application_deadline=recruitment_data['shown_application_deadline'],
actual_application_deadline=recruitment_data['actual_application_deadline'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@
from random import randint

from samfundet.models.general import User
from samfundet.models.recruitment import RecruitmentPosition, RecruitmentAdmission
from samfundet.models.recruitment import RecruitmentPosition, RecruitmentApplication

# Some example data to use for the new RecruitmentAdmission instances
ADMISSION_DATA = {
'admission_text': 'This is the admission text',
# Some example data to use for the new RecruitmentApplication instances
APPLICATION_DATA = {
'application_text': 'This is the application text',
'applicant_priority': 0,
'recruiter_priority': 0,
'recruiter_status': 0,
}


def seed():
yield 0, 'recruitment_admissions'
RecruitmentAdmission.objects.all().delete()
yield 0, 'Deleted old admissions'
yield 0, 'recruitment_applications'
RecruitmentApplication.objects.all().delete()
yield 0, 'Deleted old applications'

positions = RecruitmentPosition.objects.all()
users = User.objects.all()
created_count = 0

for position_index, position in enumerate(positions):
for _ in range(randint(0, 10)): # Create between 0 and 10 instances for each position
admission_data = ADMISSION_DATA.copy()
admission_data.update(
for _ in range(randint(0, 10)): # Create between 0 and 5 instances for each position
application_data = APPLICATION_DATA.copy()
application_data.update(
{
'recruitment_position': position,
'recruitment': position.recruitment,
'user': users[randint(0, len(users) - 1)], # random user from all users
}
)
_admission, created = RecruitmentAdmission.objects.get_or_create(**admission_data)
_application, created = RecruitmentApplication.objects.get_or_create(**application_data)

if created:
created_count += 1
yield (position_index + 1) / len(positions), 'recruitment_admissions'
yield (position_index + 1) / len(positions), 'recruitment_applications'

yield 100, f'Created {created_count} recruitment_admissions'
yield 100, f'Created {created_count} recruitment_applications'
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
# Some example data to use for the new RecruitmentPosition instances
POSITION_DATA = {
'is_funksjonaer_position': False,
'default_admission_letter_nb': 'Default Admission Letter NB',
'default_admission_letter_en': 'Default Admission Letter EN',
'default_application_letter_nb': 'Default Application Letter NB',
'default_application_letter_en': 'Default Application Letter EN',
'tags': 'tag1,tag2',
}

Expand Down
9 changes: 6 additions & 3 deletions backend/root/management/commands/seed_scripts/users.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from __future__ import annotations

import os
import random

from root.constants import Environment

from samfundet.models.general import User
from samfundet.models.general import User, Campus

# End: imports -----------------------------------------------------

Expand Down Expand Up @@ -33,25 +34,27 @@
]


def create_test_users(*, username, firstname, lastname):
def create_test_users(*, username, firstname, lastname, campus):
User.objects.create_user(
username=username,
email=f'{username}@mg-web.no',
password='passord', # nosec
first_name=firstname,
last_name=lastname,
is_superuser=(ENV == Environment.DEV),
campus=campus,
)


def seed():
campus = Campus.objects.all()
anonomyous_user = User.get_anonymous()
User.objects.filter(is_superuser=False).exclude(id=anonomyous_user.id).delete()
yield 0, 'Deleted existing non-superusers'
existing_superusers = User.objects.filter(is_superuser=True).values_list('username', flat=True)
for i, user in enumerate(TEST_USERS):
if user[0] not in existing_superusers:
create_test_users(username=user[0], firstname=user[1], lastname=user[2])
create_test_users(username=user[0], firstname=user[1], lastname=user[2], campus=random.choice(campus))
yield i / len(TEST_USERS), 'Creating test users'

yield 100, f'Created {len(TEST_USERS)} test users'
8 changes: 4 additions & 4 deletions backend/root/utils/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,10 @@
SAMFUNDET_DELETE_RECRUITMENT = 'samfundet.delete_recruitment'
SAMFUNDET_VIEW_RECRUITMENT = 'samfundet.view_recruitment'

SAMFUNDET_ADD_RECRUITMENTADMISSION = 'samfundet.add_recruitmentadmission'
SAMFUNDET_CHANGE_RECRUITMENTADMISSION = 'samfundet.change_recruitmentadmission'
SAMFUNDET_DELETE_RECRUITMENTADMISSION = 'samfundet.delete_recruitmentadmission'
SAMFUNDET_VIEW_RECRUITMENTADMISSION = 'samfundet.view_recruitmentadmission'
SAMFUNDET_ADD_RECRUITMENTAPPLICATION = 'samfundet.add_recruitmentapplication'
SAMFUNDET_CHANGE_RECRUITMENTAPPLICATION = 'samfundet.change_recruitmentapplication'
SAMFUNDET_DELETE_RECRUITMENTAPPLICATION = 'samfundet.delete_recruitmentapplication'
SAMFUNDET_VIEW_RECRUITMENTAPPLICATION = 'samfundet.view_recruitmentapplication'

SAMFUNDET_ADD_RECRUITMENTPOSITION = 'samfundet.add_recruitmentposition'
SAMFUNDET_CHANGE_RECRUITMENTPOSITION = 'samfundet.change_recruitmentposition'
Expand Down
31 changes: 16 additions & 15 deletions backend/root/utils/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
DO NOT WRITE IN THIS FILE, AS IT WILL BE OVERWRITTEN ON NEXT UPDATE.
THIS FILE WAS GENERATED BY: root.management.commands.generate_routes
LAST UPDATE: 2024-07-07 11:37:11.746770+00:00
LAST UPDATE: 2024-06-29 21:14:57.857649+00:00
"""

############################################################
Expand Down Expand Up @@ -359,15 +359,15 @@
admin__samfundet_recruitmentposition_delete = 'admin:samfundet_recruitmentposition_delete'
admin__samfundet_recruitmentposition_change = 'admin:samfundet_recruitmentposition_change'
adminsamfundetrecruitmentposition__objectId = ''
admin__samfundet_recruitmentadmission_permissions = 'admin:samfundet_recruitmentadmission_permissions'
admin__samfundet_recruitmentadmission_permissions_manage_user = 'admin:samfundet_recruitmentadmission_permissions_manage_user'
admin__samfundet_recruitmentadmission_permissions_manage_group = 'admin:samfundet_recruitmentadmission_permissions_manage_group'
admin__samfundet_recruitmentadmission_changelist = 'admin:samfundet_recruitmentadmission_changelist'
admin__samfundet_recruitmentadmission_add = 'admin:samfundet_recruitmentadmission_add'
admin__samfundet_recruitmentadmission_history = 'admin:samfundet_recruitmentadmission_history'
admin__samfundet_recruitmentadmission_delete = 'admin:samfundet_recruitmentadmission_delete'
admin__samfundet_recruitmentadmission_change = 'admin:samfundet_recruitmentadmission_change'
adminsamfundetrecruitmentadmission__objectId = ''
admin__samfundet_recruitmentapplication_permissions = 'admin:samfundet_recruitmentapplication_permissions'
admin__samfundet_recruitmentapplication_permissions_manage_user = 'admin:samfundet_recruitmentapplication_permissions_manage_user'
admin__samfundet_recruitmentapplication_permissions_manage_group = 'admin:samfundet_recruitmentapplication_permissions_manage_group'
admin__samfundet_recruitmentapplication_changelist = 'admin:samfundet_recruitmentapplication_changelist'
admin__samfundet_recruitmentapplication_add = 'admin:samfundet_recruitmentapplication_add'
admin__samfundet_recruitmentapplication_history = 'admin:samfundet_recruitmentapplication_history'
admin__samfundet_recruitmentapplication_delete = 'admin:samfundet_recruitmentapplication_delete'
admin__samfundet_recruitmentapplication_change = 'admin:samfundet_recruitmentapplication_change'
adminsamfundetrecruitmentapplication__objectId = ''
admin__samfundet_organization_permissions = 'admin:samfundet_organization_permissions'
admin__samfundet_organization_permissions_manage_user = 'admin:samfundet_organization_permissions_manage_user'
admin__samfundet_organization_permissions_manage_group = 'admin:samfundet_organization_permissions_manage_group'
Expand Down Expand Up @@ -545,12 +545,13 @@
samfundet__active_recruitments = 'samfundet:active_recruitments'
samfundet__recruitment_positions = 'samfundet:recruitment_positions'
samfundet__recruitment_positions_gang = 'samfundet:recruitment_positions_gang'
samfundet__recruitment_admission_states_choices = 'samfundet:recruitment_admission_states_choices'
samfundet__recruitment_admission_update_state_gang = 'samfundet:recruitment_admission_update_state_gang'
samfundet__recruitment_admission_update_state_position = 'samfundet:recruitment_admission_update_state_position'
samfundet__recruitment_admissions_recruiter = 'samfundet:recruitment_admissions_recruiter'
samfundet__recruitment_withdraw_admission = 'samfundet:recruitment_withdraw_admission'
samfundet__recruitment_application_states_choices = 'samfundet:recruitment_application_states_choices'
samfundet__recruitment_application_update_state_gang = 'samfundet:recruitment_application_update_state_gang'
samfundet__recruitment_application_update_state_position = 'samfundet:recruitment_application_update_state_position'
samfundet__recruitment_applications_recruiter = 'samfundet:recruitment_applications_recruiter'
samfundet__recruitment_withdraw_application = 'samfundet:recruitment_withdraw_application'
samfundet__recruitment_user_priority_update = 'samfundet:recruitment_user_priority_update'
samfundet__recruitment_withdraw_application_recruiter = 'samfundet:recruitment_withdraw_application_recruiter'
samfundet__active_recruitment_positions = 'samfundet:active_recruitment_positions'
samfundet__applicants_without_interviews = 'samfundet:applicants_without_interviews/'
samfundet__recruitment_download_gang_admission_csv = 'samfundet:recruitment_download_gang_admission_csv'
Expand Down
39 changes: 20 additions & 19 deletions backend/samfundet/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from django.contrib.sessions.models import Session
from django.contrib.contenttypes.models import ContentType

from root.utils.routes import admin__samfundet_gang_change, admin__samfundet_recruitmentadmission_change
from root.utils.routes import admin__samfundet_gang_change, admin__samfundet_recruitmentapplication_change
from root.custom_classes.admin_classes import (
CustomBaseAdmin,
CustomGuardedUserAdmin,
Expand Down Expand Up @@ -58,8 +58,8 @@
InterviewRoom,
OccupiedTimeslot,
RecruitmentPosition,
RecruitmentAdmission,
RecruitmentStatistics,
RecruitmentApplication,
RecruitmentSeperatePosition,
RecruitmentInterviewAvailability,
)
Expand Down Expand Up @@ -620,22 +620,22 @@ class RecruitmentSeperatePositionAdmin(CustomBaseAdmin):
list_display_links = ['name_nb']


class RecruitmentAdmissionInline(admin.TabularInline):
class RecruitmentApplicationInline(admin.TabularInline):
"""
Inline admin interface for RecruitmentAdmission.
Inline admin interface for RecruitmentApplication.
Displays a link to the detailed admin page of each admission along with its user and applicant priority.
Displays a link to the detailed admin page of each application along with its user and applicant priority.
"""

model = RecruitmentAdmission
model = RecruitmentApplication
extra = 0
readonly_fields = ['linked_admission_text', 'user', 'applicant_priority']
fields = ['linked_admission_text', 'user', 'applicant_priority']
readonly_fields = ['linked_application_text', 'user', 'applicant_priority']
fields = ['linked_application_text', 'user', 'applicant_priority']

def linked_admission_text(self, obj: RecruitmentAdmission) -> str:
"""Returns a clickable link leading to the admin change page of the RecruitmentAdmission instance."""
url = reverse(admin__samfundet_recruitmentadmission_change, args=[obj.pk])
return format_html('<a href="{url}">{obj}</a>', url=url, obj=obj.admission_text)
def linked_application_text(self, obj: RecruitmentApplication) -> str:
"""Returns a clickable link leading to the admin change page of the RecruitmentApplication instance."""
url = reverse(admin__samfundet_recruitmentapplication_change, args=[obj.pk])
return format_html('<a href="{url}">{obj}</a>', url=url, obj=obj.application_text)


@admin.register(RecruitmentPosition)
Expand All @@ -646,20 +646,21 @@ class RecruitmentPositionAdmin(CustomBaseAdmin):
'gang',
'id',
]
list_display = ['id', 'name_nb', 'is_funksjonaer_position', 'gang', 'admissions_count']
list_display = ['id', 'name_nb', 'is_funksjonaer_position', 'gang', 'applications_count']
search_fields = ['id', 'name_nb', 'is_funksjonaer_position', 'gang']
filter_horizontal = ['interviewers']
list_select_related = True

list_display_links = ['id']
inlines = [RecruitmentAdmissionInline]
inlines = [RecruitmentApplicationInline]

def admissions_count(self, obj: RecruitmentPosition) -> int:
count = obj.admissions.all().count()
def applications_count(self, obj: RecruitmentPosition) -> int:
count = obj.applications.all().count()
return count


@admin.register(RecruitmentAdmission)
class RecruitmentAdmissionAdmin(CustomBaseAdmin):
@admin.register(RecruitmentApplication)
class RecruitmentApplicationAdmin(CustomBaseAdmin):
sortable_by = [
'recruitment_position',
'recruitment',
Expand Down Expand Up @@ -713,7 +714,7 @@ def update_stats(modeladmin: CustomBaseAdmin, request: HttpRequest, queryset: Qu

@admin.register(RecruitmentStatistics)
class RecruitmentStatisticsAdmin(CustomGuardedModelAdmin):
list_display = ['recruitment', 'total_applicants', 'total_admissions']
list_display = ['recruitment', 'total_applicants', 'total_applications']
search_fields = ['recruitment']
actions = [update_stats]

Expand Down
Loading

0 comments on commit cb52939

Please sign in to comment.