示例#1
0
文件: views.py 项目: GaloC/gplib
def use_reference(request, item_id, reference_id, client_side_changes=None):
    reference = WFItem.get(reference_id)

    data = {'success': True}

    bad_references = []

    changes = []
    for _id, field in reference.fields_properties.iteritems():
        if int(_id) > 999:
            continue

        first = field.list[0]
        if first.subfields:
            for sub_id, subfield in first.subfields.iteritems():
                if subfield.exec_value:
                    name = "%s / %s" % (field.field_name, subfield.description)
                    changes.append((_id, sub_id, name, subfield.exec_value))
        else:
            if first.exec_value:
               changes.append((_id, None, field.field_name,
                   first.exec_value))

    item = WFItem.get(item_id)
    item.fields_properties[_id] = field

    for _id, sub_id, name, values in changes:

        if _id not in item.fields_properties.keys():
            print "bad ref", _id
            bad_references.append(_id)
            continue

        first = item.fields_properties[_id].list[0]
        if sub_id:
            if sub_id not in first.subfields:
                print "bad ref sub", _id, sub_id
                bad_references.append("%s_%s" % (_id, sub_id))
                continue

            if client_side_changes is None:
                first.subfields[sub_id].exec_value = values
        else:
            if client_side_changes is None:
                try:
                    first.exec_value = values
                except Exception, error:
                    print "Error cant insert"
                    print values, "in"
                    print first
示例#2
0
def use_reference(request, item_id, reference_id, client_side_changes=None):
    reference = WFItem.get(reference_id)

    data = {'success': True}

    bad_references = []

    changes = []
    for _id, field in reference.fields_properties.iteritems():
        if int(_id) > 999:
            continue

        first = field.list[0]
        if first.subfields:
            for sub_id, subfield in first.subfields.iteritems():
                if subfield.exec_value:
                    name = "%s / %s" % (field.field_name, subfield.description)
                    changes.append((_id, sub_id, name, subfield.exec_value))
        else:
            if first.exec_value:
                changes.append((_id, None, field.field_name, first.exec_value))

    item = WFItem.get(item_id)
    item.fields_properties[_id] = field

    for _id, sub_id, name, values in changes:

        if _id not in item.fields_properties.keys():
            print "bad ref", _id
            bad_references.append(_id)
            continue

        first = item.fields_properties[_id].list[0]
        if sub_id:
            if sub_id not in first.subfields:
                print "bad ref sub", _id, sub_id
                bad_references.append("%s_%s" % (_id, sub_id))
                continue

            if client_side_changes is None:
                first.subfields[sub_id].exec_value = values
        else:
            if client_side_changes is None:
                try:
                    first.exec_value = values
                except Exception, error:
                    print "Error cant insert"
                    print values, "in"
                    print first
示例#3
0
文件: views.py 项目: GaloC/gplib
def edit_item(request, item_id, existence=False):
    item = WFItem.get(item_id)
    if not item:
        return HttpResponseNotFound()

    wf_name = "%s_editor" % item.item_type
    if existence:
        wf_name = "%s_editor_existencia" % item.item_type

    workflow = WorkFlow.view("couchflow/orig_workflows",
        include_docs=True)[wf_name].one()

    if not workflow:
        return HttpResponseNotFound()
    workflow = clone_this_wf(workflow._id, request.user._id)

    workflow.nro_pedido = get_nro_pedido()
    workflow.visible = False
    workflow.set_enabled()
    try:
        workflow.save()
    except ResourceConflict:
        pass

    task = Task.view("couchflow/activetask",
        include_docs=True)[workflow._id].one()
    if not existence:
        task.wfitems_ids = [item_id]
    else:
        task.base_item = item_id
    task.visible = False
    task.save()

    return HttpResponseRedirect("/couchflow/execute_task/%s/" % task._id)
示例#4
0
def edit_item(request, item_id, existence=False):
    item = WFItem.get(item_id)
    if not item:
        return HttpResponseNotFound()

    wf_name = "%s_editor" % item.item_type
    if existence:
        wf_name = "%s_editor_existencia" % item.item_type

    workflow = WorkFlow.view("couchflow/orig_workflows",
                             include_docs=True)[wf_name].one()

    if not workflow:
        return HttpResponseNotFound()
    workflow = clone_this_wf(workflow._id, request.user._id)

    workflow.nro_pedido = get_nro_pedido()
    workflow.visible = False
    workflow.set_enabled()
    try:
        workflow.save()
    except ResourceConflict:
        pass

    task = Task.view("couchflow/activetask",
                     include_docs=True)[workflow._id].one()
    if not existence:
        task.wfitems_ids = [item_id]
    else:
        task.base_item = item_id
    task.visible = False
    task.save()

    return HttpResponseRedirect("/couchflow/execute_task/%s/" % task._id)
