示例#1
0
文件: 021.py 项目: mightymau/hubspace
def setup_microsite_spaces(): 
    """Create the microsites spaces object
    """
    from hubspace.model import ObjectReference, Page, ListItem, PublicSpace, Location, MetaData, MicroSiteSpace, PublicPlace, User
    from hubspace.microSite import microsite_pages, microsite_page_types, microsite_left_page_list, microsite_right_page_list, append_existing_item
    Page.createTable(ifNotExists=True)
    ObjectReference.createTable(ifNotExists=True)
    ListItem.createTable(ifNotExists=True)
    PublicSpace.createTable(ifNotExists=True)
    PublicPlace.createTable(ifNotExists=True)
    MetaData.createTable(ifNotExists=True)
    for user in User.select():
        ObjectReference(**{'object': (user.__class__.__name__, user.id)})

    for loc in Location.select():
        if loc.id == 16 or not loc.url:
            continue
       
        try:
            old_space = MicroSiteSpace.select(AND(MicroSiteSpace.q.locationID==loc.id,
                                                  MicroSiteSpace.q.nextID==None))[0]
        except IndexError:
            print `loc.name` + " doesn't have any spaces to migrate"
            old_space = None
            
        next_item = None
        while old_space:
            new_space = PublicSpace(name=old_space.name, description=old_space.description, image=old_space.image)
            object_ref = ObjectReference.selectBy(object_type='PublicSpace', object_id=new_space.id)[0]
            new_list_item = ListItem(next=next_item, location=loc, active=old_space.active, list_name="spaces_list", object_ref=object_ref)
            next_item = new_list_item
            old_space = old_space.previous

        ObjectReference(**{'object': (loc.__class__.__name__, loc.id)})
        for page, type in microsite_pages.items():
            microsite_page_types[type].create_page(page, loc, {})
        
        kwargs = {'location':loc, 'object_type': Page, 'active': 1}
        for page in microsite_left_page_list:
            kwargs.update({'name':page})
            try:
                page = Page.select(AND(Page.q.location == loc,
                                       IN(Page.q.path_name, [page, page + '.html'])))[0]
                append_existing_item('left_tabs', page, **kwargs)
            except IndexError:
                pass
        for page in microsite_right_page_list: 
            kwargs.update({'name':page})
            try:
                page = Page.select(AND(Page.q.location == loc,
                                       IN(Page.q.path_name, [page, page + '.html'])))[0]
                append_existing_item('right_tabs', page, **kwargs)
            except IndexError:
                pass
示例#2
0
文件: 028.py 项目: mightymau/hubspace
def migrate_lists():
    from hubspace.model import Page, List, ListItem, Location
    from hubspace.microSite import list_types
    
    for location in Location.select():
        results = Page.selectBy(location=location, path_name='index.html')
        if results.count() == 0:
            continue;
        else:            
            indexpage = results[0] 

        for list_name, data in list_types.items():
            object_types = ','.join(data['object_types'])
            mode = data['mode']
            thelist = List(list_name=list_name,
                           object_types=object_types,
                           mode=mode,
                           page=indexpage,
                           location=location,)
            for listitem in ListItem.selectBy(location=location,list_name=list_name):
                listitem.list = thelist