Replies: 1 comment 8 replies
-
Hm... I found a bit of an answer after hours now. You have to keep the variable as Enum in the View, and cast it to an Enum when getting it from the template. class ScopeSwitcherView(UnicornView):
active_scope: Scope = Scope.USER
def set_scope(self, scope: int):
self.active_scope = Scope(scope) In the template, use ints/strings, by using <button
type="button"
class="btn {% if active_scope == active_scope.GROUP.value %} active{% endif %}"
unicorn:click="set_scope({{ active_scope.GROUP.value }})"
>Set to GROUP</i></button> |
Beta Was this translation helpful? Give feedback.
8 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
According to the docs, passed types must be simple Python types.
I am struggling passing an IntEnum, which in fact is an int, to a view:
But I get no way to solve this. can I pass the Enum ("Scope" here) as attribute to the view?
And ideas? Would it be possible to cast Enums/IntEnums to str or ints in Unicorn? I always get the error:
Beta Was this translation helpful? Give feedback.
All reactions