Skip to content

Commit

Permalink
zpretty
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Jan 4, 2024
1 parent 16d4605 commit d445203
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/redturtle/prenotazioni/adapters/booking_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
from redturtle.prenotazioni.content.prenotazione import IPrenotazione
from zope.component import adapter
from zope.component import Interface
from zope.interface import implementer

import hashlib


class IBookingCodeGenerator(Interface):
"""
Adapter interface to generate a code
"""


@implementer(IBookingCodeGenerator)
@adapter(IPrenotazione, Interface)
class BookingCodeGenerator:
def __init__(self, context, request):
self.context = context
self.request = request

def __call__(self, *args, **kwargs):
hash_obj = hashlib.blake2b(
bytes(self.context.UID(), encoding="utf8"), digest_size=3
)

return hash_obj.hexdigest().upper()
4 changes: 2 additions & 2 deletions src/redturtle/prenotazioni/adapters/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
/>


<!-- code generator -->
<adapter factory=".booking_code.BookingCodeGenerator" />
<!-- code generator -->
<adapter factory=".booking_code.BookingCodeGenerator" />

</configure>

0 comments on commit d445203

Please sign in to comment.