Allura/allura/lib/plugin.py
def _create_project(self, neighborhood, shortname, project_name, user, user_project, private_project, apps):
        '''
        Actually create the project, no validation.  This should not be called directly
        under normal circumstances.
        '''
        from allura import model as M

        project_template = neighborhood.get_project_template()
        p = M.Project(neighborhood_id=neighborhood._id,
                      shortname=shortname,
                      name=project_name,
                      short_description='',
                      description=(
                          'You can edit this description in the admin page'),
                      homepage_title=shortname,
                      last_updated = datetime.utcnow(),
                      is_nbhd_project=False,
                      is_root=True)
        p.configure_project(
            users=[user],
            is_user_project=user_project,
            is_private_project=private_project or project_template.get(
                'private', False),
            apps=apps or [] if 'tools' in project_template else None)

        # Setup defaults from neighborhood project template if applicable
        offset = p.next_mount_point(include_hidden=True)
        if 'groups' in project_template:
            for obj in project_template['groups']:
                name = obj.get('name')
                permissions = set(obj.get('permissions', [])) & \
                    set(p.permissions)
                usernames = obj.get('usernames', [])
                # Must provide a group name
                if not name:
                    continue
                # If the group already exists, we'll add users to it,
                # but we won't change permissions on the group
                group = M.ProjectRole.by_name(name, project=p)
                if not group:
                    # If creating a new group, *must* specify permissions
                    if not permissions:
                        continue
                    group = M.ProjectRole(project_id=p._id, name=name)
                    p.acl += [M.ACE.allow(group._id, perm)
                              for perm in permissions]
                for username in usernames:
                    guser = M.User.by_username(username)
                    if not (guser and guser._id):
                        continue
                    pr = M.ProjectRole.by_user(guser, project=p, upsert=True)
                    if group._id not in pr.roles:
                        pr.roles.append(group._id)
        if 'tools' in project_template:
            for i, tool in enumerate(project_template['tools'].keys()):
                tool_config = project_template['tools'][tool]
                tool_options = tool_config.get('options', {})
                for k, v in tool_options.iteritems():
                    if isinstance(v, basestring):
                        tool_options[k] = \
                            string.Template(v).safe_substitute(
                                p.__dict__.get('root_project', {}))
                if p.app_instance(tool) is None:
                    app = p.install_app(tool,
                                        mount_label=tool_config['label'],
                                        mount_point=tool_config['mount_point'],
                                        ordinal=i + offset,
                                        **tool_options)
                    if tool == 'wiki':
                        from forgewiki import model as WM
                        text = tool_config.get('home_text',
                                               '[[members limit=20]]\n[[download_button]]')
                        WM.Page.query.get(
                            app_config_id=app.config._id).text = text

        if 'tool_order' in project_template:
            for i, tool in enumerate(project_template['tool_order']):
                p.app_config(tool).options.ordinal = i
        if 'labels' in project_template:
            p.labels = project_template['labels']
        if 'trove_cats' in project_template:
            for trove_type in project_template['trove_cats'].keys():
                troves = getattr(p, 'trove_%s' % trove_type)
                for trove_id in project_template['trove_cats'][trove_type]:
                    troves.append(
                        M.TroveCategory.query.get(trove_cat_id=trove_id)._id)
        if 'icon' in project_template:
            icon_file = StringIO(
                urlopen(project_template['icon']['url']).read())
            M.ProjectFile.save_image(
                project_template['icon']['filename'], icon_file,
                square=True, thumbnail_size=(48, 48),
                thumbnail_meta=dict(project_id=p._id, category='icon'))

        if user_project:
            # Allow for special user-only tools
            p._extra_tool_status = ['user']
            # add user project informative text to home
            from forgewiki import model as WM
            home_app = p.app_instance('wiki')
            home_page = WM.Page.query.get(app_config_id=home_app.config._id)
            home_page.text = ("This is the personal project of %s."
                              " This project is created automatically during user registration"
                              " as an easy place to store personal data that doesn't need its own"
                              " project such as cloned repositories.") % user.display_name

        # clear the RoleCache for the user so this project will
        # be picked up by user.my_projects()
        g.credentials.clear_user(user._id, None)  # unnamed roles for this user
        # named roles for this project + user
        g.credentials.clear_user(user._id, p._id)
        with h.push_config(c, project=p, user=user):
            ThreadLocalORMSession.flush_all()
            # have to add user to context, since this may occur inside auth code
            # for user-project reg, and c.user isn't set yet
            g.post_event('project_created')
        return p

        Actually create the project, no validation.  This should not be called directly
        under normal circumstances.
        
