2021-10-15 20:47:23 +05:30
|
|
|
from django.contrib import admin
|
2021-12-12 19:14:27 +05:30
|
|
|
from django.contrib.admin.templatetags.admin_urls import admin_urlname
|
|
|
|
from django.shortcuts import resolve_url
|
|
|
|
from django.utils.html import format_html
|
|
|
|
from django.utils.safestring import SafeText
|
2022-05-02 17:16:56 +05:30
|
|
|
|
2022-08-05 01:39:50 +05:30
|
|
|
from simple_history.admin import SimpleHistoryAdmin
|
|
|
|
from import_export.admin import ImportExportMixin
|
|
|
|
|
2021-12-12 19:14:27 +05:30
|
|
|
from .models import *
|
2021-10-15 20:47:23 +05:30
|
|
|
|
2022-08-05 01:39:50 +05:30
|
|
|
class UserAdmin(ImportExportMixin, SimpleHistoryAdmin):
|
|
|
|
pass
|
|
|
|
|
|
|
|
admin.site.register(User,UserAdmin)
|
2022-07-21 16:41:31 +05:30
|
|
|
admin.site.register(Admin, SimpleHistoryAdmin)
|
2022-05-01 22:51:14 +05:30
|
|
|
|
2021-12-12 19:14:27 +05:30
|
|
|
admin.site.site_header = "CDC Recruitment Portal"
|
|
|
|
|
|
|
|
|
|
|
|
def model_admin_url(obj, name=None) -> str:
|
|
|
|
url = resolve_url(admin_urlname(obj._meta, SafeText("change")), obj.pk)
|
|
|
|
return format_html('<a href="{}">{}</a>', url, name or str(obj))
|
|
|
|
|
|
|
|
|
2022-08-05 01:39:50 +05:30
|
|
|
class StudentAdmin(ImportExportMixin, SimpleHistoryAdmin):
|
|
|
|
pass
|
|
|
|
|
2021-12-12 19:14:27 +05:30
|
|
|
@admin.register(Student)
|
2022-08-05 01:39:50 +05:30
|
|
|
class Student(StudentAdmin):
|
2022-05-02 17:16:56 +05:30
|
|
|
list_display = ("roll_no", "name", "batch", "branch", "phone_number", 'can_apply')
|
|
|
|
search_fields = ("roll_no", "name", "phone_number")
|
2021-12-12 19:14:27 +05:30
|
|
|
ordering = ("roll_no", "name", "batch", "branch", "phone_number")
|
|
|
|
list_filter = ("batch", "branch")
|
2022-05-02 17:16:56 +05:30
|
|
|
actions = ['mark_can_apply_as_no', 'mark_can_apply_as_yes']
|
|
|
|
|
|
|
|
@admin.action(description="Deregister students")
|
|
|
|
def mark_can_apply_as_no(self, request, queryset):
|
|
|
|
queryset.update(can_apply=False)
|
|
|
|
self.message_user(request, "Deregistered the users")
|
|
|
|
|
|
|
|
@admin.action(description="Register students")
|
|
|
|
def mark_can_apply_as_yes(self, request, queryset):
|
|
|
|
queryset.update(can_apply=True)
|
|
|
|
self.message_user(request, "Registered the users")
|
2021-12-12 19:14:27 +05:30
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Placement)
|
2022-07-21 16:41:31 +05:30
|
|
|
class Placement(SimpleHistoryAdmin):
|
2021-12-12 19:14:27 +05:30
|
|
|
list_display = (COMPANY_NAME, CONTACT_PERSON_NAME, PHONE_NUMBER, 'tier', 'compensation_CTC')
|
|
|
|
search_fields = (COMPANY_NAME, CONTACT_PERSON_NAME)
|
|
|
|
ordering = (COMPANY_NAME, CONTACT_PERSON_NAME, 'tier', 'compensation_CTC')
|
|
|
|
list_filter = ('tier',)
|
|
|
|
|
|
|
|
|
2021-12-16 23:05:04 +05:30
|
|
|
@admin.register(PlacementApplication)
|
2022-07-21 16:41:31 +05:30
|
|
|
class PlacementApplication(SimpleHistoryAdmin):
|
2021-12-16 23:05:04 +05:30
|
|
|
list_display = ('id', 'Placement', 'Student', 'selected')
|
|
|
|
search_fields = ('id',)
|
|
|
|
ordering = ('id',)
|
|
|
|
list_filter = ('selected',)
|
|
|
|
|
|
|
|
def Placement(self, obj):
|
|
|
|
return model_admin_url(obj.placement)
|
|
|
|
|
|
|
|
def Student(self, obj):
|
|
|
|
return model_admin_url(obj.student)
|
|
|
|
|
2021-12-12 19:14:27 +05:30
|
|
|
|
2022-05-01 22:51:14 +05:30
|
|
|
@admin.register(PrePlacementOffer)
|
2022-07-21 16:41:31 +05:30
|
|
|
class PrePlacementOffer(SimpleHistoryAdmin):
|
2022-05-02 17:16:56 +05:30
|
|
|
list_display = ('company', 'Student', 'accepted')
|
2022-05-01 22:51:14 +05:30
|
|
|
search_fields = ('company',)
|
|
|
|
ordering = ('company',)
|
|
|
|
list_filter = ('accepted',)
|
|
|
|
|
|
|
|
def Student(self, obj):
|
|
|
|
return model_admin_url(obj.student)
|