示例#5
0
def clone_edit_item(request, item_id):
    item = WFItem.get(item_id)
    if not item:
        return HttpResponseNotFound()

    #clone = item.really_clone(save=True)
    #return edit_item(request, clone._id, True)
    return edit_item(request, item_id, True)
示例#6
0
文件: views.py 项目: GaloC/gplib
def clone_edit_item(request, item_id):
    item = WFItem.get(item_id)
    if not item:
        return HttpResponseNotFound()

    #clone = item.really_clone(save=True)
    #return edit_item(request, clone._id, True)
    return edit_item(request, item_id, True)
示例#7
0
def export_mrc(request, doc_id):
    item = WFItem.get(doc_id)
    if not item:
        return HttpResponseNotFound()

    data = item.marc_record().as_marc21()
    mimetype = "text/mrc"

    response = HttpResponse(data, mimetype=mimetype)
    response['Content-Disposition'] = 'attachment; filename=record.mrc'
    return response
示例#8
0
文件: views.py 项目: GaloC/gplib
def export_mrc(request, doc_id):
    item = WFItem.get(doc_id)
    if not item:
        return HttpResponseNotFound()

    data = item.marc_record().as_marc21()
    mimetype = "text/mrc"

    response = HttpResponse(data, mimetype=mimetype)
    response['Content-Disposition'] = 'attachment; filename=record.mrc'
    return response
示例#9
0
文件: views.py 项目: GaloC/gplib
def del_item(request, item_id, task_id):
    response_dict = {}
    item = WFItem.get(item_id)
    task = get_task(task_id)
    if item and task:
        if item_id in task.wfitems_ids:
            task.wfitems_ids.remove(item_id)
            item.delete()
            task.save()
            response_dict['response'] = True
            response_dict['status'] = "Item borrado correctamente"
        else:
            response_dict['response'] = False
            response_dict['status'] = "El item no existe en la tarea"
        return HttpResponse(simplejson.dumps(response_dict),\
                                mimetype='application/javascript')
    response_dict['response'] = False
    response_dict['status'] = "El item o la tarea no existen"
    return HttpResponse(simplejson.dumps(response_dict),\
                            mimetype='application/javascript')
示例#10
0
def del_item(request, item_id, task_id):
    response_dict = {}
    item = WFItem.get(item_id)
    task = get_task(task_id)
    if item and task:
        if item_id in task.wfitems_ids:
            task.wfitems_ids.remove(item_id)
            item.delete()
            task.save()
            response_dict['response'] = True
            response_dict['status'] = "Item borrado correctamente"
        else:
            response_dict['response'] = False
            response_dict['status'] = "El item no existe en la tarea"
        return HttpResponse(simplejson.dumps(response_dict),\
                                mimetype='application/javascript')
    response_dict['response'] = False
    response_dict['status'] = "El item o la tarea no existen"
    return HttpResponse(simplejson.dumps(response_dict),\
                            mimetype='application/javascript')
示例#11
0
文件: views.py 项目: GaloC/gplib
def get_cita(request, item_id):
    item = WFItem.get(item_id)

    cita_fields = [('100', 'a'), ('245', 'a'),
            ('260', 'b'), ('260', 'c')]
    cita = ''
    for f, sf in cita_fields:
        cfield = get_field(item, f, sf)
        if not cfield:
            #print "Invaid Cita!", f, sf
            cita = 'Cita no encontrada'
            break
        if sf:
            cfield = cfield[0]
        cita += cfield + ' '
    print "CITA"
    print cita

    data = simplejson.dumps({'success': True,
        'message': 'Success', 'data': cita})
    return HttpResponse(data, mimetype='application/json')
示例#12
0
文件: views.py 项目: GaloC/gplib
def render_barcode(request, doc_id):
    item = WFItem.get(doc_id)
    if not item or item.inventory_nbr is None or barcode is None:
        return HttpResponseNotFound()

    if ImageWriter is not None:
        writer = ImageWriter()
        mimetype = "image/png"
    else:
        # PIL not available, use SVG output instead
        writer = None
        mimetype = "image/svg+xml"

    output = StringIO()
    barcode.generate("code39", item.inventory_nbr, writer, output, {
        'module_width': 0.4,
        'module_height': 12,
        'text_distance': 3,
        'text_size': 12,
        'dpi': 96,
    })

    return HttpResponse(output.getvalue(), mimetype=mimetype)
