예제 #1
0
파일: views.py 프로젝트: lujancita/gplib
def catalog_items(status, user):
    if status.endswith('libro'):
        wfname = 'procesos_tecnicos'
    elif status.endswith('revista'):
        wfname = 'hemeroteca'
    else:
        raise Exception, 'revista or libro'

    filter_items = WFItem.view('couchflow/filter_items')

    items_query = filter_items[status]

    selected_items = [item['id'] for item in items_query]

    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
예제 #2
0
파일: views.py 프로젝트: lujancita/gplib
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()