def _addToRoomDayReservationsIndex(self): roomDayReservationsIndexBTree = Reservation.getRoomDayReservationsIndexRoot() for period in self.splitToPeriods(): day = period.startDT.date() key = (self.room.id, day) resvs = roomDayReservationsIndexBTree.get(key) if resvs is None: resvs = OOSet() resvs.add(self) roomDayReservationsIndexBTree[key] = resvs
class HashList(Content, ContextACLMixin, LocalRolesMixin): type_name = "HashList" type_title = _("HashList") type_description = _( "Encrypted text-rows that can be matched to this document") add_permission = PERM_MANAGE_SYSTEM css_icon = "glyphicon glyphicon-lock" nav_visible = False listing_visible = False search_visible = False salt = None def __init__(self, **kw): self.salt = bcrypt.gensalt() self.hashset = OOSet() self.plaintext_rows = OOSet() super(HashList, self).__init__(**kw) def check(self, value): value = b64encode(value.encode('utf-8')) if value in self.plaintext_rows: return True return bcrypt.hashpw(value, self.salt) in self.hashset def hash_plaintext(self, limit=100): rows = list(self.plaintext_rows)[:limit] for row in rows: hashed = bcrypt.hashpw(row, self.salt) if hashed not in self.hashset: self.hashset.add(hashed) self.plaintext_rows.remove(row) return len(self.plaintext_rows) def hash_and_remove_plaintext(self, limit=100): rows = list(self.plaintext_rows)[:limit] for row in rows: hashed = bcrypt.hashpw(row, self.salt) if hashed in self.hashset: self.hashset.remove(hashed) self.plaintext_rows.remove(row) return len(self.plaintext_rows) @property def plaintext(self): return '' @plaintext.setter def plaintext(self, value): for row in value.splitlines(): row = row.strip() if row and row not in self.plaintext_rows: self.plaintext_rows.add(b64encode(row.encode('utf-8')))
def register_status_tracking(self, username, rest_id): """ Register `username` for tracking states of given `rest_id`. Args: username (str): Name of the user. rest_id (str): Unique identificator of given REST request. """ self.log("Registering user '%s' to track '%s'." % (username, rest_id)) # handle id->username mapping self.id_to_username[rest_id] = username # handle username->ids mapping uname_to_ids = self.username_to_ids.get(username, None) if uname_to_ids is None: uname_to_ids = OOSet() self.username_to_ids[username] = uname_to_ids # add new rest_id to set uname_to_ids.add(rest_id) self.status_db[rest_id] = StatusInfo(rest_id=rest_id)
class BudgetGroup(Persistent): """ The BudgetGroup class contains a set of BudgetItem objects and is contained by Project. It has Name and Description string attributes, and a set of BudgetItems. It has methods to add and delete BudgetItem instances from the set. BudgetGroup has functions to calculate the subtotal, vat, and total of the BudgetItems in the set. The class is hashable and has a toString method. """ VAT = 0.14 def __init__(self, name = '', desc = ''): """ The BudgetGroup constructor takes a string name and desc as the Name of the project, and it's Description. It initialises with an empty set. """ self.Name = name self.Description = desc self.ItemSet = OOSet() def add(self, item): """The add method adds a BudgetItem object to the set.""" self.ItemSet.add(item) def delete(self, item): """ The delete method removes a BudgetGroup object from the set. Before removing an object it makes sure it is in the set. """ if (item in self.ItemSet): self.ItemSet.remove(item) return "Confirmed." else: return "Not in set." def subtotal(self): """ The subtotal function returns the total of the subtotal of all the BudgetItem objects. """ stotal = 0 for group in self.ItemSet: stotal+=group.subtotal() return stotal def vat(self): """ The vat function calculates the VAT percentage on the subtotal. Computing the percentage on the subtotal is more efficient than computing the percentage of each item and adding it. """ #return (self.subtotal()*VAT) return (self.subtotal()*0.14) def total (self): """ The total function computes the cost of the BudgetGroup plus VAT. Computing the subtotal increasing it with the VAT percentage is more efficient than computing the subtotal and VAT separately. """ #return (self.subtotal()*(1+VAT)) return (self.subtotal()*(1+0.14)) def __hash__(self): """This enables the class to be hashable""" return hash(self.Name) def __eq__(self, other): """This enables the class to be hashable""" return self.Name == other.Name def __str__(self): """ The toString method returns a string of the name and description of the class. If the set is not empty thereafter it prints all the BudgetItems in the set. """ output = self.Name + ": " + self.Description if self.ItemSet is not None: for item in self.ItemSet: output+=("\n\t\t"+str(item)) return output