110 lines
4.0 KiB
Python
110 lines
4.0 KiB
Python
from django.contrib import messages
|
|
from . import models
|
|
from .utils import extract_summary_from_pdf
|
|
|
|
from django.contrib import admin
|
|
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
|
|
from django.contrib.auth.admin import GroupAdmin as BaseGroupAdmin
|
|
from django.contrib.auth.models import User, Group
|
|
from .models import FormTemplate, FormStage, FormField, FormSubmission, FieldResponse
|
|
from unfold.forms import AdminPasswordChangeForm, UserChangeForm, UserCreationForm
|
|
from unfold.admin import ModelAdmin
|
|
|
|
|
|
admin.site.unregister(User)
|
|
admin.site.unregister(Group)
|
|
|
|
|
|
@admin.register(User)
|
|
class UserAdmin(BaseUserAdmin, ModelAdmin):
|
|
form = UserChangeForm
|
|
add_form = UserCreationForm
|
|
change_password_form = AdminPasswordChangeForm
|
|
|
|
|
|
@admin.register(Group)
|
|
class GroupAdmin(BaseGroupAdmin, ModelAdmin):
|
|
pass
|
|
|
|
|
|
@admin.register(models.Job)
|
|
class JobAdmin(ModelAdmin):
|
|
list_display = ('title', 'is_published', 'posted_to_linkedin', 'created_at')
|
|
list_filter = ('is_published', 'posted_to_linkedin')
|
|
search_fields = ('title', 'description_en', 'description_ar')
|
|
|
|
@admin.action(description="Parse selected resumes")
|
|
def parse_resumes(modeladmin, request, queryset):
|
|
for candidate in queryset:
|
|
if candidate.resume:
|
|
summary = extract_summary_from_pdf(candidate.resume.path)
|
|
candidate.parsed_summary = str(summary)
|
|
candidate.save()
|
|
messages.success(request, f"Parsed {queryset.count()} resumes successfully.")
|
|
|
|
@admin.register(models.Candidate)
|
|
class CandidateAdmin(ModelAdmin):
|
|
list_display = ('first_name','last_name','phone', 'email', 'job', 'applied', 'created_at')
|
|
list_filter = ('applied', 'job')
|
|
search_fields = ('name', 'email')
|
|
# readonly_fields = ('parsed_summary',)
|
|
actions = [parse_resumes]
|
|
|
|
@admin.register(models.TrainingMaterial)
|
|
class TrainingMaterialAdmin(ModelAdmin):
|
|
list_display = ('title', 'created_by', 'created_at')
|
|
search_fields = ('title', 'content')
|
|
|
|
|
|
class FormFieldInline(admin.TabularInline):
|
|
model = FormField
|
|
extra = 0
|
|
fields = ('label', 'field_type', 'required', 'order', 'is_predefined')
|
|
ordering = ('order',)
|
|
|
|
class FormStageInline(admin.TabularInline):
|
|
model = FormStage
|
|
extra = 0
|
|
fields = ('name', 'order', 'is_predefined')
|
|
ordering = ('order',)
|
|
inlines = [FormFieldInline]
|
|
|
|
@admin.register(FormTemplate)
|
|
class FormTemplateAdmin(admin.ModelAdmin):
|
|
list_display = ('name', 'created_by', 'created_at', 'is_active', 'get_stage_count')
|
|
list_filter = ('is_active', 'created_at', 'created_by')
|
|
search_fields = ('name', 'description', 'created_by__username')
|
|
inlines = [FormStageInline]
|
|
readonly_fields = ('created_at', 'updated_at')
|
|
|
|
def get_stage_count(self, obj):
|
|
return obj.get_stage_count()
|
|
get_stage_count.short_description = 'Stages'
|
|
|
|
@admin.register(FormStage)
|
|
class FormStageAdmin(admin.ModelAdmin):
|
|
list_display = ('name', 'template', 'order', 'is_predefined')
|
|
list_filter = ('is_predefined', 'template')
|
|
search_fields = ('name', 'template__name')
|
|
ordering = ('template', 'order')
|
|
|
|
@admin.register(FormField)
|
|
class FormFieldAdmin(admin.ModelAdmin):
|
|
list_display = ('label', 'field_type', 'stage', 'required', 'order', 'is_predefined')
|
|
list_filter = ('field_type', 'required', 'is_predefined', 'stage__template')
|
|
search_fields = ('label', 'stage__name', 'stage__template__name')
|
|
ordering = ('stage', 'order')
|
|
|
|
@admin.register(FormSubmission)
|
|
class FormSubmissionAdmin(admin.ModelAdmin):
|
|
list_display = ('template', 'applicant_name', 'applicant_email', 'submitted_at')
|
|
list_filter = ('submitted_at', 'template')
|
|
search_fields = ('applicant_name', 'applicant_email', 'template__name')
|
|
readonly_fields = ('submitted_at',)
|
|
|
|
@admin.register(FieldResponse)
|
|
class FieldResponseAdmin(admin.ModelAdmin):
|
|
list_display = ('field', 'submission', 'display_value')
|
|
list_filter = ('field__field_type', 'submission__template')
|
|
search_fields = ('field__label', 'submission__applicant_name')
|
|
readonly_fields = ('display_value',) |