-
Notifications
You must be signed in to change notification settings - Fork 2
/
admin.py
245 lines (206 loc) · 8 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
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
from django.contrib import admin
from django.contrib.admin.models import LogEntry
from django.contrib.localflavor.us.forms import *
from django import forms
from roster.models import *
from roster.fields import *
from roster.filters import *
def schools_as_choices():
schools = [('', "---------")]
for school in School.objects.order_by('type', 'longname'):
stype = school.get_type_display()+"s"
if not schools or schools[-1][0] != stype:
schools.append([stype, []])
schools[-1][1].append((school.id, school.longname))
return schools
#def people_as_choices():
# people = []
# for model in [Student, Adult, Contact]:
# people.append([model._meta.verbose_name_plural.capitalize(), []])
# for person in model.objects.all():
# people[-1][1].append((person.id, unicode(person)))
#
# return people
class TeamAdmin(admin.ModelAdmin):
list_display = ['name', 'program']
class PersonInline(admin.TabularInline):
model = Person
extra = 1
class SchoolAdmin(admin.ModelAdmin):
list_display = ['__unicode__', 'name', 'type']
class EmailPersonInline(admin.TabularInline):
model = PersonEmail
extra = 1
verbose_name = 'Person'
verbose_name_plural = 'People'
class EmailAdmin(admin.ModelAdmin):
list_display = ['email', 'location']
search_fields = ['email']
#inlines = [EmailPersonInline]
class AddressPersonInline(admin.TabularInline):
model = Person.addresses.through
extra = 1
max_num = 1
verbose_name = 'Person'
verbose_name_plural = 'People'
class AddressAdminForm(forms.ModelForm):
class Meta:
model = Address
def __init__(self, *args, **kwargs):
super(AddressAdminForm, self).__init__(*args, **kwargs)
self.fields['zipcode'] = USZipCodeField()
class AddressAdmin(admin.ModelAdmin):
form = AddressAdminForm
list_display = ['line1', 'city', 'state', 'zipcode']
list_filter = ['city', 'state', 'zipcode']
#inlines = [AddressPersonInline]
class PhonePersonInline(admin.TabularInline):
model = PersonPhone
extra = 1
verbose_name = 'Person'
verbose_name_plural = 'People'
class PhoneAdmin(admin.ModelAdmin):
list_display = ['full_phone', 'location']
#inlines = [PhonePersonInline]
search_fields = ['phone', 'ext']
def full_phone(self, obj):
if obj.ext:
return "%s x%s" % (obj.phone, obj.ext)
else:
return obj.phone
class PersonTeamInlineForm(forms.ModelForm):
class Meta:
model = PersonTeam
def __init__(self, *args, **kwargs):
super(PersonTeamInlineForm, self).__init__(*args, **kwargs)
self.fields['joined'] = \
USDateFormField(widget=admin.widgets.AdminDateWidget)
self.fields['joined'].required = False
self.fields['left'] = \
USDateFormField(widget=admin.widgets.AdminDateWidget)
self.fields['left'].required = False
class PersonTeamInline(admin.TabularInline):
model = PersonTeam
form = PersonTeamInlineForm
extra = 1
verbose_name = 'Team'
verbose_name_plural = 'Teams'
class PersonEmailInline(admin.TabularInline):
model = PersonEmail
extra = 1
verbose_name = 'Email address'
verbose_name_plural = 'Email addresses'
class PersonAddressInline(admin.TabularInline):
model = Person.addresses.through
extra = 1
max_num = 1
verbose_name = 'Address'
verbose_name_plural = 'Addresses'
class PersonPhoneInline(admin.TabularInline):
model = PersonPhone
extra = 1
verbose_name = 'Phone number'
verbose_name_plural = 'Phone numbers'
class RelationshipAdminForm(forms.ModelForm):
class Meta:
model = Relationship
def __init__(self, *args, **kwargs):
super(RelationshipAdminForm, self).__init__(*args, **kwargs)
#self.fields['person_to'].choices = people_as_choices()
class RelationshipInline(admin.TabularInline):
model = Relationship
form = RelationshipAdminForm
fk_name = 'person_from'
extra = 1
verbose_name_plural = 'Relationships'
class PersonAdminForm(forms.ModelForm):
class Meta:
model = Person
def __init__(self, *args, **kwargs):
super(PersonAdminForm, self).__init__(*args, **kwargs)
self.fields['school'].choices = schools_as_choices()
self.fields['medical'].widget = \
forms.widgets.Textarea(attrs={'rows':2, 'cols':60})
self.fields['medications'].widget = \
forms.widgets.Textarea(attrs={'rows':2, 'cols':60})
self.fields['prospective_source'].widget = \
forms.widgets.Textarea(attrs={'rows':2, 'cols':60})
self.fields['comments'].widget = \
forms.widgets.Textarea(attrs={'rows':2, 'cols':60})
class PersonAdmin(admin.ModelAdmin):
form = PersonAdminForm
list_display = ['__unicode__', 'lastname', 'get_firstname', 'active_roles']
list_filter = ['teams', RoleListFilter, StatusListFilter, 'gender', 'school']
search_fields = ['^firstname', '^lastname', '^nickname']
inlines = [PersonTeamInline,
PersonEmailInline,
PersonPhoneInline,
PersonAddressInline,
RelationshipInline]
radio_fields = {'gender': admin.HORIZONTAL}
fieldsets = [
(None, {'fields': ['firstname', 'lastname', 'suffix', 'nickname',
'gender',
('birth_month', 'birth_day', 'birth_year'),
('school', 'grad_year'),
'company',
'shirt_size',
'legacy_badge', 'photo', 'position']}),
('Medical information', {'fields': ['medical', 'medications']}),
('Misc information', {'fields': ['prospective_source', 'comments']}),
]
class RelationshipTypeAdmin(admin.ModelAdmin):
list_display = ['type', 'parent', 'sort_order']
class WaiverAdmin(admin.ModelAdmin):
list_display = ['person', 'org', 'year']
list_filter = ['org', 'year', 'person']
class TimeRecordAdmin(admin.ModelAdmin):
list_display = ['person', 'event', 'clock_in', 'clock_out', 'hours',
'recorded']
list_filter = ['event', 'clock_in', 'recorded', 'person']
class EventPersonInlineForm(forms.ModelForm):
class Meta:
model = EventPerson
def __init__(self, *args, **kwargs):
super(EventPersonInlineForm, self).__init__(*args, **kwargs)
#self.fields['person'].choices = people_as_choices()
class EventPersonInline(admin.TabularInline):
form = EventPersonInlineForm
model = EventPerson
extra = 1
verbose_name = 'Person'
verbose_name_plural = 'People'
class EventAdminForm(forms.ModelForm):
class Meta:
model = Event
def __init__(self, *args, **kwargs):
super(EventAdminForm, self).__init__(*args, **kwargs)
self.fields['date'] = \
USDateFormField(widget=admin.widgets.AdminDateWidget)
self.fields['end_date'] = \
USDateFormField(widget=admin.widgets.AdminDateWidget)
self.fields['end_date'].required = False
class EventAdmin(admin.ModelAdmin):
form = EventAdminForm
list_display = ['name', 'location', 'date', 'time', 'end_date',
'end_time']
list_filter = ['location', 'date']
search_fields = ['name']
inlines = [EventPersonInline]
class LogEntryAdmin(admin.ModelAdmin):
list_display = ['__unicode__', 'user', 'action_time']
readonly_fields = ('content_type', 'user', 'action_time')
admin.site.register(Organization)
admin.site.register(Program)
admin.site.register(Team, TeamAdmin)
admin.site.register(School, SchoolAdmin)
admin.site.register(Company)
admin.site.register(Email, EmailAdmin)
admin.site.register(Address, AddressAdmin)
admin.site.register(Phone, PhoneAdmin)
admin.site.register(RelationshipType, RelationshipTypeAdmin)
admin.site.register(Waiver, WaiverAdmin)
admin.site.register(Person, PersonAdmin)
admin.site.register(TimeRecord, TimeRecordAdmin)
admin.site.register(Event, EventAdmin)
admin.site.register(LogEntry, LogEntryAdmin)