Actually create the project, no validation.  This should not be called directly
under normal circumstances.
Actually create the project no validation . This should not be called directly under normal circumstances .
def _create_project(self, neighborhood, shortname, project_name, user, user_project, private_project, apps):
        from allura import model as M
        project_template = neighborhood.get_project_template()
        p = M.Project(neighborhood_id=neighborhood._id,
                      shortname=shortname,
                      name=project_name,
                      short_description='',
                      description=(
                          'You can edit this description in the admin page'),
                      homepage_title=shortname,
                      last_updated = datetime.utcnow(),
                      is_nbhd_project=False,
                      is_root=True)
        p.configure_project(
            users=[user],
            is_user_project=user_project,
            is_private_project=private_project or project_template.get(
                'private', False),
            apps=apps or [] if 'tools' in project_template else None)
        offset = p.next_mount_point(include_hidden=True)
        if 'groups' in project_template:
            for obj in project_template['groups']:
                name = obj.get('name')
                permissions = set(obj.get('permissions', [])) & \
                    set(p.permissions)
                usernames = obj.get('usernames', [])
                if not name:
                    continue
                group = M.ProjectRole.by_name(name, project=p)
                if not group:
                    if not permissions:
                        continue
                    group = M.ProjectRole(project_id=p._id, name=name)
                    p.acl += [M.ACE.allow(group._id, perm)
                              for perm in permissions]
                for username in usernames:
                    guser = M.User.by_username(username)
                    if not (guser and guser._id):
                        continue
                    pr = M.ProjectRole.by_user(guser, project=p, upsert=True)
                    if group._id not in pr.roles:
                        pr.roles.append(group._id)
        if 'tools' in project_template:
            for i, tool in enumerate(project_template['tools'].keys()):
                tool_config = project_template['tools'][tool]
                tool_options = tool_config.get('options', {})
                for k, v in tool_options.iteritems():
                    if isinstance(v, basestring):
                        tool_options[k] = \
                            string.Template(v).safe_substitute(
                                p.__dict__.get('root_project', {}))
                if p.app_instance(tool) is None:
                    app = p.install_app(tool,
                                        mount_label=tool_config['label'],
                                        mount_point=tool_config['mount_point'],
                                        ordinal=i + offset,
                                        **tool_options)
                    if tool == 'wiki':
                        from forgewiki import model as WM
                        text = tool_config.get('home_text',
                                               '[[members limit=20]]\n[[download_button]]')
                        WM.Page.query.get(
                            app_config_id=app.config._id).text = text
        if 'tool_order' in project_template:
            for i, tool in enumerate(project_template['tool_order']):
                p.app_config(tool).options.ordinal = i
        if 'labels' in project_template:
            p.labels = project_template['labels']
        if 'trove_cats' in project_template:
            for trove_type in project_template['trove_cats'].keys():
                troves = getattr(p, 'trove_%s' % trove_type)
                for trove_id in project_template['trove_cats'][trove_type]:
                    troves.append(
                        M.TroveCategory.query.get(trove_cat_id=trove_id)._id)
        if 'icon' in project_template:
            icon_file = StringIO(
                urlopen(project_template['icon']['url']).read())
            M.ProjectFile.save_image(
                project_template['icon']['filename'], icon_file,
                square=True, thumbnail_size=(48, 48),
                thumbnail_meta=dict(project_id=p._id, category='icon'))
        if user_project:
            p._extra_tool_status = ['user']
            from forgewiki import model as WM
            home_app = p.app_instance('wiki')
            home_page = WM.Page.query.get(app_config_id=home_app.config._id)
            home_page.text = ("This is the personal project of %s."
                              " This project is created automatically during user registration"
                              " as an easy place to store personal data that doesn't need its own"
                              " project such as cloned repositories.") % user.display_name
        g.credentials.clear_user(user._id, None)  
        g.credentials.clear_user(user._id, p._id)
        with h.push_config(c, project=p, user=user):
            ThreadLocalORMSession.flush_all()
            g.post_event('project_created')
        return p