示例#13
0
def get_cita(request, item_id):
    item = WFItem.get(item_id)

    cita_fields = [('100', 'a'), ('245', 'a'), ('260', 'b'), ('260', 'c')]
    cita = ''
    for f, sf in cita_fields:
        cfield = get_field(item, f, sf)
        if not cfield:
            #print "Invaid Cita!", f, sf
            cita = 'Cita no encontrada'
            break
        if sf:
            cfield = cfield[0]
        cita += cfield + ' '
    print "CITA"
    print cita

    data = simplejson.dumps({
        'success': True,
        'message': 'Success',
        'data': cita
    })
    return HttpResponse(data, mimetype='application/json')
示例#14
0
def render_barcode(request, doc_id):
    item = WFItem.get(doc_id)
    if not item or item.inventory_nbr is None or barcode is None:
        return HttpResponseNotFound()

    if ImageWriter is not None:
        writer = ImageWriter()
        mimetype = "image/png"
    else:
        # PIL not available, use SVG output instead
        writer = None
        mimetype = "image/svg+xml"

    output = StringIO()
    barcode.generate(
        "code39", item.inventory_nbr, writer, output, {
            'module_width': 0.4,
            'module_height': 12,
            'text_distance': 3,
            'text_size': 12,
            'dpi': 96,
        })

    return HttpResponse(output.getvalue(), mimetype=mimetype)
示例#15
0
def save_task(request, task_type, task_id):
    try:
        if task_type == "DecisionTask":
            task = DecisionTask.get(task_id)
            form = DecisionTaskForm(request.POST)
        elif task_type == "DynamicDataTask":
            task = DynamicDataTask.get(task_id)
            form = ExecDynamicForm(request.POST)
        elif task_type == "WFItemsLoader":
            task = WFItemsLoader.get(task_id)
            form = ExecWFItemsLoader(request.POST)
        elif task_type == "FilterWFItems":
            task = FilterWFItems.get(task_id)
            form = ExecFilterWFItemsForm(request.POST)
        elif task_type == "MarcImport":
            task = MarcImport.get(task_id)
            form = ExecMarcImportForm(request.POST)
    except ResourceNotFound:
        return HttpResponseRedirect('/')

    workflow = WorkFlow.get(task.workflow_id)

    if 'cancelar' in request.POST and \
           task.doc_type != 'FilterWFItems':
        if task.node_type == 'start':
            workflow.remove_relations()
            workflow.delete()
        return HttpResponseRedirect('/')

    elif 'cancelar' in request.POST and \
             task.doc_type == 'FilterWFItems':
        response_dict = {}
        response_dict['response'] = False
        response_dict['url'] = '/'
        return HttpResponse(simplejson.dumps(response_dict),\
                            mimetype='application/javascript')

    item = task.get_item()
    response_dict = {}

    item_validation_errors = []
    if task_type not in ('WFItemsLoader', ):
        item_validation_errors = item.check_form(request.POST, task)

    if form.is_valid() and not item_validation_errors:
        user = request.user

        task.saved_by = user._id

        if item.is_clone:
            item.comments = form.cleaned_data['comments']
            item.save()

        if task.doc_type == "DecisionTask" or \
                task.doc_type == "DynamicDataTask":
            if item.is_clone:

                images = save_task_item(request, item, task)
                item.save()

                save_images(item, images)

                more_items = []
                if len(task.wfitems_ids) > 1:
                    more_items = [WFItem.get(x) for x in task.wfitems_ids]
                elif task.group_by_urn:
                    more_items = WFItem.view(
                        "couchflow/by_urn", include_docs=True)[item.urn].all()

                if more_items:
                    for new_item in more_items:
                        if new_item._id != item._id:
                            # TODO: don't replace all the properties
                            new_item.fields_properties = item.fields_properties

                            new_item.comments = item.comments
                            try:
                                new_item.save()
                            except ResourceConflict:
                                pass

        if task.doc_type == "DynamicDataTask":
            for field in task.extra_fields:
                field_data = request.POST.getlist(field)
                if field_data == "":
                    field_data = None
                task.extra_fields[field]['exec_value'] = field_data
            task.save()
            task.active_conector()
            try:
                task.save()
            except ResourceConflict:
                pass
        elif task.doc_type == "WFItemsLoader":
            task.save()
            task.active_conector()
        elif task.doc_type == "DecisionTask":
            if 'aceptar' in request.POST:
                task.confirmation = True
            else:
                task.confirmation = False
            task.save()
            task.active_conector()

        elif task.doc_type == "FilterWFItems":
            selected_items = request.POST.getlist('selected_items')
            task.wfitems_ids = selected_items
            task.save()
            task.active_conector()
            response_dict['response'] = True
            return HttpResponse(simplejson.dumps(response_dict),\
                                mimetype='application/javascript')
        elif task.doc_type == "MarcImport":
            task.active_conector()

        groups = user.groups
        new_tasks = workflow.get_active_tasks()

        url_redirect = '/'
        for task in new_tasks:
            if task.group_id in groups or user.is_superuser:
                url_redirect = '/couchflow/execute_task/%s' % task._id
                break

        return HttpResponseRedirect(url_redirect)

    if task.doc_type == 'FilterWFItems':
        response_dict['response'] = True
        response_dict['status'] = "Campos mal cargados"
        return HttpResponse(simplejson.dumps(response_dict),
                            mimetype='application/javascript')
    else:
        context = {
            'form': form,
            'task': task,
            'item_errors': item_validation_errors
        }
        return render_to_response('couchflow/save_task_error.html',
                                  context,
                                  context_instance=RequestContext(request))
