def add_message(id, title, text, msg_type='info', can_hide=False, start=datetime.now(), end='', req_roles=[], location='fullsite', tal_condition='', roles_byp_talcond=[], use_local_roles=False, activate=False): """ Add a message in the configuration folder msg_type: info, significant, warning start: default now end: default empty, or use pattern YYYYMMDD-HHSS location: fullsite, homepage """ site = api.portal.getSite() config = site['messages-config'] # We pass if id already exists if id in config: return None rich_text = _richtextval(text) try: end_date = datetime.strptime(end, '%Y%m%d-%H%M') except ValueError: end_date = None message = api.content.create(container=config, type='Message', id=id, title=title, **{'msg_type': msg_type, 'text': rich_text, 'can_hide': can_hide, 'start': start, 'end': end_date, 'required_roles': req_roles, 'location': location, 'hidden_uid': generate_uid(), 'tal_condition': tal_condition, 'roles_bypassing_talcondition': roles_byp_talcond, 'use_local_roles': use_local_roles}) if activate: api.content.transition(message, 'activate') return message
def change_hidden_uid(message, event): """ Generate a new uid if the message is deactivated """ if event.action == 'deactivate': message.hidden_uid = generate_uid()