Skip to content

Commit

Permalink
Added random_element filter to properly work
Browse files Browse the repository at this point in the history
  • Loading branch information
frikky committed Jun 17, 2024
1 parent 7e4a36e commit de2a8ba
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions backend/app_sdk/app_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def md5_base64(a):
a = str(a)
foundhash = hashlib.md5(a.encode('utf-8')).hexdigest()
return base64.b64encode(foundhash.encode('utf-8'))


@shuffle_filters.register
def base64_encode(a):
Expand All @@ -107,6 +108,17 @@ def base64_encode(a):
except:
return base64.b64encode(a).decode()

@shuffle_filters.register
def random_element(a):
# Choose a random item from an array
a = list(a)

if len(a) == 0:
return ""

return random.choice(a)


@shuffle_filters.register
def base64_decode(a):
a = str(a)
Expand Down

0 comments on commit de2a8ba

Please sign in to comment.