示例#16
0
def save_new_item(request, task_id, edit_item_id=None):
    # if edit_item_id is provided, edit it

    response_dict = {}
    if request.method == 'POST':
        task = get_task(task_id)
        workflow = WorkFlow.get(task.workflow_id)

        if edit_item_id:
            item = WFItem.get(edit_item_id)
        else:
            item = task.get_item()

        item_validation_errors = item.check_form(request.POST, task)
        for err in item_validation_errors:
            if err[1] == "int":
                err[1] = "Numero"
        if item_validation_errors:
            response_dict = {}
            response_dict['response'] = False
            status = "No se puede crear el item, campos mal cargados"
            response_dict['status'] = status
            response_dict['errors'] = item_validation_errors
            return HttpResponse(simplejson.dumps(response_dict),\
                                mimetype='application/javascript')

        # TODO: set uid by hand
        # Clone the item
        if not edit_item_id:
            item = item.really_clone(save=True)
            item.is_clone = True

        # set no the item the order number to can keep track of an order
        order_nbr = task.order_nbr
        if not order_nbr:
            order_nbr = task.order_nbr = get_nro_pedido()
        item.order_nbr = order_nbr

        images = save_task_item(request, item, task)
        item.save()

        #response_dict['item_name'] = item.name + ": " + get_item_name(item)
        response_dict['item_name'] = get_item_name(item)

        save_images(item, images)

        if not edit_item_id:
            task.wfitems_ids.append(item._id)
            task.save()

        response_dict['response'] = True
        response_dict['status'] = "Bien"
        response_dict['item_id'] = item._id

        return HttpResponse(simplejson.dumps(response_dict),\
                            mimetype='application/javascript')

    response_dict['response'] = False
    response_dict['status'] = "Mal"
    return HttpResponse(simplejson.dumps(response_dict),\
                        mimetype='application/javascript')
示例#17
0
文件: views.py 项目: GaloC/gplib
def save_new_item(request, task_id, edit_item_id=None):
    # if edit_item_id is provided, edit it

    response_dict = {}
    if request.method == 'POST':
        task = get_task(task_id)
        workflow = WorkFlow.get(task.workflow_id)

        if edit_item_id:
            item = WFItem.get(edit_item_id)
        else:
            item = task.get_item()

        item_validation_errors = item.check_form(request.POST, task)
        for err in item_validation_errors:
            if err[1] == "int":
                err[1] = "Numero"
        if item_validation_errors:
            response_dict = {}
            response_dict['response'] = False
            status = "No se puede crear el item, campos mal cargados"
            response_dict['status'] = status
            response_dict['errors'] = item_validation_errors
            return HttpResponse(simplejson.dumps(response_dict),\
                                mimetype='application/javascript')

        # TODO: set uid by hand
        # Clone the item
        if not edit_item_id:
            item = item.really_clone(save=True)
            item.is_clone = True

        # set no the item the order number to can keep track of an order
        order_nbr = task.order_nbr
        if not order_nbr:
            order_nbr = task.order_nbr = get_nro_pedido()
        item.order_nbr = order_nbr

        images = save_task_item(request, item, task)
        item.save()

        #response_dict['item_name'] = item.name + ": " + get_item_name(item)
        response_dict['item_name'] = get_item_name(item)

        save_images(item, images)

        if not edit_item_id:
            task.wfitems_ids.append(item._id)
            task.save()

        response_dict['response'] = True
        response_dict['status'] = "Bien"
        response_dict['item_id'] = item._id

        return HttpResponse(simplejson.dumps(response_dict),\
                            mimetype='application/javascript')

    response_dict['response'] = False
    response_dict['status'] = "Mal"
    return HttpResponse(simplejson.dumps(response_dict),\
                        mimetype='application/javascript')
