80 lines
2.2 KiB
Python
80 lines
2.2 KiB
Python
from django.contrib import admin, messages
|
|
|
|
from vbv_lernwelt.learning_mentor.models import (
|
|
AgentParticipantRelation,
|
|
MentorInvitation,
|
|
OrganisationSupervisor,
|
|
OrganisationSupervisortRoleType,
|
|
)
|
|
from vbv_lernwelt.learning_mentor.services import (
|
|
create_or_sync_ausbildungsverantwortlicher,
|
|
create_or_sync_berufsbildner,
|
|
)
|
|
|
|
|
|
@admin.action(description="Organisation Supervisor: Sync")
|
|
def create_or_sync_org_supervisor(_modeladmin, request, queryset):
|
|
success = []
|
|
for supervisor in queryset:
|
|
sync_fn = (
|
|
create_or_sync_berufsbildner
|
|
if supervisor.role == OrganisationSupervisortRoleType.BERUFSBILDNER.value
|
|
else create_or_sync_ausbildungsverantwortlicher
|
|
)
|
|
success.append(sync_fn(supervisor.supervisor, supervisor.organisation))
|
|
if all(success):
|
|
messages.add_message(
|
|
request,
|
|
messages.SUCCESS,
|
|
"Organisation Supervisor synchronisiert",
|
|
)
|
|
else:
|
|
messages.add_message(
|
|
request,
|
|
messages.ERROR,
|
|
"Einige Organisation Supervisors konnten nicht synchronisiert werden",
|
|
)
|
|
|
|
|
|
@admin.register(AgentParticipantRelation)
|
|
class TrainerParticipantRelationAdmin(admin.ModelAdmin):
|
|
list_display = ["agent", "participant", "role"]
|
|
|
|
search_fields = [
|
|
"agent__email",
|
|
"agent__first_name",
|
|
"agent__last_name",
|
|
"participant__user__email",
|
|
"participant__user__first_name",
|
|
"participant__user__last_name",
|
|
]
|
|
|
|
raw_id_fields = [
|
|
"agent",
|
|
"participant",
|
|
# "course_session",
|
|
]
|
|
|
|
list_filter = ["role"]
|
|
|
|
|
|
@admin.register(MentorInvitation)
|
|
class MentorInvitationAdmin(admin.ModelAdmin):
|
|
list_display = ["id", "email", "participant", "created"]
|
|
readonly_fields = ["id", "created", "email", "participant"]
|
|
search_fields = ["email"]
|
|
|
|
|
|
@admin.register(OrganisationSupervisor)
|
|
class OrganisationSupervisorAdmin(admin.ModelAdmin):
|
|
list_display = ["supervisor", "organisation", "role"]
|
|
|
|
search_fields = ["supervisor"]
|
|
|
|
raw_id_fields = [
|
|
"supervisor",
|
|
]
|
|
|
|
list_filter = ["role", "organisation"]
|
|
actions = [create_or_sync_org_supervisor]
|