-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathadmin.py
96 lines (70 loc) · 2.81 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from django.contrib import admin
from django.apps import apps
# from graphql_auth.models import UserStatus
from django.contrib.auth.admin import UserAdmin
from django.core.mail import send_mail
from django.contrib.auth.models import User
from .models import Profile, UserLog
@admin.decorators.display(description="Verified", boolean=True)
def is_verified(obj):
return obj.status.verified
admin.site.site_title = "Petroly"
admin.site.index_title = "Administration"
admin.site.site_header = "Petroly Administration"
admin.site.login_template = "registration/login.html"
admin.site.unregister(User)
@admin.register(User)
class UserAdminCostom(UserAdmin):
"""Costom UserAdmin"""
actions = ["send_message_email", "create_status"]
list_display = ["username", "email", "is_staff", is_verified, "date_joined"]
@admin.action(description="Send them the message email")
def send_message_email(self, request, queryset):
with open("./templates/message_email.html", "r") as f:
html = f.read()
for user in queryset:
send_mail(
"مبادرة بترولي تشكرك",
message=None,
from_email="[email protected]",
html_message=html,
recipient_list=[
user.email,
],
)
print(user.email)
# @admin.action(description="Create a UserStatus object")
# def create_status(self, request, queryset):
# for user in queryset:
# try:
# obj = UserStatus.objects.get_or_create(user=user)
# print(obj)
# except Exception as e:
# print(e)
@admin.register(Profile)
class ProfileAdmin(admin.ModelAdmin):
list_display = ["user", "major", "year"]
search_fields = [
"user__username",
"user__email",
]
@admin.register(UserLog)
class UserLogAdmin(admin.ModelAdmin):
"""Custom admin for `UserLog` model class."""
list_display = ["ip", "updated_on", "created_on", "function"]
# app = apps.get_app_config('graphql_auth')
# for model_name, model in app.models.items():
# admin.site.register(model)
# @admin.register(UserStatus)
# class UserStatusAdmin(admin.ModelAdmin):
# list_display = ["user", "verified", "archived"]
# list_filter = ["verified"]
# actions = ["make_verified", "make_unverified", "make_archived", "make_unarchived"]
# def make_verified(self, request, queryset):
# queryset.update(verified=True)
# def make_unverified(self, request, queryset):
# queryset.update(verified=False)
# def make_archived(self, request, queryset):
# queryset.update(archived=True)
# def make_unarchived(self, request, queryset):
# queryset.update(archived=False)