def filter_wflows(user): for i in ('libro', 'revista'): catalog_items('a catalogar %s' % i, user) # TODO return db = FilterWFItems.get_db() wf_tasks = db.view("couchflow/wf_by_first_task_type", include_docs=True)["FilterWFItems":"FilterWFItems"] tasks = {} wflows = [] wf_tasks = wf_tasks.all() for value in wf_tasks: if value["doc"]["doc_type"] == "WorkFlow": wflows.append(WorkFlow.wrap(value["doc"])) elif value["doc"]["doc_type"] == "FilterWFItems": task = FilterWFItems.wrap(value["doc"]) tasks[task._id] = task for wf in wflows: task = tasks.get(wf.first_task_id, None) if not task: raise Exception, "Check" field = task.item_fields.get("99989", None) print "Filter by", field if not field: print "cant get status field" continue filter_items = WFItem.view('couchflow/filter_items') items_query = filter_items[field] selected_items = [item['id'] for item in items_query] if not selected_items: continue clone = clone_this_wf(wf._id, user._id) clone.set_enabled() try: clone.save() except Exception, error: print error tasks = Task.view("couchflow/activetask", include_docs=True) tasks = tasks[clone._id] task = tasks.one() task.wfitems_ids = selected_items task.save() task.active_conector()
def get_tasks(user=None, exclude=None, include=None): exclude = exclude or [] include = include or [] #tasks = Task.view("couchflow/usertask", include_docs=True) db = Task.get_db() items_tasks = db.view('couchflow/usertask2', include_docs=True) if user: start = [user._id] end = [user._id, {}] items, tasks = get_item_tasks(items_tasks[start:end]) else: items, tasks = get_item_tasks(items_tasks) tasks_dic = {} for task in tasks: if task: tasks_dic[task['_id']] = task if user: for group in user.groups: start = [group] end = [group, {}] group_items, group_tasks = get_item_tasks(items_tasks[start:end]) items.update(group_items) for task in group_tasks: tasks_dic[task['_id']] = task wf_tasks = {} for task in tasks_dic.values(): item = items[task['wfitems_ids'][0]] item["id"] = item["_id"] task["id"] = task["_id"] task["is_bulkable"] = is_bulkable(task) status = get_task_status(item) if not status: continue #wf = cache.get(task.workflow_id, None) #if not wf: # wf = WorkFlow.get(task.workflow_id) #wf_type = wf.workflow_type.split('_', 1)[0] wf_type = task['workflow_type'].split('_', 1)[0] if exclude and wf_type in exclude: continue if include and wf_type not in include: continue nro_pedido = item["order_nbr"] if nro_pedido not in wf_tasks: wf_tasks[nro_pedido] = [] wf_tasks[nro_pedido].append(nro_pedido) wf_tasks[nro_pedido].append(task) #save_tasks.append(task) tasks = [task for values in wf_tasks.values() for task in values] #db.bulk_save(save_tasks) return tasks
if not selected_items: return workflows = WorkFlow.view("couchflow/orig_workflows", include_docs=True) workflows = workflows[wfname] workflow = workflows.one() clone = clone_this_wf(workflow._id, user._id) clone.set_enabled() try: clone.save() except Exception, error: print error tasks = Task.view("couchflow/activetask", include_docs=True) tasks = tasks[clone._id] task = tasks.one() task.wfitems_ids = selected_items task.save() task.active_conector() return len(items_query) @login_required def tech_process(request): user_obj = request.user user = None