Blame view

src/core/pyros_django/common/admin.py 7.7 KB
eefbbbd2   Etienne Pallier   Model splitting g...
1
2

# Django imports
5ce2836f   Alexis Koralewski   update models (ad...
3
4
5
from django import forms
from django.contrib import admin
from django.contrib.auth.models import User
5ce2836f   Alexis Koralewski   update models (ad...
6
7
8
# EP
from django.conf import settings

eefbbbd2   Etienne Pallier   Model splitting g...
9
# Project imports
b95a693f   Alexis Koralewski   restructuration d...
10
from user_mgmt.models import Country, Institute, PyrosUser, UserLevel, ScientificProgram
5ce2836f   Alexis Koralewski   update models (ad...
11
from common.models import *
b95a693f   Alexis Koralewski   restructuration d...
12
13
from majordome.models import *
from env_monitor.models import *
bfe3fba1   Etienne Pallier   started common/mo...
14
from devices.models import Detector, Filter, AgentDeviceStatus, FilterWheel, Telescope, PlcDevice, PlcDeviceStatus
b95a693f   Alexis Koralewski   restructuration d...
15
16
from seq_submit.models import Image, Schedule, Sequence, Album, Plan, ScheduleHasSequences #, StrategyObs, NrtAnalysis
#from seq_submit.models import Image, StrategyObs, Schedule, Request, Alert, Sequence, Album, Plan, NrtAnalysis, ScheduleHasSequences
bfe3fba1   Etienne Pallier   started common/mo...
17

93039f18   Alexis Koralewski   Fix issues due to...
18
# MOVED TO DASHBOARD
5ce2836f   Alexis Koralewski   update models (ad...
19
20

# EP added
93039f18   Alexis Koralewski   Fix issues due to...
21
22
23
24
25
26
# class ReadOnlyModelAdmin(admin.ModelAdmin):
#     """ModelAdmin class that prevents modifications through the admin.
#     The changelist and the detail view work, but a 403 is returned
#     if one actually tries to edit an object.
#     Source: https://gist.github.com/aaugustin/1388243
#     """
5ce2836f   Alexis Koralewski   update models (ad...
27

93039f18   Alexis Koralewski   Fix issues due to...
28
#     actions = None
5ce2836f   Alexis Koralewski   update models (ad...
29

93039f18   Alexis Koralewski   Fix issues due to...
30
31
#     def get_readonly_fields(self, request, obj=None):
#         return self.fields or [f.name for f in self.model._meta.fields]
5ce2836f   Alexis Koralewski   update models (ad...
32

93039f18   Alexis Koralewski   Fix issues due to...
33
34
#     def has_add_permission(self, request):
#         return False
5ce2836f   Alexis Koralewski   update models (ad...
35

93039f18   Alexis Koralewski   Fix issues due to...
36
37
38
39
40
#     # Allow viewing objects but not actually changing them
#     def has_change_permission(self, request, obj=None):
#         if request.method not in ('GET', 'HEAD'):
#             return False
#         return super(ReadOnlyModelAdmin, self).has_change_permission(request, obj)
5ce2836f   Alexis Koralewski   update models (ad...
41

93039f18   Alexis Koralewski   Fix issues due to...
42
43
#     def has_delete_permission(self, request, obj=None):
#         return False
5ce2836f   Alexis Koralewski   update models (ad...
44
45


93039f18   Alexis Koralewski   Fix issues due to...
46
47
48
49
50
51
# # EP added

# # Edit mode
# # DEBUG = False
# # View only mode
# # DEBUG = True
5ce2836f   Alexis Koralewski   update models (ad...
52

93039f18   Alexis Koralewski   Fix issues due to...
53
# ''' Uncomment for production '''
5ce2836f   Alexis Koralewski   update models (ad...
54

93039f18   Alexis Koralewski   Fix issues due to...
55
56
57
58
59
60
# # if settings.DEBUG:
# # class PyrosModelAdmin(ReadOnlyModelAdmin):
# #     pass
# # else:
# #     class PyrosModelAdmin(admin.ModelAdmin):
# #         pass
5ce2836f   Alexis Koralewski   update models (ad...
61

93039f18   Alexis Koralewski   Fix issues due to...
62
63

# class PyrosModelAdmin(admin.ModelAdmin):
5ce2836f   Alexis Koralewski   update models (ad...
64
#     pass
5ce2836f   Alexis Koralewski   update models (ad...
65

93039f18   Alexis Koralewski   Fix issues due to...
66
# # Many To Many interface adapter
5ce2836f   Alexis Koralewski   update models (ad...
67

5ce2836f   Alexis Koralewski   update models (ad...
68

93039f18   Alexis Koralewski   Fix issues due to...
69
70
71
# class PyrosUserAndSPInline(admin.TabularInline):
#     #model = ScientificProgram.pyros_users.through
#     pass
5ce2836f   Alexis Koralewski   update models (ad...
72
73


93039f18   Alexis Koralewski   Fix issues due to...
74
75
# class SequenceAndScheduleInline(admin.TabularInline):
#     model = Schedule.sequences.through
5ce2836f   Alexis Koralewski   update models (ad...
76

93039f18   Alexis Koralewski   Fix issues due to...
77
78
79
# class PyrosUserAndUserLevelInline(admin.TabularInline):
#     # add admin representation for m2m relation between PyrosUser and UserLevel
#     model = UserLevel.pyros_users.through
5ce2836f   Alexis Koralewski   update models (ad...
80

93039f18   Alexis Koralewski   Fix issues due to...
81
82
83
84
85
# class ScheduleAdmin(admin.ModelAdmin):
#     inlines = [
#         SequenceAndScheduleInline,
#     ]
#     exclude = ('sequences',)
5ce2836f   Alexis Koralewski   update models (ad...
86

5ce2836f   Alexis Koralewski   update models (ad...
87

93039f18   Alexis Koralewski   Fix issues due to...
88
# # One To Many interface adapters
5ce2836f   Alexis Koralewski   update models (ad...
89

93039f18   Alexis Koralewski   Fix issues due to...
90
91
92
93
94
# class SequenceInline(admin.TabularInline):
#     model = Sequence
#     readonly_fields = ("name",)
#     fields = ("name",)
#     show_change_link = True
5ce2836f   Alexis Koralewski   update models (ad...
95

5ce2836f   Alexis Koralewski   update models (ad...
96

93039f18   Alexis Koralewski   Fix issues due to...
97
98
99
100
101
# # class RequestInline(admin.TabularInline):
# #     model = Request
# #     readonly_fields = ("name",)
# #     fields = ("name",)
# #     show_change_link = True
5ce2836f   Alexis Koralewski   update models (ad...
102
103


93039f18   Alexis Koralewski   Fix issues due to...
104
105
# class AlbumInline(admin.TabularInline):
#     model = Album
3f6876e5   Alexis Koralewski   fix issues with t...
106
107
108
#     readonly_fields = ("name",)
#     fields = ("name",)
#     show_change_link = True
5ce2836f   Alexis Koralewski   update models (ad...
109
110


93039f18   Alexis Koralewski   Fix issues due to...
111
112
113
114
115
# class PlanInline(admin.TabularInline):
#     model = Plan
#     #readonly_fields = ("name",)
#     #fields = ("name",)
#     show_change_link = True
5ce2836f   Alexis Koralewski   update models (ad...
116
117


93039f18   Alexis Koralewski   Fix issues due to...
118
119
120
121
122
# class ImageInline(admin.TabularInline):
#     model = Image
#     readonly_fields = ("name",)
#     fields = ("name",)
#     show_change_link = True
5ce2836f   Alexis Koralewski   update models (ad...
123
124


93039f18   Alexis Koralewski   Fix issues due to...
125
126
127
128
129
# class DetectorInline(admin.TabularInline):
#     model = Detector
#     readonly_fields = ("device_name",)
#     fields = ("device_name",)
#     show_change_link = True
5ce2836f   Alexis Koralewski   update models (ad...
130
131


93039f18   Alexis Koralewski   Fix issues due to...
132
133
134
135
136
# class PyrosUserInline(admin.TabularInline):
#     model = PyrosUser
#     readonly_fields = ("user_username",)
#     fields = ("user_username",)
#     show_change_link = True
5ce2836f   Alexis Koralewski   update models (ad...
137
138


93039f18   Alexis Koralewski   Fix issues due to...
139
140
141
142
143
# class FilterInline(admin.TabularInline):
#     model = Filter
#     readonly_fields = ("device_name",)
#     fields = ("device_name",)
#     show_change_link = True
5ce2836f   Alexis Koralewski   update models (ad...
144
145


93039f18   Alexis Koralewski   Fix issues due to...
146
147
148
149
150
# # class AlertInline(admin.TabularInline):
# #     model = Alert
# #     readonly_fields = ("request_name",)
# #     fields = ("request_name",)
# #     show_change_link = True
5ce2836f   Alexis Koralewski   update models (ad...
151
152


93039f18   Alexis Koralewski   Fix issues due to...
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# # Admin model classes

# # class RequestAdmin(PyrosModelAdmin):
# #    pass
#     # inlines = [
#     #     SequenceInline,
#     # ]


# class SequenceAdmin(PyrosModelAdmin):
#     inlines = [
#         AlbumInline,
#         SequenceAndScheduleInline,  # for M2M interface
#     ]
5ce2836f   Alexis Koralewski   update models (ad...
167
168


93039f18   Alexis Koralewski   Fix issues due to...
169
170
171
172
173
174
175
176
177
# class PyrosUserAdmin(PyrosModelAdmin):
#     list_display = ("user_username","is_active","laboratory")
#     list_filter = ("is_active",)
#     list_editable = ("is_active",)
#     inlines = [
#         #RequestInline,
#         # A user has many SPs
# #        PyrosUserAndSPInline,  # for M2M interface   
#     ]
5ce2836f   Alexis Koralewski   update models (ad...
178

5ce2836f   Alexis Koralewski   update models (ad...
179

93039f18   Alexis Koralewski   Fix issues due to...
180
181
182
183
184
185
# '''
# class StrategyObsAdmin(PyrosModelAdmin):
#     inlines = [
#         #AlertInline,
#     ]
# '''
5ce2836f   Alexis Koralewski   update models (ad...
186

5ce2836f   Alexis Koralewski   update models (ad...
187

93039f18   Alexis Koralewski   Fix issues due to...
188
189
190
191
192
193
194
# class ScientificProgramAdmin(PyrosModelAdmin):
#     inlines = [
#         #RequestInline,
#         # A SP has many users:
#     #    PyrosUserAndSPInline,  # for M2M interface
#     ]
#     exclude = ('pyros_users',)  # for M2M interface
5ce2836f   Alexis Koralewski   update models (ad...
195

5ce2836f   Alexis Koralewski   update models (ad...
196

93039f18   Alexis Koralewski   Fix issues due to...
197
198
199
200
# class CountryAdmin(PyrosModelAdmin):
#     inlines = [
#         PyrosUserInline,
#     ]
5ce2836f   Alexis Koralewski   update models (ad...
201

5ce2836f   Alexis Koralewski   update models (ad...
202

93039f18   Alexis Koralewski   Fix issues due to...
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# class UserLevelAdmin(PyrosModelAdmin):
#     inlines = [
#         #PyrosUserInline,
#         PyrosUserAndUserLevelInline,
#     ]
#     list_display = ("name","priority",)
#     # we need to exclude pyros_users which represents the m2m relation between UserLevel and PyrosUser
#     exclude = ("pyros_users",)


# class FilterAdmin(PyrosModelAdmin):
#     # inlines = [
#     #     PlanInline,
#     # ]
#     pass
5ce2836f   Alexis Koralewski   update models (ad...
218

93039f18   Alexis Koralewski   Fix issues due to...
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297

# class FilterWheelAdmin(PyrosModelAdmin):
#     inlines = [
#         FilterInline,
#     ]


# '''
# class NrtAnalysisAdmin(PyrosModelAdmin):
#     inlines = [
#         ImageInline,
#     ]
# '''


# class DetectorAdmin(PyrosModelAdmin):
#     pass
#     # inlines = [
#     #     AlbumInline,
#     # ]


# class TelescopeAdmin(PyrosModelAdmin):
#     inlines = [
#         DetectorInline,
#     ]


# class PlanAdmin(PyrosModelAdmin):
#     inlines = [
#         ImageInline,
#     ]


# # class AlbumAdmin(admin.ModelAdmin):
# class AlbumAdmin(PyrosModelAdmin):
#     inlines = [
#         PlanInline,
#     ]


# # Link the models to the admin interface

# # (EP added 10/7/19)
# admin.site.register(AgentCmd)
# admin.site.register(AgentLogs)
# admin.site.register(AgentSurvey)
# admin.site.register(AgentDeviceStatus)


# admin.site.register(Album, AlbumAdmin)
# #admin.site.register(Alert)
# admin.site.register(Country, CountryAdmin)
# admin.site.register(Detector, DetectorAdmin)
# admin.site.register(Filter, FilterAdmin)
# admin.site.register(FilterWheel, FilterWheelAdmin)
# admin.site.register(Image)
# admin.site.register(Log)
# #admin.site.register(NrtAnalysis, NrtAnalysisAdmin)
# admin.site.register(Plan, PlanAdmin)
# #admin.site.register(Request, RequestAdmin)
# admin.site.register(Schedule, ScheduleAdmin)
# admin.site.register(ScheduleHasSequences)
# admin.site.register(ScientificProgram, ScientificProgramAdmin)
# admin.site.register(Sequence, SequenceAdmin)
# admin.site.register(SiteWatch)
# admin.site.register(SiteWatchHistory)
# #admin.site.register(StrategyObs, StrategyObsAdmin)
# ##admin.site.register(TaskId)
# admin.site.register(Telescope, TelescopeAdmin)
# admin.site.register(PyrosUser, PyrosUserAdmin)
# admin.site.register(UserLevel, UserLevelAdmin)
# admin.site.register(Version)
# admin.site.register(WeatherWatch)
# admin.site.register(WeatherWatchHistory)
# admin.site.register(PlcDeviceStatus)
# admin.site.register(PlcDevice)
# admin.site.register(Config)
# admin.site.register(Institute)