Skip to content

Commit c69556e

Browse files
committed
Improve admin form validation for used_roles. Commit ready for merge.
- Legacy-Id: 17992
1 parent 033da55 commit c69556e

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

ietf/group/admin.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from functools import update_wrapper
66

7+
from django import forms
8+
79
from django.contrib import admin
810
from django.contrib.admin.utils import unquote
911
from django.core.exceptions import PermissionDenied
@@ -25,7 +27,20 @@ class RoleInline(admin.TabularInline):
2527
class GroupURLInline(admin.TabularInline):
2628
model = GroupURL
2729

30+
class GroupForm(forms.ModelForm):
31+
class Meta:
32+
model = Group
33+
fields = '__all__'
34+
35+
def clean_used_roles(self):
36+
data = self.cleaned_data['used_roles']
37+
if data is None or data == '':
38+
raise forms.ValidationError("Must contain a valid json expression. To use the defaults prove an empty list: []")
39+
return data
40+
41+
2842
class GroupAdmin(admin.ModelAdmin):
43+
form = GroupForm
2944
list_display = ["acronym", "name", "type", "state", "time", "role_list"]
3045
list_display_links = ["acronym", "name"]
3146
list_filter = ["type", "state", "time"]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated by Django 2.0.13 on 2020-06-15 11:10
2+
3+
from django.db import migrations
4+
import jsonfield.fields
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('group', '0030_populate_default_used_roles'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='group',
16+
name='used_roles',
17+
field=jsonfield.fields.JSONField(blank=True, default=[], help_text="Leave an empty list to get the group_type's default used roles", max_length=128),
18+
),
19+
migrations.AlterField(
20+
model_name='grouphistory',
21+
name='used_roles',
22+
field=jsonfield.fields.JSONField(blank=True, default=[], help_text="Leave an empty list to get the group_type's default used roles", max_length=128),
23+
),
24+
]

ietf/group/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class GroupInfo(models.Model):
4343
unused_states = models.ManyToManyField('doc.State', help_text="Document states that have been disabled for the group.", blank=True)
4444
unused_tags = models.ManyToManyField(DocTagName, help_text="Document tags that have been disabled for the group.", blank=True)
4545

46-
used_roles = jsonfield.JSONField(max_length=128, blank=False, default=[], help_text="Leave an empty list to get the group_type's default used roles")
46+
used_roles = jsonfield.JSONField(max_length=128, blank=True, default=[], help_text="Leave an empty list to get the group_type's default used roles")
4747

4848
uses_milestone_dates = models.BooleanField(default=True)
4949

0 commit comments

Comments
 (0)