Beispiel #1
0
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
Beispiel #2
0
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,
            }