-
Notifications
You must be signed in to change notification settings - Fork 2
/
admin_base.py
83 lines (64 loc) · 2.57 KB
/
admin_base.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
# -*- encoding: UTF-8 -*-
#
# Copyright 2014-2015
#
# STIC-Investigación - Universidad de La Laguna (ULL) <[email protected]>
#
# This file is part of CVN.
#
# CVN is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# CVN is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with CVN. If not, see
# <http://www.gnu.org/licenses/>.
#
from .forms import UserProfileAdminForm, UploadCVNForm
from .models import OldCvnPdf, CVN
from core.widgets import FileFieldURLWidget
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
class OldCvnPdfInline(admin.TabularInline):
model = OldCvnPdf
extra = 0
readonly_fields = ('uploaded_at', )
fields = ('cvn_file', 'uploaded_at')
def formfield_for_dbfield(self, db_field, **kwargs):
if db_field.name == 'cvn_file':
kwargs['widget'] = FileFieldURLWidget
return super(OldCvnPdfInline, self).formfield_for_dbfield(
db_field, **kwargs)
def has_add_permission(self, request):
return False
def has_delete_permission(self, request, obj=None):
return False
class BaseUserProfileAdmin(admin.ModelAdmin):
form = UserProfileAdminForm
list_display = ('user', 'get_first_name', 'get_last_name', 'documento',
'rrhh_code', )
list_filter = ('cvn__status', 'cvn__is_inserted', )
def get_first_name(self, obj):
return obj.user.first_name
get_first_name.short_description = _("Name")
def get_last_name(self, obj):
return obj.user.last_name
get_last_name.short_description = _("Surname")
search_fields = ['user__username', 'documento', 'rrhh_code',
'user__first_name', 'user__last_name', ]
def has_add_permission(self, request):
return False
class BaseCvnInline(admin.TabularInline):
model = CVN
form = UploadCVNForm
fields = ('cvn_file', 'xml_file', 'fecha', 'uploaded_at', 'status',
'is_inserted')
readonly_fields = ('fecha', 'uploaded_at', 'status', 'is_inserted')
def has_delete_permission(self, request, obj=None):
return False