def _create_project ( self , neighborhood , shortname , project_name , user , user_project , private_project , apps ) : from allura import model as M project_template = neighborhood . get_project_template ( ) p = M . Project ( neighborhood_id = neighborhood . _id , shortname = shortname , name = project_name , short_description = '' , description = ( 'You can edit this description in the admin page' ) , homepage_title = shortname , last_updated = datetime . utcnow ( ) , is_nbhd_project = False , is_root = True ) p . configure_project ( users = [ user ] , is_user_project = user_project , is_private_project = private_project or project_template . get ( 'private' , False ) , apps = apps or [ ] if 'tools' in project_template else None ) offset = p . next_mount_point ( include_hidden = True ) if 'groups' in project_template : for obj in project_template [ 'groups' ] : name = obj . get ( 'name' ) permissions = set ( obj . get ( 'permissions' , [ ] ) ) & set ( p . permissions ) usernames = obj . get ( 'usernames' , [ ] ) if not name : continue group = M . ProjectRole . by_name ( name , project = p ) if not group : if not permissions : continue group = M . ProjectRole ( project_id = p . _id , name = name ) p . acl += [ M . ACE . allow ( group . _id , perm ) for perm in permissions ] for username in usernames : guser = M . User . by_username ( username ) if not ( guser and guser . _id ) : continue pr = M . ProjectRole . by_user ( guser , project = p , upsert = True ) if group . _id not in pr . roles : pr . roles . append ( group . _id ) if 'tools' in project_template : for i , tool in enumerate ( project_template [ 'tools' ] . keys ( ) ) : tool_config = project_template [ 'tools' ] [ tool ] tool_options = tool_config . get ( 'options' , { } ) for k , v in tool_options . iteritems ( ) : if isinstance ( v , basestring ) : tool_options [ k ] = string . Template ( v ) . safe_substitute ( p . __dict__ . get ( 'root_project' , { } ) ) if p . app_instance ( tool ) is None : app = p . install_app ( tool , mount_label = tool_config [ 'label' ] , mount_point = tool_config [ 'mount_point' ] , ordinal = i + offset , ** tool_options ) if tool == 'wiki' : from forgewiki import model as WM text = tool_config . get ( 'home_text' , '[[members limit=20]]\n[[download_button]]' ) WM . Page . query . get ( app_config_id = app . config . _id ) . text = text if 'tool_order' in project_template : for i , tool in enumerate ( project_template [ 'tool_order' ] ) : p . app_config ( tool ) . options . ordinal = i if 'labels' in project_template : p . labels = project_template [ 'labels' ] if 'trove_cats' in project_template : for trove_type in project_template [ 'trove_cats' ] . keys ( ) : troves = getattr ( p , 'trove_%s' % trove_type ) for trove_id in project_template [ 'trove_cats' ] [ trove_type ] : troves . append ( M . TroveCategory . query . get ( trove_cat_id = trove_id ) . _id ) if 'icon' in project_template : icon_file = StringIO ( urlopen ( project_template [ 'icon' ] [ 'url' ] ) . read ( ) ) M . ProjectFile . save_image ( project_template [ 'icon' ] [ 'filename' ] , icon_file , square = True , thumbnail_size = ( 48 , 48 ) , thumbnail_meta = dict ( project_id = p . _id , category = 'icon' ) ) if user_project : p . _extra_tool_status = [ 'user' ] from forgewiki import model as WM home_app = p . app_instance ( 'wiki' ) home_page = WM . Page . query . get ( app_config_id = home_app . config . _id ) home_page . text = ( "This is the personal project of %s." " This project is created automatically during user registration" " as an easy place to store personal data that doesn't need its own" " project such as cloned repositories." ) % user . display_name g . credentials . clear_user ( user . _id , None ) g . credentials . clear_user ( user . _id , p . _id ) with h . push_config ( c , project = p , user = user ) : ThreadLocalORMSession . flush_all ( ) g . post_event ( 'project_created' ) return p
Actually create the project, no validation.
Actually create the project no validation .
'''
        Actually create the project, no validation.  This should not be called directly
        under normal circumstances.
        ''' # Setup defaults from neighborhood project template if applicable # Must provide a group name # If the group already exists, we'll add users to it, # but we won't change permissions on the group # If creating a new group, *must* specify permissions # Allow for special user-only tools # add user project informative text to home # clear the RoleCache for the user so this project will # be picked up by user.my_projects() # unnamed roles for this user # named roles for this project + user # have to add user to context, since this may occur inside auth code # for user-project reg, and c.user isn't set yet
self
neighborhood
shortname
project_name
user
user_project
private_project
apps