forked from adamlaska/datatracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.py
More file actions
427 lines (328 loc) · 13.9 KB
/
Copy pathviews.py
File metadata and controls
427 lines (328 loc) · 13.9 KB
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
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
from django.contrib import messages
from django.conf import settings
from django.forms.models import inlineformset_factory
from django.shortcuts import render, get_object_or_404, redirect
from ietf.group.models import Group, ChangeStateGroupEvent, GroupEvent, GroupURL, Role
from ietf.group.utils import save_group_in_history, get_charter_text, setup_default_community_list_for_group
from ietf.ietfauth.utils import role_required
from ietf.person.models import Person
from ietf.secr.groups.forms import GroupModelForm, RoleForm, SearchForm
from ietf.secr.areas.forms import AWPForm
from ietf.secr.utils.meeting import get_current_meeting
# -------------------------------------------------
# Helper Functions
# -------------------------------------------------
def add_legacy_fields(group):
'''
This function takes a Group object as input and adds legacy attributes:
start_date,proposed_date,concluded_date,meeting_scheduled
'''
# it's possible there could be multiple records of a certain type in which case
# we just return the latest record
query = GroupEvent.objects.filter(group=group, type="changed_state").order_by('time')
proposed = query.filter(changestategroupevent__state="proposed")
meeting = get_current_meeting()
if proposed:
group.proposed_date = proposed[0].time
active = query.filter(changestategroupevent__state="active")
if active:
group.start_date = active[0].time
concluded = query.filter(changestategroupevent__state="conclude")
if concluded:
group.concluded_date = concluded[0].time
if group.session_set.filter(meeting__number=meeting.number):
group.meeting_scheduled = 'YES'
else:
group.meeting_scheduled = 'NO'
group.chairs = group.role_set.filter(name="chair")
group.techadvisors = group.role_set.filter(name="techadv")
group.editors = group.role_set.filter(name="editor")
group.secretaries = group.role_set.filter(name="secr")
group.liaison_contacts = group.liaisonstatementgroupcontacts_set.first()
#fill_in_charter_info(group)
#--------------------------------------------------
# AJAX Functions
# -------------------------------------------------
'''
def get_ads(request):
""" AJAX function which takes a URL parameter, "area" and returns the area directors
in the form of a list of dictionaries with "id" and "value" keys(in json format).
Used to populate select options.
"""
results=[]
area = request.GET.get('area','')
qs = AreaDirector.objects.filter(area=area)
for item in qs:
d = {'id': item.id, 'value': item.person.first_name + ' ' + item.person.last_name}
results.append(d)
return HttpResponse(json.dumps(results), content_type='application/javascript')
'''
# -------------------------------------------------
# Standard View Functions
# -------------------------------------------------
@role_required('Secretariat')
def add(request):
'''
Add a new IETF or IRTF Group
**Templates:**
* ``groups/add.html``
**Template Variables:**
* form, awp_formset
'''
AWPFormSet = inlineformset_factory(Group, GroupURL, form=AWPForm, max_num=2, can_delete=False)
if request.method == 'POST':
button_text = request.POST.get('submit', '')
if button_text == 'Cancel':
return redirect('ietf.secr.groups.views.search')
form = GroupModelForm(request.POST)
awp_formset = AWPFormSet(request.POST, prefix='awp')
if form.is_valid() and awp_formset.is_valid():
group = form.save()
for form in awp_formset.forms:
if form.has_changed():
awp = form.save(commit=False)
awp.group = group
awp.save()
if group.features.has_documents:
setup_default_community_list_for_group(group)
# create GroupEvent(s)
# always create started event
ChangeStateGroupEvent.objects.create(group=group,
type='changed_state',
by=request.user.person,
state=group.state,
desc='Started group')
messages.success(request, 'The Group was created successfully!')
return redirect('ietf.secr.groups.views.view', acronym=group.acronym)
else:
form = GroupModelForm(initial={'state':'active','type':'wg'})
awp_formset = AWPFormSet(prefix='awp')
return render(request, 'groups/add.html', {
'form': form,
'awp_formset': awp_formset},
)
@role_required('Secretariat')
def blue_dot(request):
'''
This is a report view. It returns a text/plain listing of working group chairs.
'''
people = Person.objects.filter(role__name__slug='chair',
role__group__type='wg',
role__group__state__slug__in=('active','bof','proposed')).distinct()
chairs = []
for person in people:
parts = person.name_parts()
groups = [ r.group.acronym for r in person.role_set.filter(name__slug='chair',
group__type='wg',
group__state__slug__in=('active','bof','proposed')) ]
entry = {'name':'%s, %s' % (parts[3], parts[1]),
'groups': ', '.join(groups)}
chairs.append(entry)
# sort the list
sorted_chairs = sorted(chairs, key = lambda a: a['name'])
return render(request, 'groups/blue_dot_report.txt', { 'chairs':sorted_chairs },
content_type="text/plain; charset=%s"%settings.DEFAULT_CHARSET,
)
@role_required('Secretariat')
def charter(request, acronym):
"""
View Group Charter
**Templates:**
* ``groups/charter.html``
**Template Variables:**
* group, charter_text
"""
group = get_object_or_404(Group, acronym=acronym)
# TODO: get_charter_text() should be updated to return None
if group.charter:
charter_text = get_charter_text(group)
else:
charter_text = ''
return render(request, 'groups/charter.html', {
'group': group,
'charter_text': charter_text},
)
@role_required('Secretariat')
def delete_role(request, acronym, id):
"""
Handle deleting roles for groups (chair, editor, advisor, secretary)
**Templates:**
* none
Redirects to people page on success.
"""
group = get_object_or_404(Group, acronym=acronym)
role = get_object_or_404(Role, id=id)
if request.method == 'POST' and request.POST['post'] == 'yes':
# save group
save_group_in_history(group)
role.delete()
messages.success(request, 'The entry was deleted successfully')
return redirect('ietf.secr.groups.views.people', acronym=acronym)
return render(request, 'confirm_delete.html', {'object': role})
@role_required('Secretariat')
def edit(request, acronym):
"""
Edit Group details
**Templates:**
* ``groups/edit.html``
**Template Variables:**
* group, form, awp_formset
"""
group = get_object_or_404(Group, acronym=acronym)
AWPFormSet = inlineformset_factory(Group, GroupURL, form=AWPForm, max_num=2)
if request.method == 'POST':
button_text = request.POST.get('submit', '')
if button_text == 'Cancel':
return redirect('ietf.secr.groups.views.view', acronym=acronym)
form = GroupModelForm(request.POST, instance=group)
awp_formset = AWPFormSet(request.POST, instance=group)
if form.is_valid() and awp_formset.is_valid():
awp_formset.save()
if form.changed_data:
state = form.cleaned_data['state']
# save group
save_group_in_history(group)
form.save()
# create appropriate GroupEvent
if 'state' in form.changed_data:
if state.name == 'Active':
desc = 'Started group'
else:
desc = state.name + ' group'
ChangeStateGroupEvent.objects.create(group=group,
type='changed_state',
by=request.user.person,
state=state,
desc=desc)
form.changed_data.remove('state')
# if anything else was changed
if form.changed_data:
GroupEvent.objects.create(group=group,
type='info_changed',
by=request.user.person,
desc='Info Changed')
# if the acronym was changed we'll want to redirect using the new acronym below
if 'acronym' in form.changed_data:
acronym = form.cleaned_data['acronym']
messages.success(request, 'The Group was changed successfully')
return redirect('ietf.secr.groups.views.view', acronym=acronym)
else:
form = GroupModelForm(instance=group)
awp_formset = AWPFormSet(instance=group)
messages.warning(request, "WARNING: don't use this tool to change group names. Use Datatracker when possible.")
return render(request, 'groups/edit.html', {
'group': group,
'awp_formset': awp_formset,
'form': form},
)
@role_required('Secretariat')
def people(request, acronym):
"""
Edit Group Roles (Chairs, Secretary, etc)
**Templates:**
* ``groups/people.html``
**Template Variables:**
* form, group
"""
group = get_object_or_404(Group, acronym=acronym)
if request.method == 'POST':
# we need to pass group for form validation
form = RoleForm(request.POST,group=group)
if form.is_valid():
name = form.cleaned_data['name']
person = form.cleaned_data['person']
email = form.cleaned_data['email']
# save group
save_group_in_history(group)
Role.objects.create(name=name,
person=person,
email=email,
group=group)
if not email.origin or email.origin == person.user.username:
email.origin = "role: %s %s" % (group.acronym, name.slug)
email.save()
messages.success(request, 'New %s added successfully!' % name)
return redirect('ietf.secr.groups.views.people', acronym=group.acronym)
else:
form = RoleForm(initial={'name':'chair', 'group_acronym':group.acronym}, group=group)
return render(request, 'groups/people.html', {
'form':form,
'group':group},
)
@role_required('Secretariat')
def search(request):
"""
Search IETF Groups
**Templates:**
* ``groups/search.html``
**Template Variables:**
* form, results
"""
results = []
if request.method == 'POST':
form = SearchForm(request.POST)
if request.POST['submit'] == 'Add':
return redirect('ietf.secr.groups.views.add')
if form.is_valid():
kwargs = {}
group_acronym = form.cleaned_data['group_acronym']
group_name = form.cleaned_data['group_name']
primary_area = form.cleaned_data['primary_area']
meeting_scheduled = form.cleaned_data['meeting_scheduled']
state = form.cleaned_data['state']
type = form.cleaned_data['type']
meeting = get_current_meeting()
# construct seach query
if group_acronym:
kwargs['acronym__istartswith'] = group_acronym
if group_name:
kwargs['name__istartswith'] = group_name
if primary_area:
kwargs['parent'] = primary_area
if state:
kwargs['state'] = state
if type:
kwargs['type'] = type
#else:
# kwargs['type__in'] = ('wg','rg','ietf','ag','sdo','team')
if meeting_scheduled == 'YES':
kwargs['session__meeting__number'] = meeting.number
# perform query
if kwargs:
if meeting_scheduled == 'NO':
qs = Group.objects.filter(**kwargs).exclude(session__meeting__number=meeting.number).distinct()
else:
qs = Group.objects.filter(**kwargs).distinct()
else:
qs = Group.objects.all()
results = qs.order_by('acronym')
# if there's just one result go straight to view
if len(results) == 1:
return redirect('ietf.secr.groups.views.view', acronym=results[0].acronym)
# process GET argument to support link from area app
elif 'primary_area' in request.GET:
area = request.GET.get('primary_area','')
results = Group.objects.filter(parent__id=area,type='wg',state__in=('bof','active','proposed')).order_by('name')
form = SearchForm({'primary_area':area,'state':'','type':'wg'})
else:
form = SearchForm(initial={'state':'active'})
# loop through results and tack on meeting_scheduled because it is no longer an
# attribute of the meeting model
for result in results:
add_legacy_fields(result)
return render(request, 'groups/search.html', {
'results': results,
'form': form},
)
@role_required('Secretariat')
def view(request, acronym):
"""
View IETF Group details
**Templates:**
* ``groups/view.html``
**Template Variables:**
* group
"""
group = get_object_or_404(Group, acronym=acronym)
add_legacy_fields(group)
return render(request, 'groups/view.html', { 'group': group } )