示例#18
0
文件: views.py 项目: GaloC/gplib
def save_task(request, task_type, task_id):
    try:
        if task_type == "DecisionTask":
            task = DecisionTask.get(task_id)
            form = DecisionTaskForm(request.POST)
        elif task_type == "DynamicDataTask":
            task = DynamicDataTask.get(task_id)
            form = ExecDynamicForm(request.POST)
        elif task_type == "WFItemsLoader":
            task = WFItemsLoader.get(task_id)
            form = ExecWFItemsLoader(request.POST)
        elif task_type == "FilterWFItems":
            task = FilterWFItems.get(task_id)
            form = ExecFilterWFItemsForm(request.POST)
        elif task_type == "MarcImport":
            task = MarcImport.get(task_id)
            form = ExecMarcImportForm(request.POST)
    except ResourceNotFound:
        return  HttpResponseRedirect('/')

    workflow = WorkFlow.get(task.workflow_id)

    if 'cancelar' in request.POST and \
           task.doc_type != 'FilterWFItems':
        if task.node_type == 'start':
            workflow.remove_relations()
            workflow.delete()
        return HttpResponseRedirect('/')

    elif 'cancelar' in request.POST and \
             task.doc_type == 'FilterWFItems':
        response_dict = {}
        response_dict['response'] = False
        response_dict['url'] = '/'
        return HttpResponse(simplejson.dumps(response_dict),\
                            mimetype='application/javascript')

    item = task.get_item()
    response_dict = {}

    item_validation_errors = []
    if task_type not in ('WFItemsLoader',):
        item_validation_errors = item.check_form(request.POST, task)

    if form.is_valid() and not item_validation_errors:
        user = request.user

        task.saved_by = user._id

        if item.is_clone:
            item.comments = form.cleaned_data['comments']
            item.save()

        if task.doc_type == "DecisionTask" or \
                task.doc_type == "DynamicDataTask":
            if item.is_clone:

                images = save_task_item(request, item, task)
                item.save()

                save_images(item, images)

                more_items = []
                if len(task.wfitems_ids) > 1:
                    more_items = [WFItem.get(x) for x in task.wfitems_ids]
                elif task.group_by_urn:
                    more_items = WFItem.view("couchflow/by_urn",
                        include_docs=True)[item.urn].all()

                if more_items:
                    for new_item in more_items:
                        if new_item._id != item._id:
                            # TODO: don't replace all the properties
                            new_item.fields_properties = item.fields_properties

                            new_item.comments = item.comments
                            try:
                                new_item.save()
                            except ResourceConflict:
                                pass

        if task.doc_type == "DynamicDataTask":
            for field in task.extra_fields:
                field_data = request.POST.getlist(field)
                if field_data == "":
                    field_data = None
                task.extra_fields[field]['exec_value'] = field_data
            task.save()
            task.active_conector()
            try:
                task.save()
            except ResourceConflict:
                pass
        elif task.doc_type == "WFItemsLoader":
            task.save()
            task.active_conector()
        elif task.doc_type == "DecisionTask":
            if  'aceptar' in request.POST:
                task.confirmation = True
            else:
                task.confirmation = False
            task.save()
            task.active_conector()

        elif task.doc_type == "FilterWFItems":
            selected_items = request.POST.getlist('selected_items')
            task.wfitems_ids = selected_items
            task.save()
            task.active_conector()
            response_dict['response'] = True
            return HttpResponse(simplejson.dumps(response_dict),\
                                mimetype='application/javascript')
        elif task.doc_type == "MarcImport":
            task.active_conector()

        groups = user.groups
        new_tasks = workflow.get_active_tasks()

        url_redirect = '/'
        for task in new_tasks:
            if task.group_id in groups or user.is_superuser:
                url_redirect = '/couchflow/execute_task/%s' % task._id
                break

        return  HttpResponseRedirect(url_redirect)

    if task.doc_type == 'FilterWFItems':
        response_dict['response'] = True
        response_dict['status'] = "Campos mal cargados"
        return HttpResponse(simplejson.dumps(response_dict),
                            mimetype='application/javascript')
    else:
        context = {
            'form': form,
            'task': task,
            'item_errors': item_validation_errors
        }
        return render_to_response('couchflow/save_task_error.html',
            context, context_instance=RequestContext(request))