Upgrades
[cas.git] / src / ftp / admin.py
1 from django.contrib import admin
2 from django.utils.safestring import mark_safe
3 from django.utils.translation import gettext as _
4 from . import models
5 from .utils import generate_password
6
7
8 @admin.register(models.FtpUser)
9 class FtpUserAdmin(admin.ModelAdmin):
10     fields = ['login', 'created_at', 'last_seen_at', 'password', 'password_set_at']
11     readonly_fields = ['created_at', 'last_seen_at', 'password_set_at']
12
13     def save_model(self, request, obj, form, change):
14         if not obj.password:
15             pwd = obj.set_password(save=False)
16             self.message_user(
17                 request,
18                 mark_safe(
19                     _('Password for <strong>%(login)s</strong> set to: <input disabled value="%(password)s">.') % {
20                         "login": obj.login,
21                         "password": pwd,
22                     }
23                 )
24             )
25         return super().save_model(request, obj, form, change)
26
27
28