Add non WG Area choices to Parent field of secretariat groups edit form. Fixes #1344. Commit ready for merge.

- Legacy-Id: 13499
This commit is contained in:
Ryan Cross 2017-06-02 18:50:01 +00:00
parent 254e35fa56
commit a63d5132b2
2 changed files with 40 additions and 4 deletions

View file

@ -1,7 +1,7 @@
import re
from django import forms
from django.db.models import Q
from django.db.models import Count
from ietf.group.models import Group, GroupMilestone, Role
from ietf.name.models import GroupStateName, GroupTypeName, RoleName
@ -33,6 +33,13 @@ def get_person(name):
return None
return person
def get_parent_group_choices():
area_choices = [(g.id, g.name) for g in Group.objects.filter(type='area',state='active')]
other_parents = Group.objects.annotate(children=Count('group')).filter(children__gt=0).order_by('name').exclude(type='area')
other_choices = [(g.id, g.name) for g in other_parents]
choices = (('Working Group Areas',area_choices),('Other',other_choices))
return choices
# ---------------------------------------------
# Forms
# ---------------------------------------------
@ -66,7 +73,7 @@ class GroupMilestoneForm(forms.ModelForm):
class GroupModelForm(forms.ModelForm):
type = forms.ModelChoiceField(queryset=GroupTypeName.objects.all(),empty_label=None)
parent = forms.ModelChoiceField(queryset=Group.objects.filter(Q(type='area',state='active')|Q(acronym='irtf')),required=False)
parent = forms.ModelChoiceField(queryset=Group.objects.all(),required=False)
ad = forms.ModelChoiceField(queryset=Person.objects.filter(role__name='ad',role__group__state='active',role__group__type='area'),required=False)
state = forms.ModelChoiceField(queryset=GroupStateName.objects.exclude(slug__in=('dormant','unknown')),empty_label=None)
liaison_contacts = forms.CharField(max_length=255,required=False,label='Default Liaison Contacts')
@ -82,8 +89,9 @@ class GroupModelForm(forms.ModelForm):
self.fields['list_archive'].label = 'List Archive'
self.fields['ad'].label = 'Area Director'
self.fields['comments'].widget.attrs['rows'] = 3
self.fields['parent'].label = 'Area'
self.fields['parent'].label = 'Area / Parent'
self.fields['parent'].choices = get_parent_group_choices()
if self.instance.pk:
lsgc = self.instance.liaisonstatementgroupcontacts_set.first() # there can only be one
if lsgc:

View file

@ -2,11 +2,19 @@
from django.urls import reverse
from ietf.utils.test_utils import TestCase
from ietf.group.models import Group
from ietf.secr.groups.forms import get_parent_group_choices
from ietf.group.factories import GroupFactory
from ietf.person.models import Person
from ietf.utils.test_data import make_test_data
import debug # pyflakes:ignore
class GroupsTest(TestCase):
def test_get_parent_group_choices(self):
make_test_data()
choices = get_parent_group_choices()
area = Group.objects.filter(type='area',state='active').first()
self.assertEqual(choices[0][1][0][0],area.id)
# ------- Test Search -------- #
def test_search(self):
"Test Search"
@ -107,6 +115,26 @@ class GroupsTest(TestCase):
self.assertRedirects(response, target)
self.failUnless('changed successfully' in response.content)
def test_edit_non_wg_group(self):
make_test_data()
parent_sdo = GroupFactory.create(type_id='sdo',state_id='active')
child_sdo = GroupFactory.create(type_id='sdo',state_id='active',parent=parent_sdo)
url = reverse('ietf.secr.groups.views.edit', kwargs={'acronym':child_sdo.acronym})
target = reverse('ietf.secr.groups.views.view', kwargs={'acronym':child_sdo.acronym})
post_data = {'acronym':child_sdo.acronym,
'name':'New Name',
'type':'sdo',
'state':child_sdo.state_id,
'parent':parent_sdo.id,
'ad':'',
'groupurl_set-TOTAL_FORMS':'2',
'groupurl_set-INITIAL_FORMS':'0',
'submit':'Save'}
self.client.login(username="secretary", password="secretary+password")
response = self.client.post(url,post_data,follow=True)
self.assertRedirects(response, target)
self.failUnless('changed successfully' in response.content)
# ------- Test People -------- #
def test_people_delete(self):
make_test_data()