def get_link_targets(request): pagestore = pagestore_manager.get_pagestore_by_type('mongo') project_id = request.GET['project_id'] response = create_response(200) #获得category集合 categories = [] category_records = pagestore.get_records(project_id, category_page_id) for category_record in category_records: categories.append({ 'text': category_record['model']['name'], 'value': './?type=viper&rid=' + category_record['id'] }) #获得article article_records = pagestore.get_records(project_id, article_page_id) articles = [] for article_record in article_records: articles.append({ 'text': article_record['model']['title'], 'value': './?type=viper&rid=' + article_record['id'] }) response.data = [{ 'name': u'文章分类', 'data': categories }, { 'name': u'文章', 'data': articles }] return response.get_response()
def delete_project(request, project_id): #删除mongo中project所有的page pagestore = pagestore_manager.get_pagestore_by_type('mongo') pagestore.remove_project_pages(str(project_id)) #删除project本身 Project.objects.filter(id=project_id).delete() return HttpResponseRedirect(request.META['HTTP_REFERER'])
def __delete_workspaces(workspace_ids): pagestore = pagestore_manager.get_pagestore_by_type('mongo') project_ids = [] for workspace_id in workspace_ids: for project in Project.objects.filter(workspace_id=workspace_id): print '>>> remove mongo page in project ', project.id pagestore.remove_project_pages(str(project.id)) project_ids.append(project.id) Project.objects.filter(id__in=project_ids).delete() Workspace.objects.filter(id__in=workspace_ids).delete()
def __delete_project(project): pagestore = pagestore_manager.get_pagestore_by_type('mongo') #module_project = Project.objects.get(id=project_id) ''' for jqm_project in Project.objects.filter(datasource_project_id=module_project.id): pagestore.remove_project_pages(str(jqm_project.id)) Project.objects.filter(datasource_project_id=module_project.id).delete() ''' pagestore.remove_project_pages(str(project.id)) Project.objects.filter(id=project.id).delete()
def handle(self, **options): Command.pagestore = pagestore_manager.get_pagestore_by_type('mongo') manager = User.objects.get(username='******') manager_projects = Project.objects.filter(owner=manager) manager_project_ids = set([p.id for p in manager_projects]) id2project = dict([(p.id, p) for p in manager_projects]) all_users = [ user for user in User.objects.all() if (user.username != 'admin' and user.username != 'manager') ] id2user = dict([(user.id, user) for user in all_users]) #搜集user的project信息 user2projects = {} for user in all_users: user_project_ids = set([ p.source_project_id for p in Project.objects.filter(owner=user) ]) missing_project_ids = list(manager_project_ids - user_project_ids) if len(missing_project_ids) > 0: missing_projects = set() added_projects = set() for missing_project_id in missing_project_ids: missing_project = id2project[missing_project_id] if missing_project.inner_name in added_projects: continue else: missing_projects.add(missing_project) added_projects.add(missing_project.inner_name) user2projects[user.id] = missing_projects if len(user2projects) == 0: print 'no user should be update' return print u'缺失webapp project的用户为:' print '\tUSER\tPROJECTS' for user_id, projects in user2projects.items(): print '\t', id2user[user_id].username, '\t', for project in projects: print project.name, print '' while True: print u'\npress "y" to install project for all user, "n" to exit' print '>>>', value = raw_input() if value == 'n': return if value == 'y': break for user_id, projects in user2projects.items(): user = id2user[user_id] for project in projects: self.install_webapp_project(user, project.inner_name) self.set_template_project(user) print 'finish!'
def add_module(request): pagestore = pagestore_manager.get_pagestore_by_type('mongo') #获得页面上选中的module module_ids = [] for key, value in request.POST.items(): if key.startswith('module_'): module_ids.append(int(value)) module_id_set = set(module_ids) #获得用户已经创建的workspace existed_workspaces = list(Workspace.objects.filter(owner=request.user)) existed_source_workspace_id_set = set() modules_need_restore = set() modules_need_delete = set() for existed_workspace in existed_workspaces: existed_source_workspace_id_set.add( existed_workspace.source_workspace_id) if (existed_workspace.source_workspace_id in module_id_set) and existed_workspace.is_deleted: #已删除的workspace出现在选中的workspace集合中,需要恢复 modules_need_restore.add(existed_workspace.id) continue if not (existed_workspace.source_workspace_id in module_id_set): #已有的workspace不在选中的workspace集合中,需要删除 modules_need_delete.add(existed_workspace.id) continue modules_need_add = module_id_set - existed_source_workspace_id_set #处理需要创建的module workspace id2module = dict([(workspace.id, workspace) for workspace in Workspace.objects.filter( id__in=list(modules_need_add))]) for module_workspace_id, module_workspace in id2module.items(): new_workspace = Workspace.objects.create( owner=request.user, name=module_workspace.name, source_workspace_id=module_workspace.id, data_backend=module_workspace.data_backend) module_projects = list( Project.objects.filter(workspace=module_workspace_id)) #复制workspace下的jqm project,及其page template_project = None #template_project默认为遇到的第一个jqm project new_data_backend = None for module_project in module_projects: new_project = Project.objects.create( owner=request.user, workspace_id=new_workspace.id, name=module_project.name, type=module_project.type, source_project_id=module_project.id, datasource_project_id=0) if module_project.type == 'viper': #跳过viper project,不拷贝page new_data_backend = 'viper:%d' % new_project.id continue pagestore.copy_project_pages(str(module_project.id), str(new_project.id)) if not template_project: template_project = new_project if new_data_backend: Workspace.objects.filter(id=new_workspace.id).update( template_project_id=template_project.id, data_backend=new_data_backend) else: Workspace.objects.filter(id=new_workspace.id).update( template_project_id=template_project.id) #处理需要恢复的module workspace #Workspace.objects.filter(id__in=list(modules_need_restore)).update(is_deleted = False) #处理需要删除的module workspace #Workspace.objects.filter(id__in=list(modules_need_delete)).update(is_deleted = True) #做物理删除 __delete_workspaces(list(modules_need_delete)) return HttpResponseRedirect('/webapp/modules/')
def __get_modules_page_second_navs(workspaces): pagestore = pagestore_manager.get_pagestore_by_type('mongo') second_navs = [] for workspace in workspaces: if workspace.is_deleted: continue if 'viper:' in workspace.data_backend: project_id = workspace.data_backend.split(':')[-1] project = Project.objects.get(id=project_id) #取viper project的source project的page集合 pages = list(pagestore.get_pages(str(project.source_project_id))) webapp_editor_nav = {'section': workspace.name, 'navs': []} for page in pages: page_id = page['page_id'] page_model = page['component']['model'] print page_model if page_model.get('is_free_page', 'no') == 'yes': url = '/workbench/viper/page/?project_id=%s&page_id=%s' % ( project_id, page_id) else: url = '/workbench/viper/records/?project_id=%s&page_id=%s' % ( project_id, page_id) webapp_editor_nav['navs'].append({ 'name': page_id, 'url': url, 'title': page['component']['model']['navName'] }) #插入“管理模板” ''' webapp_editor_nav['navs'].append({ 'name': 'template', 'url': '/termite/workbench/project/edit/%d/' % workspace.template_project_id, 'title': u'模板管理' }) ''' second_navs.append(webapp_editor_nav) elif 'module:' in workspace.data_backend: export_module_name = 'webapp.modules.%s.export' % workspace.data_backend.split( ':')[-1] module = __import__(export_module_name, {}, {}, [ '*', ]) #second_navs.append({'section': workspace.name, 'navs':module.NAV['navs']}) nav = copy.deepcopy(module.NAV) #插入“管理模板” ''' nav['navs'].append({ 'name': 'template', 'url': '/termite/workbench/project/edit/%d/' % workspace.template_project_id, 'title': u'模板管理' }) ''' second_navs.append(nav) else: pass ''' second_navs.append( { 'section': u'微站模块', 'navs': [{ 'name': 'module', 'title': u'模块管理', 'url': '/webapp/modules/', }] } ) second_navs.append( { 'section': u'微站统计', 'navs': [{ 'name': 'statistics', 'title': u'流量统计', 'url': '/webapp/visit_statistics/', }] } ) ''' return second_navs