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-11 13:02:26 +05:30
|
|
|
from simple_history.admin import SimpleHistoryAdmin
|
|
|
|
from import_export.admin import ImportExportMixin, ExportMixin
|
|
|
|
from import_export import resources
|
|
|
|
|
2021-12-12 19:14:27 +05:30
|
|
|
from .models import *
|
2023-07-29 17:39:34 +05:30
|
|
|
from .utils import send_email_for_opening
|
2021-10-15 20:47:23 +05:30
|
|
|
|
2022-09-12 11:24:50 +05:30
|
|
|
|
|
|
|
class ArrayFieldListFilter(admin.SimpleListFilter):
|
|
|
|
"""This is a list filter based on the values
|
|
|
|
from a model's `keywords` ArrayField. """
|
|
|
|
|
|
|
|
title = 'Roles'
|
|
|
|
parameter_name = 'user_type'
|
|
|
|
|
|
|
|
def lookups(self, request, model_admin):
|
|
|
|
# Very similar to our code above, but this method must return a
|
|
|
|
# list of tuples: (lookup_value, human-readable value). These
|
|
|
|
# appear in the admin's right sidebar
|
|
|
|
|
|
|
|
keywords = User.objects.values_list("user_type", flat=True)
|
|
|
|
keywords = [(kw, kw) for sublist in keywords for kw in sublist if kw]
|
|
|
|
keywords = sorted(set(keywords))
|
|
|
|
return keywords
|
|
|
|
|
|
|
|
def queryset(self, request, queryset):
|
|
|
|
# when a user clicks on a filter, this method gets called. The
|
|
|
|
# provided queryset with be a queryset of Items, so we need to
|
|
|
|
# filter that based on the clicked keyword.
|
|
|
|
|
|
|
|
lookup_value = self.value() # The clicked keyword. It can be None!
|
|
|
|
if lookup_value:
|
|
|
|
# the __contains lookup expects a list, so...
|
|
|
|
queryset = queryset.filter(user_type__contains=[lookup_value])
|
|
|
|
return queryset
|
|
|
|
|
|
|
|
|
2022-08-11 13:02:26 +05:30
|
|
|
class UserAdmin(ImportExportMixin, SimpleHistoryAdmin):
|
2022-09-12 11:24:50 +05:30
|
|
|
list_display = ('email', 'user_type', 'last_login_time')
|
|
|
|
list_filter = (ArrayFieldListFilter, 'last_login_time')
|
|
|
|
search_fields = ('email', 'user_type')
|
|
|
|
ordering = ('email', 'user_type')
|
2022-08-11 13:02:26 +05:30
|
|
|
|
2022-09-12 11:24:50 +05:30
|
|
|
|
|
|
|
admin.site.register(User, UserAdmin)
|
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-11 13:02:26 +05:30
|
|
|
class StudentAdmin(ImportExportMixin, SimpleHistoryAdmin):
|
|
|
|
pass
|
|
|
|
|
2022-09-12 11:26:09 +05:30
|
|
|
|
2021-12-12 19:14:27 +05:30
|
|
|
@admin.register(Student)
|
2022-08-11 13:02:26 +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
|
|
|
|
2022-08-11 13:02:26 +05:30
|
|
|
class PlacementResources(resources.ModelResource):
|
|
|
|
class Meta:
|
|
|
|
model = Placement
|
2024-06-04 15:02:15 +05:30
|
|
|
exclude = ('changed_by', 'is_company_details_pdf', 'is_description_pdf',
|
2022-08-11 13:02:26 +05:30
|
|
|
'is_compensation_details_pdf', 'is_selection_procedure_details_pdf')
|
|
|
|
class AdminAdmin(ExportMixin, SimpleHistoryAdmin):
|
|
|
|
resource_class = PlacementResources
|
|
|
|
|
2021-12-12 19:14:27 +05:30
|
|
|
|
2022-09-12 11:24:50 +05:30
|
|
|
class PlacementResources(resources.ModelResource):
|
|
|
|
class Meta:
|
|
|
|
model = Placement
|
2024-06-04 15:02:15 +05:30
|
|
|
exclude = ( 'changed_by', 'is_company_details_pdf', 'is_description_pdf',
|
2022-09-12 11:24:50 +05:30
|
|
|
'is_compensation_details_pdf', 'is_selection_procedure_details_pdf')
|
|
|
|
|
|
|
|
|
|
|
|
class AdminAdmin(ExportMixin, SimpleHistoryAdmin):
|
|
|
|
resource_class = PlacementResources
|
|
|
|
|
|
|
|
|
2022-09-12 11:26:09 +05:30
|
|
|
class PlacementResources(resources.ModelResource):
|
|
|
|
class Meta:
|
|
|
|
model = Placement
|
2024-06-04 15:02:15 +05:30
|
|
|
exclude = ('changed_by', 'is_company_details_pdf', 'is_description_pdf',
|
2022-09-12 11:26:09 +05:30
|
|
|
'is_compensation_details_pdf', 'is_selection_procedure_details_pdf')
|
|
|
|
|
|
|
|
|
|
|
|
class AdminAdmin(ExportMixin, SimpleHistoryAdmin):
|
|
|
|
resource_class = PlacementResources
|
|
|
|
|
2023-07-29 17:39:34 +05:30
|
|
|
def save_model(self, request, obj, form, change):
|
|
|
|
# Check if email_verified field is being changed from False to True
|
|
|
|
if change and not obj._state.adding and obj.email_verified and form.initial.get('email_verified', False) != obj.email_verified:
|
|
|
|
# Run the send_email_for_opening function
|
|
|
|
send_email_for_opening(obj)
|
|
|
|
|
|
|
|
# Save the model as usual
|
|
|
|
super().save_model(request, obj, form, change)
|
|
|
|
|
|
|
|
|
2022-09-12 11:26:09 +05:30
|
|
|
|
2021-12-12 19:14:27 +05:30
|
|
|
@admin.register(Placement)
|
2022-08-11 13:02:26 +05:30
|
|
|
class Placement(AdminAdmin):
|
2023-08-05 02:10:41 +05:30
|
|
|
list_display = (COMPANY_NAME, DESIGNATION , CONTACT_PERSON_NAME, PHONE_NUMBER, 'tier', 'compensation_CTC', 'email_verified', 'updated_at')
|
2021-12-12 19:14:27 +05:30
|
|
|
search_fields = (COMPANY_NAME, CONTACT_PERSON_NAME)
|
2023-08-02 23:29:04 +05:30
|
|
|
ordering = ('updated_at', COMPANY_NAME, CONTACT_PERSON_NAME, 'tier', 'compensation_CTC')
|
2021-12-12 19:14:27 +05:30
|
|
|
list_filter = ('tier',)
|
|
|
|
|
|
|
|
|
2022-08-11 13:02:26 +05:30
|
|
|
class PlacementApplicationResources(resources.ModelResource):
|
|
|
|
class Meta:
|
|
|
|
model = PlacementApplication
|
|
|
|
exclude = ('id', 'changed_by')
|
|
|
|
|
2022-09-12 11:26:09 +05:30
|
|
|
|
2022-08-11 13:02:26 +05:30
|
|
|
class PlacementAdmin(ExportMixin, SimpleHistoryAdmin):
|
|
|
|
resource_class = PlacementApplicationResources
|
|
|
|
|
2023-10-03 01:47:26 +05:30
|
|
|
class InternshipApplicationResources(resources.ModelResource):
|
|
|
|
class Meta:
|
|
|
|
model = InternshipApplication
|
|
|
|
exclude = ('id', 'changed_by')
|
|
|
|
class InternshipApplicationAdmin(ExportMixin, SimpleHistoryAdmin):
|
|
|
|
resource_class = InternshipApplicationResources
|
|
|
|
|
2022-09-12 11:24:50 +05:30
|
|
|
|
2021-12-16 23:05:04 +05:30
|
|
|
@admin.register(PlacementApplication)
|
2022-08-11 13:02:26 +05:30
|
|
|
class PlacementApplication(PlacementAdmin):
|
2021-12-16 23:05:04 +05:30
|
|
|
list_display = ('id', 'Placement', 'Student', 'selected')
|
2023-10-19 04:19:49 +05:30
|
|
|
search_fields = ('id',)
|
|
|
|
ordering = ('id',)
|
2021-12-16 23:05:04 +05:30
|
|
|
list_filter = ('selected',)
|
|
|
|
|
|
|
|
def Placement(self, obj):
|
|
|
|
return model_admin_url(obj.placement)
|
|
|
|
|
|
|
|
def Student(self, obj):
|
|
|
|
return model_admin_url(obj.student)
|
2023-10-03 01:47:26 +05:30
|
|
|
@admin.register(InternshipApplication)
|
|
|
|
class InternshipApplication(InternshipApplicationAdmin):
|
|
|
|
list_display = ('id', 'Internship', 'Student', 'selected')
|
2023-10-19 04:19:49 +05:30
|
|
|
search_fields = ('id',)
|
|
|
|
ordering = ('id',)
|
2023-10-03 01:47:26 +05:30
|
|
|
list_filter = ('selected',)
|
2021-12-16 23:05:04 +05:30
|
|
|
|
2023-10-03 01:47:26 +05:30
|
|
|
def Internship(self, obj):
|
|
|
|
return model_admin_url(obj.internship)
|
|
|
|
|
|
|
|
def Student(self, obj):
|
|
|
|
return model_admin_url(obj.student)
|
2021-12-12 19:14:27 +05:30
|
|
|
|
2022-08-11 13:02:26 +05:30
|
|
|
class PrePlacementResources(resources.ModelResource):
|
|
|
|
class Meta:
|
|
|
|
model = PrePlacementOffer
|
|
|
|
exclude = ('id', 'changed_by')
|
|
|
|
|
2022-09-12 11:26:09 +05:30
|
|
|
|
2022-08-11 13:02:26 +05:30
|
|
|
class PrePlacementOfferAdmin(ExportMixin, SimpleHistoryAdmin):
|
|
|
|
resource_class = PrePlacementResources
|
|
|
|
|
2022-09-12 11:24:50 +05:30
|
|
|
|
2022-05-01 22:51:14 +05:30
|
|
|
@admin.register(PrePlacementOffer)
|
2022-08-11 13:02:26 +05:30
|
|
|
class PrePlacementOffer(PrePlacementOfferAdmin):
|
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)
|
2023-07-24 19:00:52 +05:30
|
|
|
|
2023-08-01 16:33:36 +05:30
|
|
|
|
|
|
|
class InternshipResources(resources.ModelResource):
|
|
|
|
class Meta:
|
|
|
|
model = Internship
|
|
|
|
exclude = ('id', 'changed_by', 'is_company_details_pdf', 'is_description_pdf',
|
2023-10-03 01:47:26 +05:30
|
|
|
'is_stipend_details_pdf', 'is_selection_procedure_details_pdf')
|
2023-08-01 16:33:36 +05:30
|
|
|
|
|
|
|
|
|
|
|
class InternAdmin(ExportMixin, SimpleHistoryAdmin):
|
|
|
|
resource_class = InternshipResources
|
|
|
|
|
2023-08-02 17:02:40 +05:30
|
|
|
def save_model(self, request, obj, form, change):
|
|
|
|
# Check if email_verified field is being changed from False to True
|
|
|
|
if change and not obj._state.adding and obj.email_verified and form.initial.get('email_verified', False) != obj.email_verified:
|
|
|
|
# Run the send_email_for_opening function
|
|
|
|
send_email_for_opening(obj)
|
2023-08-01 16:33:36 +05:30
|
|
|
|
2023-08-02 17:02:40 +05:30
|
|
|
super().save_model(request, obj, form, change)
|
2023-08-01 16:33:36 +05:30
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Internship)
|
|
|
|
class Placement(InternAdmin):
|
2023-08-05 02:10:41 +05:30
|
|
|
list_display = (COMPANY_NAME, DESIGNATION, CONTACT_PERSON_NAME, PHONE_NUMBER, 'stipend', 'email_verified', 'updated_at')
|
2023-08-01 16:33:36 +05:30
|
|
|
search_fields = (COMPANY_NAME, CONTACT_PERSON_NAME)
|
2023-08-02 23:29:04 +05:30
|
|
|
ordering = ('updated_at', COMPANY_NAME, CONTACT_PERSON_NAME, 'stipend')
|
2023-08-01 16:33:36 +05:30
|
|
|
|
2023-10-03 17:46:31 +05:30
|
|
|
@admin.register(Issues)
|
|
|
|
class Issues(admin.ModelAdmin):
|
|
|
|
list_display = ('id', 'title', 'description')
|
|
|
|
search_fields = ('id', 'title', 'description')
|
|
|
|
ordering = ('id', 'title', 'description')
|
|
|
|
# list_filter = ('status',)
|
|
|
|
|
|
|
|
def Student(self, obj):
|
|
|
|
return model_admin_url(obj.student)
|