Ejemplo n.º 1
0
 def create_group(user_id, name, desc, owner, parent_id, join_pol, memb_vis, memb_edit=''):
     if not group_db.has_key(user_id):
         g = group_db.create_group(user_id=user_id,
             name=name,
             description=desc,
             owner=owner,
             no_pay=True)
         group_db.force_accept(g)
         if parent_id:
             group_db.join_group(g, group_db[parent_id], force=1)
 
     g = group_db[user_id]
     if join_pol:
         api.group_set_join_policy(user_admin, g, join_pol)
         if join_pol == 'open':
             # if membership is open, allow non-members to read
             api.group_set_other_perms(user_admin, g, 'ro')
     if memb_vis:
         api.group_set_membership_visible(user_admin, g, memb_vis)
     if desc:
         api.group_set_settings(user_admin, g, description=desc)
     if memb_edit:
         api.group_set_member_edit(user_admin, g, memb_edit)
         
     # set date of formation
     create = datetime(2004, 05, 10, 12, 0, 0)
     g.date = create
Ejemplo n.º 2
0
def create_initial_groups():
    """Create initial top-level groups if they don't already exist."""
    
    from base import get_group_database, get_user_database
    import api
    
    # we want any groups we create in here to be active immediately
    save_min_sponsors = Group._min_sponsors
    Group._min_sponsors = 1
    
    user_db = get_user_database()
    group_db = get_group_database()
    
    user_admin = user_db['admin']
    
    def create_group(user_id, name, desc, owner, parent_id, join_pol, memb_vis, memb_edit=''):
        if not group_db.has_key(user_id):
            g = group_db.create_group(user_id=user_id,
                name=name,
                description=desc,
                owner=owner,
                no_pay=True)
            group_db.force_accept(g)
            if parent_id:
                group_db.join_group(g, group_db[parent_id], force=1)
    
        g = group_db[user_id]
        if join_pol:
            api.group_set_join_policy(user_admin, g, join_pol)
            if join_pol == 'open':
                # if membership is open, allow non-members to read
                api.group_set_other_perms(user_admin, g, 'ro')
        if memb_vis:
            api.group_set_membership_visible(user_admin, g, memb_vis)
        if desc:
            api.group_set_settings(user_admin, g, description=desc)
        if memb_edit:
            api.group_set_member_edit(user_admin, g, memb_edit)
            
        # set date of formation
        create = datetime(2004, 05, 10, 12, 0, 0)
        g.date = create
    
    
    groups = [
        ('top', 'Top', 'This group contains the top-level groups.', user_admin, None, '', 'open', ''),
        ('regional', 'Regional', 'Contains groups with a regional focus.', user_admin, 'top', '', 'open', ''),
        ('orgs', 'Organizations', 'Contains categories of organizations.', user_admin, 'top', '', 'open', ''),
        ('community', 'Community', 'Contains groups that are focused or based on ned.com.', user_admin, 'top', '', 'open', ''),
        ('issues', 'Issues', 'Contains groups focused on particular issues.', user_admin, 'top', '', 'open', ''),
        ('general', 'General', 'Contains groups that don\'t belong in other categories.', user_admin, 'top', 'open', 'open', ''),
        ('general-other', 'General', 'Contains groups that don\'t belong in other categories.', user_admin, 'general', 'open', 'open', ''),
        ('help', 'Help', 'Contains site help.', user_admin, 'community', '', 'open', ''),
        ('community-general', 'Community - General',
            '', user_admin, 'community', 'open', 'open', 'member'),
        ('suggestions', 'Suggestions', 'For community suggestions.', user_admin, 'community-general', '', 'open', ''),
        ('public', 'Public sector',
            'Groups operating in the public sector should join this group.', user_admin, 'orgs', 'open', 'open', 'member'),
        ('private', 'Private sector',
            'Groups operating in the private sector should join this group.', user_admin, 'orgs', 'open', 'open', 'member'),
        ('social', 'Social sector',
            'Groups operating in the social sector should join this group.', user_admin, 'orgs', 'open', 'open', 'member'),
        ('orgs-general', 'Organizations - General',
            "For organizations that don't fit in other categories.", user_admin, 'orgs', 'open', 'open', 'member'),
        ('issues-business', 'Business',
            '', user_admin, 'issues', 'open', 'open', 'member'),
        ('issues-cyf', 'Children - Youth - Families',
            '', user_admin, 'issues', 'open', 'open', 'member'),
        ('issues-education', 'Education',
            '', user_admin, 'issues', 'open', 'open', 'member'),
        ('issues-env', 'Environment - Conservation',
            '', user_admin, 'issues', 'open', 'open', 'member'),
        ('issues-health', 'Health Care',
            '', user_admin, 'issues', 'open', 'open', 'member'),
        ('issues-pol', 'Policy - Politics',
            '', user_admin, 'issues', 'open', 'open', 'member'),
        ('issues-religion', 'Religion',
            '', user_admin, 'issues', 'open', 'open', 'member'),
        ('issues-soc', 'Social Justice - Human Services',
            '', user_admin, 'issues', 'open', 'open', 'member'),
        ('issues-tech', 'Technology',
            '', user_admin, 'issues', 'open', 'open', 'member'),
        ('issues-general', 'Issues - General',
            '', user_admin, 'issues', 'open', 'open', 'member'),
        ('ned', '<ned> Network',
            '', user_admin, '', '', '', ''),
        ('ned-internal', 'Ned - Internal',
            '', user_admin, '', '', '', ''),
        ('sitedev', 'Site Development',
            '', user_admin, 'ned-internal', '', '', ''),
        ]
    
    for user_id, name, desc, owner, parent_id, join_pol, memb_vis, memb_edit in groups:
        create_group(user_id, name, desc, owner, parent_id, join_pol, memb_vis, memb_edit)
    
    # Help group
    g_help = group_db['help']
    api.group_set_anon_read(user_admin, g_help, True)
                            
    # ON groups
    g_on = group_db['ned']
    group_db.join_group(g_on, group_db['private'], force=1)
    group_db.join_group(g_on, group_db['public'], force=1)
    group_db.join_group(g_on, group_db['social'], force=1)
    api.group_set_owners_by_user_id(user_admin, g_on, ['admin', 'jimc'])
    api.group_set_join_policy(user_admin, g_on, 'owner')
    api.group_set_invite_policy(user_admin, g_on, 'owner')
    api.group_set_membership_visible(user_admin, g_on, 'open')
    api.group_set_member_edit(user_admin, g_on, True)
    api.group_set_anon_read(user_admin, g_on, True)
        
    g_on_int = group_db['ned-internal']
    api.group_set_owners_by_user_id(user_admin, g_on_int, ['admin', 'jimc'])
    api.group_set_join_policy(user_admin, g_on_int, 'owner')
    api.group_set_invite_policy(user_admin, g_on_int, 'owner')
    api.group_set_membership_visible(user_admin, g_on_int, 'member')
    api.group_set_member_edit(user_admin, g_on_int, True)
    api.group_set_anon_read(user_admin, g_on_int, False)
    
    g_sitedev = group_db['sitedev']
    api.group_set_owners_by_user_id(user_admin, g_sitedev, ['admin', 'jimc'])
    
    Group._min_sponsors = save_min_sponsors