-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathadmin.py
executable file
·218 lines (173 loc) · 8.32 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
from .models import *
from import_export import resources, fields
from import_export.widgets import ForeignKeyWidget
from import_export.admin import ImportExportModelAdmin, ExportMixin
from tola.util import getCountry
from admin_report.mixins import ChartReportAdmin
# Resource for CSV export
class DocumentationResource(resources.ModelResource):
country = fields.Field(column_name='country', attribute='country', widget=ForeignKeyWidget(Country, 'country'))
program = fields.Field(column_name='program', attribute='program', widget=ForeignKeyWidget(Program, 'name'))
project = fields.Field(column_name='project', attribute='project', widget=ForeignKeyWidget(ProjectAgreement, 'project_name'))
class Meta:
model = Documentation
widgets = {
'create_date': {'format': '%d/%m/%Y'},
'edit_date': {'format': '%d/%m/%Y'},
'expected_start_date': {'format': '%d/%m/%Y'},
}
class DocumentationAdmin(ImportExportModelAdmin):
resource_class = DocumentationResource
list_display = ('program','project')
list_filter = ('program__country',)
pass
# Resource for CSV export
class ProjectAgreementResource(resources.ModelResource):
class Meta:
model = ProjectAgreement
widgets = {
'create_date': {'format': '%d/%m/%Y'},
'edit_date': {'format': '%d/%m/%Y'},
'expected_start_date': {'format': '%d/%m/%Y'},
'expected_end_date': {'format': '%d/%m/%Y'},
}
class ProjectAgreementAdmin(ImportExportModelAdmin):
resource_class = ProjectAgreementResource
list_display = ('program','project_name','short','create_date')
list_filter = ('program__country','short')
filter_horizontal = ('capacity','evaluate','site','stakeholder')
def queryset(self, request, queryset):
"""
Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`.
"""
# Filter by logged in users allowable countries
user_countries = getCountry(request.user)
#if not request.user.user.is_superuser:
return queryset.filter(country__in=user_countries)
pass
# Resource for CSV export
class ProjectCompleteResource(resources.ModelResource):
class Meta:
model = ProjectComplete
widgets = {
'create_date': {'format': '%d/%m/%Y'},
'edit_date': {'format': '%d/%m/%Y'},
'expected_start_date': {'format': '%d/%m/%Y'},
'expected_end_date': {'format': '%d/%m/%Y'},
'actual_start_date': {'format': '%d/%m/%Y'},
'actual_end_date': {'format': '%d/%m/%Y'},
}
class ProjectCompleteAdmin(ImportExportModelAdmin):
resource_class = ProjectCompleteResource
list_display = ('program', 'project_name', 'activity_code','short','create_date')
list_filter = ('program__country', 'office', 'short')
display = 'project_name'
def queryset(self, request, queryset):
"""
Returns the filtered queryset based on the value
provided in the query string and retrievable via
`self.value()`.
"""
# Filter by logged in users allowable countries
user_countries = getCountry(request.user)
#if not request.user.user.is_superuser:
return queryset.filter(country__in=user_countries)
pass
# Resource for CSV export
class CountryResource(resources.ModelResource):
class Meta:
model = Country
class CountryAdmin(ImportExportModelAdmin):
resource_class = CountryResource
list_display = ('country','code','organization','create_date', 'edit_date')
list_filter = ('country','organization__name')
# Resource for CSV export
class SiteProfileResource(resources.ModelResource):
country = fields.Field(column_name='country', attribute='country', widget=ForeignKeyWidget(Country, 'country'))
type = fields.Field(column_name='type', attribute='type', widget=ForeignKeyWidget(ProfileType, 'profile'))
office = fields.Field(column_name='office', attribute='office', widget=ForeignKeyWidget(Office, 'code'))
district = fields.Field(column_name='admin level 2', attribute='district', widget=ForeignKeyWidget(District, 'name'))
province = fields.Field(column_name='admin level 1', attribute='province', widget=ForeignKeyWidget(Province, 'name'))
admin_level_three = fields.Field(column_name='admin level 3', attribute='admin_level_three', widget=ForeignKeyWidget(AdminLevelThree, 'name'))
class Meta:
model = SiteProfile
skip_unchanged = True
report_skipped = False
#import_id_fields = ['id']
class SiteProfileAdmin(ImportExportModelAdmin):
resource_class = SiteProfileResource
list_display = ('name','office', 'country', 'province','district','admin_level_three','village')
list_filter = ('country__country',)
search_fields = ('office__code','country__country')
pass
class ProgramAdmin(admin.ModelAdmin):
list_display = ('countries','name','gaitid', 'description','budget_check','funding_status')
search_fields = ('name','gaitid')
list_filter = ('funding_status','country','budget_check','funding_status')
display = 'Program'
class ApprovalAuthorityAdmin(admin.ModelAdmin):
list_display = ('approval_user','budget_limit','fund','country')
display = 'Approval Authority'
search_fields = ('approval_user__user__first_name', 'approval_user__user__last_name', 'country__country')
list_filter = ('create_date','country')
class StakeholderAdmin(ImportExportModelAdmin):
list_display = ('name', 'type', 'country', 'approval', 'approved_by', 'filled_by', 'create_date')
display = 'Stakeholder List'
list_filter = ('country', 'type')
class TolaUserProxyResource(resources.ModelResource):
country = fields.Field(column_name='country', attribute='country', widget=ForeignKeyWidget(Country, 'country'))
user = fields.Field(column_name='user', attribute='user', widget=ForeignKeyWidget(User, 'username'))
email = fields.Field()
def dehydrate_email(self, user):
return '%s' % (user.user.email)
class Meta:
model = TolaUserProxy
fields = ('title', 'name', 'user','country','create_date', 'email' )
export_order = ('title', 'name', 'user','country','email','create_date')
class ReportTolaUserProxyAdmin(ChartReportAdmin, ExportMixin, admin.ModelAdmin ):
resource_class = TolaUserProxyResource
def get_queryset(self, request):
qs = super(ReportTolaUserProxyAdmin, self).get_queryset(request)
return qs.filter(user__is_active= True)
list_display = ('title','name', 'user','email', 'country', 'create_date')
list_filter = ('country', 'create_date', 'user__is_staff')
def email(self, data):
auth_users = User.objects.all()
for a_user in auth_users:
if data.user == a_user:
email = a_user.email
return email
admin.site.register(Organization, OrganizationAdmin)
admin.site.register(Country, CountryAdmin)
admin.site.register(Province, ProvinceAdmin)
admin.site.register(Office, OfficeAdmin)
admin.site.register(District, DistrictAdmin)
admin.site.register(AdminLevelThree, AdminLevelThreeAdmin)
admin.site.register(Village)
admin.site.register(Program, ProgramAdmin)
admin.site.register(Sector)
admin.site.register(ProjectAgreement, ProjectAgreementAdmin)
admin.site.register(ProjectComplete, ProjectCompleteAdmin)
admin.site.register(Documentation,DocumentationAdmin)
admin.site.register(Template)
admin.site.register(SiteProfile, SiteProfileAdmin)
admin.site.register(Capacity)
admin.site.register(Monitor)
admin.site.register(Benchmarks)
admin.site.register(Evaluate)
admin.site.register(ProjectType, ProjectTypeAdmin)
admin.site.register(Budget)
admin.site.register(ProfileType)
admin.site.register(ApprovalAuthority, ApprovalAuthorityAdmin)
admin.site.register(ChecklistItem, ChecklistItemAdmin)
admin.site.register(Checklist, ChecklistAdmin)
admin.site.register(Stakeholder, StakeholderAdmin)
admin.site.register(Contact, ContactAdmin)
admin.site.register(StakeholderType)
admin.site.register(TolaUser,TolaUserAdmin)
admin.site.register(TolaSites,TolaSitesAdmin)
admin.site.register(FormGuidance,FormGuidanceAdmin)
admin.site.register(TolaUserProxy, ReportTolaUserProxyAdmin)
admin.site.register(TolaBookmarks, TolaBookmarksAdmin)