def save_confirmation(context, confirmation): mtool = getToolByName(context, 'portal_membership') storage = IAttendeesStorage(context) member = mtool.getAuthenticatedMember() # If the user belongs to any invited groups, store the user's confirmation # for those groups. member_groups = member.getGroups() if 'AuthenticatedUsers' in member_groups: member_groups.remove('AuthenticatedUsers') if member_groups: group_dicts = storage.groups invited_groups = get_invited_groups(context) groups_to_confirm = [g for g in member_groups if g in invited_groups] for group in groups_to_confirm: for group_dict in group_dicts: if group_dict['name'] == group: group_dict['attending'][confirmation].append({ 'name': member.getProperty('fullname', None) or member.id, 'email': member.getProperty('email'), 'id': member.id, }) break storage.groups = group_dicts # If the user was (also) invited individually, store the confirmation under # internal_attendees if member.id in get_invited_usernames(context): internal_attendees = storage.get('internal_attendees', []) for att in internal_attendees: if att['id'] == member.id: att['attending'] = confirmation storage.internal_attendees = internal_attendees
def show_email_new_button(form): """ """ context = form.context storage = IAttendeesStorage(context) attendees = storage.get('internal_attendees', []) + \ storage.get('external_attendees', []) if not attendees: return False return True
def updateWidgets(self): """ Make sure that the widgets are populated with stored or request values. """ super(EventInviteForm, self).updateWidgets() context = aq_inner(self.context) storage = IAttendeesStorage(context) for key in ['internal_attendees', 'external_attendees']: widget_value = self.request.get('form.widgets.%s' % key) if not widget_value: if key == 'internal_attendees': widget_value = [k['id'] for k in storage.get(key, [])] else: widget_value = storage.get(key) if widget_value: self.widgets[key].value = widget_value
def save_attendees(context, data): mtool = getToolByName(context, 'portal_membership') gtool = getToolByName(context, 'portal_groups') storage = IAttendeesStorage(context) group_ids = gtool.getGroupIds() internal_attendees = [] existing_internal_attendees = storage.get('internal_attendees', []) existing_attendance = {} for entry in existing_internal_attendees: existing_attendance[entry["id"]] = entry.get("attending", None) groups = [] for name in data['internal_attendees']: if name in group_ids: group = gtool.getGroupById(name) groups.append({ 'name': group.id, 'attending': {'Yes': [], 'No': [], 'Maybe': []}, }) else: member = mtool.getMemberById(name) attending = None if member.id in existing_attendance: attending = existing_attendance[member.id] internal_attendees.append({ 'name': member.getProperty('fullname', None) or member.id, 'email': member.getProperty('email'), 'id': member.id, 'attending': attending, }) storage.internal_attendees = internal_attendees storage.external_attendees = data['external_attendees'] storage.groups = groups return {'internal_attendees': storage.internal_attendees, 'external_attendees': storage.external_attendees, 'groups': storage.groups, }
def get_new_attendees(context, data): """ Gets newly added attendees and returns a dictionary in the proper format. $data is a dict, whose required format is the same as would be submitted to the request by the z3c.form widgets as defined in browser/invite.py Here's an example: { 'external_attendees': [ {'email': '*****@*****.**', 'name': 'Max Mustermann'}, {'email': '*****@*****.**', 'name': 'John Doe'} ], 'internal_attendees': [ 'Administrators', 'Reviewers', 'Site Administrators', 'andreas-ebersbacher', 'jan-keller', 'werner-wechsler' ] } Important to note is that Groups and Plone users are both listed under 'internal_attendees' (due to UserAndGroupSelectionWidget), but that they must be separated into two groups in the returned dict. """ mtool = getToolByName(context, 'portal_membership') gtool = getToolByName(context, 'portal_groups') group_ids = gtool.getGroupIds() storage = IAttendeesStorage(context) new_attendees = { 'internal_attendees': [], 'external_attendees': [], 'groups': [], } old_names = [k['id'] for k in storage.get('internal_attendees', [])] old_groups = [k['name'] for k in storage.get('groups', [])] # Groups in the same widget as internal users so is stored under # 'internal_attendees'. We'll have to deal with them here... for name in data.get('internal_attendees', []): if name in group_ids: if name in old_groups: continue # Group group = gtool.getGroupById(name) new_attendees['groups'].append({'name': group.id}) elif name not in old_names: # User member = mtool.getMemberById(name) new_attendees['internal_attendees'].append({ 'name': member.getProperty('fullname', None) or member.id, 'email': member.getProperty('email') }) for entry in data.get('external_attendees', []): if entry in storage.get('external_attendees', []): continue new_attendees['external_attendees'].append(entry) return new_attendees
def get_invited_usernames(context): storage = IAttendeesStorage(context) return [m['id'] for m in storage.get('internal_attendees', [])]
def get_invited_groups(context): storage = IAttendeesStorage(context) return [g['name'] for g in storage.get('groups', [])]