Ejemplo n.º 1
0
def update_row(request, instance, import_type, row_id):
    """Update an importeventrow.

    Take the import_type and row_id from the URL and use it
    to retrieve the necessary row object. Then, iterate over
    the kvs in the json request body and set them on the row.
    """
    Clz = get_import_row_model(import_type)
    row = Clz.objects.get(pk=row_id)
    ie = row.import_event

    basedata = row.datadict

    for k, v in request.POST.iteritems():
        if k in basedata:
            basedata[k] = v

    # save the row and then perform validation, because
    # validation in this case is not the process of determining
    # if save is allowed, but rather of determining the error status
    # of the row and its fields so it can be presented correctly to
    # the user for further action.
    row.datadict = basedata
    row.save()
    row.validate_row()

    panel_name = request.GET.get('panel', 'verified')
    page_number = int(request.GET.get('page', '1'))
    context = _get_status_panels(ie, instance, panel_name, page_number)
    context['active_panel_name'] = 'error'
    return context
Ejemplo n.º 2
0
def update_row(request, instance, import_type, row_id):
    """Update an importeventrow.

    Take the import_type and row_id from the URL and use it
    to retrieve the necessary row object. Then, iterate over
    the kvs in the json request body and set them on the row.
    """
    Clz = get_import_row_model(import_type)
    row = Clz.objects.get(pk=row_id)
    ie = row.import_event

    basedata = row.datadict

    for k, v in request.POST.iteritems():
        if k in basedata:
            basedata[k] = v

    # save the row and then perform validation, because
    # validation in this case is not the process of determining
    # if save is allowed, but rather of determining the error status
    # of the row and its fields so it can be presented correctly to
    # the user for further action.
    row.datadict = basedata
    row.save()
    row.validate_row()

    panel_name = request.GET.get('panel', 'verified')
    page_number = int(request.GET.get('page', '1'))
    context = _get_status_panels(ie, instance, panel_name, page_number)
    context['active_panel_name'] = 'error'
    return context
Ejemplo n.º 3
0
def update_row(request, instance, import_type, row_id):
    """Update an importeventrow.

    Take the import_type and row_id from the URL and use it
    to retrieve the necessary row object. Then, iterate over
    the kvs in the json request body and set them on the row.
    """
    Clz = get_import_row_model(import_type)
    row = Clz.objects.get(pk=row_id)
    ie = row.import_event

    basedata = row.datadict

    # Minor workaround for updating species columns in tree imports
    # The client sends up a species_id field, which does not match any of the
    # columns in the ImportRow. If it is present, we look up the species in the
    # DB and fill in the appropriate species fields in the ImportRow
    if 'species_id' in request.POST:
        # this round tripped from the server, so it should always have a match.
        species = Species.objects.get(pk=request.POST['species_id'])
        basedata.update({
            fields.trees.GENUS: species.genus,
            fields.trees.SPECIES: species.species,
            fields.trees.CULTIVAR: species.cultivar,
            fields.trees.OTHER_PART_OF_NAME: species.other_part_of_name,
            fields.trees.COMMON_NAME: species.common_name
        })

    for k, v in request.POST.iteritems():
        if k in basedata:
            basedata[k] = v

    # save the row and then perform validation, because
    # validation in this case is not the process of determining
    # if save is allowed, but rather of determining the error status
    # of the row and its fields so it can be presented correctly to
    # the user for further action.
    row.datadict = basedata
    row.save()
    row.validate_row()

    panel_name = request.GET.get('panel', 'verified')
    page_number = int(request.GET.get('page', '1'))
    context = _get_status_panels(ie, instance, panel_name, page_number)
    context['active_panel_name'] = 'error'
    return context
Ejemplo n.º 4
0
def update_row(request, instance, import_type, row_id):
    """Update an importeventrow.

    Take the import_type and row_id from the URL and use it
    to retrieve the necessary row object. Then, iterate over
    the kvs in the json request body and set them on the row.
    """
    Clz = get_import_row_model(import_type)
    row = Clz.objects.get(pk=row_id)
    ie = row.import_event

    basedata = row.datadict

    # Minor workaround for updating species columns in tree imports
    # The client sends up a species_id field, which does not match any of the
    # columns in the ImportRow. If it is present, we look up the species in the
    # DB and fill in the appropriate species fields in the ImportRow
    if 'species_id' in request.POST:
        # this round tripped from the server, so it should always have a match.
        species = Species.objects.get(pk=request.POST['species_id'])
        basedata.update({
            fields.trees.GENUS: species.genus,
            fields.trees.SPECIES: species.species,
            fields.trees.CULTIVAR: species.cultivar,
            fields.trees.OTHER_PART_OF_NAME: species.other_part_of_name,
            fields.trees.COMMON_NAME: species.common_name
        })

    for k, v in request.POST.iteritems():
        if k in basedata:
            basedata[k] = v

    # save the row and then perform validation, because
    # validation in this case is not the process of determining
    # if save is allowed, but rather of determining the error status
    # of the row and its fields so it can be presented correctly to
    # the user for further action.
    row.datadict = basedata
    row.save()
    row.validate_row()

    panel_name = request.GET.get('panel', 'verified')
    page_number = int(request.GET.get('page', '1'))
    context = _get_status_panels(ie, instance, panel_name, page_number)
    context['active_panel_name'] = 'error'
    return context