Browse Source

fix: action

pull/9090/head
feng 2 years ago
parent
commit
ec462e09e0
  1. 2
      apps/common/drf/fields.py
  2. 7
      apps/common/utils/integer.py
  3. 10
      apps/perms/const.py

2
apps/common/drf/fields.py

@ -162,6 +162,8 @@ class BitChoicesField(TreeChoicesMixin, serializers.MultipleChoiceField):
这里将获取到的值再执行一下 to_internal_value 方法, 转化为内部值 这里将获取到的值再执行一下 to_internal_value 方法, 转化为内部值
""" """
data = super().run_validation(data) data = super().run_validation(data)
if isinstance(data, int):
return data
value = self.to_internal_value(data) value = self.to_internal_value(data)
self.run_validators(value) self.run_validators(value)
return value return value

7
apps/common/utils/integer.py

@ -1,5 +1,4 @@
def bit(x): def bit(x):
if x == 0: if x < 1:
return 0 raise ValueError("x must be greater than 1")
else: return 2 ** (x - 1)
return 2 ** (x - 1)

10
apps/perms/const.py

@ -10,11 +10,11 @@ __all__ = ["ActionChoices"]
class ActionChoices(BitChoices): class ActionChoices(BitChoices):
connect = bit(0), _("Connect") connect = bit(1), _("Connect")
upload = bit(1), _("Upload") upload = bit(2), _("Upload")
download = bit(2), _("Download") download = bit(3), _("Download")
copy = bit(3), _("Copy") copy = bit(4), _("Copy")
paste = bit(4), _("Paste") paste = bit(5), _("Paste")
@classmethod @classmethod
def is_tree(cls): def is_tree(cls):

Loading…
Cancel
Save