pref: 优化 permission actionss

This commit is contained in:
ibuler
2022-11-11 17:28:13 +08:00
parent 1cd551e692
commit 9c5b3a03c6
4 changed files with 76 additions and 83 deletions

View File

@@ -2,10 +2,10 @@
#
import json
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import force_text
from django.core.validators import MinValueValidator, MaxValueValidator
from django.db import models
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _
from common.utils import signer, crypto
@@ -211,22 +211,28 @@ class BitChoices(models.IntegerChoices):
def branches(cls):
return [i for i in cls]
@classmethod
def is_tree(cls):
return False
@classmethod
def tree(cls):
if not cls.is_tree():
return []
root = [_("All"), cls.branches()]
return cls.render_node(root)
return [cls.render_node(root)]
@classmethod
def render_node(cls, node):
if isinstance(node, BitChoices):
return {
"id": node.name,
"value": node.name,
"label": node.label,
}
else:
name, children = node
return {
"id": name,
"value": name,
"label": name,
"children": [cls.render_node(child) for child in children],
}