-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathadmin.py
67 lines (62 loc) · 2.26 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from django.contrib import admin
from .models import User
from utility import export_as_csv
from .utility import mail_content, send_email_using_microservice
# Register your models here.
@admin.register(User)
class UserAdmin(admin.ModelAdmin):
"""
Custom admin class for User model.
"""
@admin.action(description='Lock Selected User')
def lock_user(self, request, queryset):
"""
Admin action to lock selected users.
"""
queryset.update(is_locked=True)
self.message_user(request, "Selected User Locked")
@admin.action(description='Resend Verification Mail')
def resend_mail(self, request, queryset):
"""
Admin action to resend verification mail to selected users.
"""
for obj in queryset:
anwesha_id = obj.anwesha_id
email = obj.email_id
fullname = obj.full_name
body = mail_content(type=1, email_id=email, anwesha_id=anwesha_id, full_name=fullname)
send_email_using_microservice(
email_id=email,
subject="No reply",
text=body
)
self.message_user(request, "Email sent again")
list_display = ('anwesha_id', 'full_name', 'email_id', 'collage_name')
actions = [lock_user, export_as_csv, resend_mail]
list_filter = ('user_type', 'is_locked', 'collage_name')
fieldsets = (
('Basic Information', {
'fields': (
'anwesha_id',
'full_name',
'email_id',
'phone_number',
'profile_photo',
('age', 'gender'),
'user_type'
)
}),
('Social Links', {
'fields': ('instagram_id', 'facebook_id', 'collage_name', 'qr_code')
}),
('Internal Flags', {
'fields': (
('accomadation_selected', 'is_profile_completed'),
('is_email_verified', 'is_locked', 'is_loggedin'),
'password',
('secret', 'signature')
)
})
)
empty_value_display = '-empty-'
search_fields = ['full_name', 'anwesha_id', 'email_id', 'phone_number', 'collage_name']