Improve admin form validation for used_roles. Commit ready for merge.
- Legacy-Id: 17992
This commit is contained in:
parent
033da559d2
commit
c69556efe1
|
@ -4,6 +4,8 @@
|
|||
|
||||
from functools import update_wrapper
|
||||
|
||||
from django import forms
|
||||
|
||||
from django.contrib import admin
|
||||
from django.contrib.admin.utils import unquote
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
@ -25,7 +27,20 @@ class RoleInline(admin.TabularInline):
|
|||
class GroupURLInline(admin.TabularInline):
|
||||
model = GroupURL
|
||||
|
||||
class GroupForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Group
|
||||
fields = '__all__'
|
||||
|
||||
def clean_used_roles(self):
|
||||
data = self.cleaned_data['used_roles']
|
||||
if data is None or data == '':
|
||||
raise forms.ValidationError("Must contain a valid json expression. To use the defaults prove an empty list: []")
|
||||
return data
|
||||
|
||||
|
||||
class GroupAdmin(admin.ModelAdmin):
|
||||
form = GroupForm
|
||||
list_display = ["acronym", "name", "type", "state", "time", "role_list"]
|
||||
list_display_links = ["acronym", "name"]
|
||||
list_filter = ["type", "state", "time"]
|
||||
|
|
24
ietf/group/migrations/0031_allow_blank_used_roles.py
Normal file
24
ietf/group/migrations/0031_allow_blank_used_roles.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Generated by Django 2.0.13 on 2020-06-15 11:10
|
||||
|
||||
from django.db import migrations
|
||||
import jsonfield.fields
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('group', '0030_populate_default_used_roles'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='group',
|
||||
name='used_roles',
|
||||
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),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='grouphistory',
|
||||
name='used_roles',
|
||||
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),
|
||||
),
|
||||
]
|
|
@ -43,7 +43,7 @@ class GroupInfo(models.Model):
|
|||
unused_states = models.ManyToManyField('doc.State', help_text="Document states that have been disabled for the group.", blank=True)
|
||||
unused_tags = models.ManyToManyField(DocTagName, help_text="Document tags that have been disabled for the group.", blank=True)
|
||||
|
||||
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")
|
||||
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")
|
||||
|
||||
uses_milestone_dates = models.BooleanField(default=True)
|
||||
|
||||
|
|
Loading…
Reference in a new issue