Beispiel #1
0
def data_package_id(filename=None):
    form = DataPackageIDForm()
    eml_node = load_eml(filename=filename)

    # Process POST
    # if request.method == 'POST' and form.validate_on_submit():
    if request.method == 'POST':
        save = False
        if is_dirty_form(form):
            save = True

        if save:
            data_package_id = form.data_package_id.data
            create_data_package_id(data_package_id, filename)
            set_active_packageid(data_package_id)
            form.md5.data = form_md5(form)

        new_page = PAGE_TITLE
        this_page = PAGE_DATA_PACKAGE_ID
        new_page = handle_hidden_buttons(new_page, this_page)

        return redirect(url_for(new_page, filename=filename))

    # Process GET
    data_package_id = eml_node.attribute_value('packageId')
    form.data_package_id.data = data_package_id if data_package_id else ''
    form.md5.data = form_md5(form)

    set_current_page('data_package_id')
    help = get_helps(['data_package_id'])
    return render_template('data_package_id.html',
                           form=form,
                           help=help,
                           title='Data Package ID')
Beispiel #2
0
def geographic_coverage_select(filename=None):
    form = GeographicCoverageSelectForm(filename=filename)

    # Process POST
    if request.method == 'POST':
        form_value = request.form
        form_dict = form_value.to_dict(flat=False)
        url = select_post(filename, form, form_dict, 'POST',
                          PAGE_GEOGRAPHIC_COVERAGE_SELECT,
                          PAGE_INTELLECTUAL_RIGHTS,
                          PAGE_TEMPORAL_COVERAGE_SELECT,
                          PAGE_GEOGRAPHIC_COVERAGE)
        return redirect(url)

    # Process GET
    gc_list = []
    title = "Geographic Coverage"

    eml_node = load_eml(filename=filename)
    if eml_node:
        dataset_node = eml_node.find_child(names.DATASET)
        if dataset_node:
            gc_list = list_geographic_coverages(dataset_node)

    set_current_page('geographic_coverage')
    help = get_helps(['geographic_coverages', 'geographic_coverages_csv_file'])
    return render_template('geographic_coverage_select.html',
                           title=title,
                           gc_list=gc_list,
                           form=form,
                           help=help)
Beispiel #3
0
def publication_info(filename=None):
    form = PublicationInfoForm()

    # Process POST
    # if request.method == 'POST' and form.validate_on_submit():
    if request.method == 'POST':
        if 'Next' in request.form:
            new_page = PAGE_METHOD_STEP_SELECT
        elif BTN_HIDDEN_CHECK in request.form:
            new_page = PAGE_CHECK
        elif BTN_HIDDEN_SAVE in request.form:
            new_page = PAGE_PUBLICATION_INFO
        elif BTN_HIDDEN_DOWNLOAD in request.form:
            new_page = PAGE_DOWNLOAD
        elif BTN_HIDDEN_NEW in request.form:
            new_page = PAGE_CREATE
        elif BTN_HIDDEN_OPEN in request.form:
            new_page = PAGE_OPEN
        elif BTN_HIDDEN_CLOSE in request.form:
            new_page = PAGE_CLOSE
        else:
            new_page = PAGE_PUBLISHER

        save = False
        if is_dirty_form(form):
            save = True

        if save:
            pubplace = form.pubplace.data
            pubdate = form.pubdate.data
            create_pubinfo(pubplace=pubplace,
                           pubdate=pubdate,
                           filename=filename)

        return redirect(url_for(new_page, filename=filename))

    # Process GET
    eml_node = load_eml(filename=filename)
    pubplace_node = eml_node.find_single_node_by_path(
        [names.DATASET, names.PUBPLACE])
    if pubplace_node:
        form.pubplace.data = pubplace_node.content
    pubdate_node = eml_node.find_single_node_by_path(
        [names.DATASET, names.PUBDATE])
    if pubdate_node:
        form.pubdate.data = pubdate_node.content
    form.md5.data = form_md5(form)
    set_current_page('publication_info')
    help = get_helps(['pubplace', 'pubdate'])
    return render_template('publication_info.html',
                           help=help,
                           form=form,
                           title='Publication Info')
Beispiel #4
0
def title(filename=None):
    form = TitleForm()

    # Process POST
    # if request.method == 'POST' and form.validate_on_submit():
    if request.method == 'POST':
        new_page = PAGE_DATA_TABLE_SELECT
        save = False
        if is_dirty_form(form):
            save = True

        if save:
            create_title(title=form.title.data, filename=filename)
            form.md5.data = form_md5(form)

        if 'Next' in request.form:
            new_page = PAGE_DATA_TABLE_SELECT
        elif BTN_HIDDEN_CHECK in request.form:
            new_page = PAGE_CHECK
        elif BTN_HIDDEN_SAVE in request.form:
            new_page = PAGE_TITLE
        elif BTN_HIDDEN_DOWNLOAD in request.form:
            new_page = PAGE_DOWNLOAD
        elif BTN_HIDDEN_NEW in request.form:
            new_page = PAGE_CREATE
        elif BTN_HIDDEN_OPEN in request.form:
            new_page = PAGE_OPEN
        elif BTN_HIDDEN_CLOSE in request.form:
            new_page = PAGE_CLOSE

        return redirect(url_for(new_page, filename=filename))

    # Process GET
    eml_node = load_eml(filename=filename)
    dataset_node = eml_node.find_child(child_name=names.DATASET)
    title_node = dataset_node.find_child(names.TITLE)
    if title_node:
        form.title.data = title_node.content
    form.md5.data = form_md5(form)

    set_current_page('title')
    help = get_helps(['title', 'nav', 'welcome'])
    first_usage = is_first_usage()
    return render_template('title.html',
                           title='Title',
                           form=form,
                           help=help,
                           is_first_usage=first_usage)
Beispiel #5
0
def data_package_id(filename=None):
    form = DataPackageIDForm()
    eml_node = load_eml(filename=filename)

    # Process POST
    # if request.method == 'POST' and form.validate_on_submit():
    if request.method == 'POST':
        new_page = PAGE_TITLE
        save = False
        if is_dirty_form(form):
            save = True

        if save:
            data_package_id = form.data_package_id.data
            create_data_package_id(data_package_id, filename)
            set_active_packageid(data_package_id)
            form.md5.data = form_md5(form)

        if 'Next' in request.form:
            new_page = PAGE_CHECK
        elif BTN_HIDDEN_CHECK in request.form:
            new_page = PAGE_CHECK
        elif BTN_HIDDEN_SAVE in request.form:
            new_page = PAGE_DATA_PACKAGE_ID
        elif BTN_HIDDEN_DOWNLOAD in request.form:
            new_page = PAGE_DOWNLOAD
        elif BTN_HIDDEN_NEW in request.form:
            new_page = PAGE_CREATE
        elif BTN_HIDDEN_OPEN in request.form:
            new_page = PAGE_OPEN
        elif BTN_HIDDEN_CLOSE in request.form:
            new_page = PAGE_CLOSE

        return redirect(url_for(new_page, filename=filename))

    # Process GET
    data_package_id = eml_node.attribute_value('packageId')
    form.data_package_id.data = data_package_id if data_package_id else ''
    form.md5.data = form_md5(form)

    set_current_page('data_package_id')
    help = get_helps(['data_package_id'])
    return render_template('data_package_id.html',
                           form=form,
                           help=help,
                           title='Data Package ID')
Beispiel #6
0
def publication_info(filename=None):
    form = PublicationInfoForm()

    # Process POST
    # if request.method == 'POST' and form.validate_on_submit():
    if request.method == 'POST':

        new_page = PAGE_METHOD_STEP_SELECT
        this_page = PAGE_PUBLICATION_INFO
        new_page = handle_hidden_buttons(new_page, this_page)

        save = False
        if is_dirty_form(form):
            save = True

        if save:
            pubplace = form.pubplace.data
            pubdate = form.pubdate.data
            create_pubinfo(pubplace=pubplace,
                           pubdate=pubdate,
                           filename=filename)

        return redirect(url_for(new_page, filename=filename))

    # Process GET
    eml_node = load_eml(filename=filename)
    pubplace_node = eml_node.find_single_node_by_path(
        [names.DATASET, names.PUBPLACE])
    if pubplace_node:
        form.pubplace.data = pubplace_node.content
    pubdate_node = eml_node.find_single_node_by_path(
        [names.DATASET, names.PUBDATE])
    if pubdate_node:
        form.pubdate.data = pubdate_node.content
    form.md5.data = form_md5(form)
    set_current_page('publication_info')
    help = get_helps(['pubplace', 'pubdate'])
    return render_template('publication_info.html',
                           help=help,
                           form=form,
                           title='Publication Info')
Beispiel #7
0
def title(filename=None):
    log_info(f'Title')

    form = TitleForm()

    # Process POST
    if request.method == 'POST' and form.validate_on_submit():
        save = False
        if is_dirty_form(form):
            save = True

        if save:
            create_title(title=form.title.data, filename=filename)
            form.md5.data = form_md5(form)

        new_page = PAGE_DATA_TABLE_SELECT
        this_page = PAGE_TITLE
        new_page = handle_hidden_buttons(new_page, this_page)

        return redirect(url_for(new_page, filename=filename))

    # Process GET
    eml_node = load_eml(filename=filename)
    dataset_node = eml_node.find_child(child_name=names.DATASET)
    title_node = dataset_node.find_child(names.TITLE)
    if title_node:
        form.title.data = title_node.content
    form.md5.data = form_md5(form)

    set_current_page('title')
    help = get_helps(['title', 'nav', 'welcome'])
    first_usage = is_first_usage()
    return render_template('title.html',
                           title='Title',
                           form=form,
                           help=help,
                           is_first_usage=first_usage)
Beispiel #8
0
def taxonomic_coverage(filename=None, node_id=None, taxon=None):
    form = TaxonomicCoverageForm(filename=filename)

    # Process POST
    if request.method == 'POST' and BTN_CANCEL in request.form:
        url = url_for(PAGE_TAXONOMIC_COVERAGE_SELECT, filename=filename)
        return redirect(url)

    if request.method == 'POST' and form.validate_on_submit():
        save = False
        if is_dirty_form(form):
            save = True
        # flash(f'save: {save}')

        form_value = request.form
        have_links = False

        if 'Fill' in form_value:
            source = form.taxonomic_authority.data
            if source == 'ITIS':
                source_type = TaxonomySourceEnum.ITIS
            elif source == 'NCBI':
                source_type = TaxonomySourceEnum.NCBI
            elif source == "WORMS":
                source_type = TaxonomySourceEnum.WORMS
            try:
                source_name = ''
                for choice in form.taxonomic_authority.choices:
                    if choice[0] == source:
                        source_name = choice[1]
                        break
                hierarchy = fill_taxonomic_coverage(form.taxon_value.data,
                                                    source_type, source_name)
                if hierarchy:
                    # set the taxon rank dropdown appropriately
                    rank = hierarchy[0][0].capitalize()
                    if (rank, rank) in form.taxon_rank.choices:
                        form.taxon_rank.data = rank
                    # see if we should display a Links column
                    for taxon in hierarchy:
                        if taxon[4]:
                            have_links = True
                            break
            except ValueError as e:
                flash(str(e))
                hierarchy = [(form.taxon_rank.data, form.taxon_value.data, '',
                              '')]
            form.hierarchy.data = hierarchy
            form.hidden_taxon_rank.data = form.taxon_rank.data
            form.hidden_taxon_value.data = form.taxon_value.data
            form.hidden_taxonomic_authority.data = form.taxonomic_authority.data
            help = get_helps(['taxonomic_coverage_fill_hierarchy'])

            return render_template(
                'taxonomic_coverage.html',
                title='Taxonomic Coverage',
                form=form,
                hierarchy=hierarchy,
                taxon_rank=form.taxon_rank.data,
                taxon_value=form.taxon_value.data,
                taxonomic_authority=form.taxonomic_authority.data,
                help=help,
                have_links=have_links)

        form_dict = form_value.to_dict(flat=False)
        new_page = PAGE_TAXONOMIC_COVERAGE_SELECT
        if form_dict:
            for key in form_dict:
                val = form_dict[key][0]  # value is the first list element

                if val == BTN_HIDDEN_NEW:
                    new_page = PAGE_CREATE
                    break
                elif val == BTN_HIDDEN_OPEN:
                    new_page = PAGE_OPEN
                    break
                elif val == BTN_HIDDEN_CLOSE:
                    new_page = PAGE_CLOSE
                    break

        if save:
            if not form.taxon_value.data and not form.taxon_rank.data:
                return redirect(url_for(new_page, filename=filename))

            submitted_hierarchy = form_value.get('hierarchy')
            if isinstance(form_value.get('hierarchy'),
                          str) and form_value.get('hierarchy'):
                # convert hierarchy string to list
                submitted_hierarchy = ast.literal_eval(
                    form_value.get('hierarchy'))
                form.hierarchy.data = submitted_hierarchy

            # if we're saving after doing 'Fill Hierarchy', fill in the values we've been passed
            if form_value.get('hidden_taxon_rank'):
                form.taxon_rank.data = form_value.get('hidden_taxon_rank')
                form.taxon_value.data = form_value.get('hidden_taxon_value')
                form.taxonomic_authority.data = form_value.get(
                    'hidden_taxonomic_authority')
            elif not submitted_hierarchy:
                # we don't have a hierarchy, so construct a fake hierarchy to be used by create_taxonomic_coverage()
                form.hierarchy.data = [(form_value.get('taxon_rank'),
                                        form_value.get('taxon_value'), '', '',
                                        '', '')]

            if not form_value.get('taxon_rank'):
                flash('Taxon Rank is required.')
                return redirect(
                    url_for(PAGE_TAXONOMIC_COVERAGE,
                            filename=filename,
                            node_id=node_id,
                            taxon=form.taxon_value.data))

            eml_node = load_eml(filename=filename)

            dataset_node = eml_node.find_child(names.DATASET)
            if not dataset_node:
                dataset_node = Node(names.DATASET)

            coverage_node = dataset_node.find_child(names.COVERAGE)
            if not coverage_node:
                coverage_node = Node(names.COVERAGE, parent=dataset_node)
                add_child(dataset_node, coverage_node)

            txc_node = Node(names.TAXONOMICCOVERAGE, parent=coverage_node)

            create_taxonomic_coverage(txc_node,
                                      form.general_taxonomic_coverage.data,
                                      form.hierarchy.data,
                                      form.taxonomic_authority.data)

            if node_id and len(node_id) != 1:
                old_txc_node = Node.get_node_instance(node_id)
                if old_txc_node:
                    coverage_parent_node = old_txc_node.parent
                    coverage_parent_node.replace_child(old_txc_node, txc_node)
                else:
                    msg = f"No node found in the node store with node id {node_id}"
                    raise Exception(msg)
            else:
                add_child(coverage_node, txc_node)

            save_both_formats(filename=filename, eml_node=eml_node)

        return redirect(url_for(new_page, filename=filename))

    # Process GET
    have_links = False
    if node_id == '1':
        form.init_md5()
        if taxon:
            form.taxon_value.data = taxon
    else:
        eml_node = load_eml(filename=filename)
        dataset_node = eml_node.find_child(names.DATASET)
        if dataset_node:
            coverage_node = dataset_node.find_child(names.COVERAGE)
            if coverage_node:
                txc_nodes = coverage_node.find_all_children(
                    names.TAXONOMICCOVERAGE)
                if txc_nodes:
                    for txc_node in txc_nodes:
                        if node_id == txc_node.id:
                            have_links = populate_taxonomic_coverage_form(
                                form, txc_node)

    help = get_helps(['taxonomic_coverage_fill_hierarchy'])

    set_current_page('taxonomic_coverage')
    return render_template('taxonomic_coverage.html',
                           title='Taxonomic Coverage',
                           form=form,
                           hierarchy=form.hierarchy.data,
                           have_links=have_links,
                           help=help)
Beispiel #9
0
def geographic_coverage(filename=None, node_id=None):
    form = GeographicCoverageForm(filename=filename)

    # Process POST
    if request.method == 'POST' and BTN_CANCEL in request.form:
        url = url_for(PAGE_GEOGRAPHIC_COVERAGE_SELECT, filename=filename)
        return redirect(url)

    if request.method == 'POST' and form.validate_on_submit():
        submit_type = None
        if is_dirty_form(form):
            submit_type = 'Save Changes'

        form_value = request.form
        form_dict = form_value.to_dict(flat=False)
        new_page = PAGE_GEOGRAPHIC_COVERAGE_SELECT
        this_page = PAGE_GEOGRAPHIC_COVERAGE
        if form_dict:
            for key in form_dict:
                val = form_dict[key][0]  # value is the first list element
                new_page = check_val_for_hidden_buttons(val, new_page, this_page)

        url = url_for(new_page, filename=filename)

        if submit_type == 'Save Changes':
            eml_node = load_eml(filename=filename)

            dataset_node = eml_node.find_child(names.DATASET)
            if not dataset_node:
                dataset_node = Node(names.DATASET)

            coverage_node = dataset_node.find_child(names.COVERAGE)
            if not coverage_node:
                coverage_node = Node(names.COVERAGE, parent=dataset_node)
                add_child(dataset_node, coverage_node)

            geographic_description = form.geographic_description.data
            wbc = form.wbc.data if form.wbc.data is not None else ''
            ebc = form.ebc.data if form.ebc.data is not None else ''
            nbc = form.nbc.data if form.nbc.data is not None else ''
            sbc = form.sbc.data if form.sbc.data is not None else ''
            amin = form.amin.data if form.amin.data is not None else ''
            amax = form.amax.data if form.amax.data is not None else ''
            aunits = form.aunits.data if form.aunits.data is not None else ''

            gc_node = Node(names.GEOGRAPHICCOVERAGE, parent=coverage_node)

            create_geographic_coverage(
                gc_node,
                geographic_description,
                wbc, ebc, nbc, sbc, amin, amax, aunits)

            if node_id and len(node_id) != 1:
                old_gc_node = Node.get_node_instance(node_id)
                if old_gc_node:
                    coverage_parent_node = old_gc_node.parent
                    coverage_parent_node.replace_child(old_gc_node, gc_node)
                else:
                    msg = f"No node found in the node store with node id {node_id}"
                    raise Exception(msg)
            else:
                add_child(coverage_node, gc_node)

            if nbc and sbc and nbc < sbc:
                flash('North should be greater than or equal to South', 'error')
                url = (url_for(PAGE_GEOGRAPHIC_COVERAGE, filename=filename, node_id=gc_node.id))

            if ebc and wbc and ebc < wbc:
                flash('East should be greater than or equal to West', 'error')
                url = (url_for(PAGE_GEOGRAPHIC_COVERAGE, filename=filename, node_id=gc_node.id))

            save_both_formats(filename=filename, eml_node=eml_node)

        return redirect(url)

    # Process GET
    if node_id == '1':
        form.init_md5()
    else:
        eml_node = load_eml(filename=filename)
        dataset_node = eml_node.find_child(names.DATASET)
        if dataset_node:
            coverage_node = dataset_node.find_child(names.COVERAGE)
            if coverage_node:
                gc_nodes = coverage_node.find_all_children(names.GEOGRAPHICCOVERAGE)
                if gc_nodes:
                    for gc_node in gc_nodes:
                        if node_id == gc_node.id:
                            populate_geographic_coverage_form(form, gc_node)

    set_current_page('geographic_coverage')
    help = get_helps(['geographic_coverages', 'geographic_description', 'bounding_coordinates', 'bounding_altitudes'])
    return render_template('geographic_coverage.html', title='Geographic Coverage', form=form, help=help)
Beispiel #10
0
def responsible_party(filename=None, node_id=None, method=None,
                      node_name=None, back_page=None, title=None,
                      next_page=None, save_and_continue=False, help=None,
                      project_node_id=None):

    if BTN_CANCEL in request.form:
        if not project_node_id:
            url = url_for(back_page, filename=filename)
        else:
            url = url_for(back_page, filename=filename, node_id=project_node_id)
        return redirect(url)

    form = ResponsiblePartyForm(filename=filename)
    eml_node = load_eml(filename=filename)
    dataset_node = eml_node.find_child(names.DATASET)
    if not dataset_node:
        dataset_node = Node(names.DATASET, parent=eml_node)
        add_child(eml_node, dataset_node)
    parent_node = dataset_node
    role = False
    new_page = select_new_page(back_page, next_page)
    # new_page = back_page

    form_value = request.form
    form_dict = form_value.to_dict(flat=False)
    url = select_post(filename, form, form_dict,
                      'POST', PAGE_PUBLISHER,
                      PAGE_MAINTENANCE, PAGE_PUBLICATION_INFO,
                      PAGE_PUBLISHER, project_node_id=project_node_id)

    # If this is an associatedParty or a project personnel element,
    # set role to True so it will appear as a form field.
    if node_name == names.ASSOCIATEDPARTY or node_name == names.PERSONNEL:
        role = True

    # If this is a project personnel party, place it under the
    # project node, not under the dataset node
    if node_name == names.PERSONNEL:
        if not project_node_id:
            project_node = dataset_node.find_child(names.PROJECT)
            if not project_node:
                project_node = Node(names.PROJECT, parent=dataset_node)
                add_child(dataset_node, project_node)
            parent_node = project_node
        else:
            parent_node = Node.get_node_instance(project_node_id)

    # Process POST
    save = False
    if is_dirty_form(form):
        save = True

    if form.validate_on_submit():
        if save:
            salutation = form.salutation.data
            gn = form.gn.data
            mn = form.mn.data
            sn = form.sn.data
            user_id = form.user_id.data
            organization = form.organization.data
            position_name = form.position_name.data
            address_1 = form.address_1.data
            address_2 = form.address_2.data
            city = form.city.data
            state = form.state.data
            postal_code = form.postal_code.data
            country = form.country.data
            phone = form.phone.data
            fax = form.fax.data
            email = form.email.data
            online_url = form.online_url.data
            role = form.role.data

            rp_node = Node(node_name, parent=parent_node)

            create_responsible_party(
                rp_node,
                filename,
                salutation,
                gn,
                mn,
                sn,
                user_id,
                organization,
                position_name,
                address_1,
                address_2,
                city,
                state,
                postal_code,
                country,
                phone,
                fax,
                email,
                online_url,
                role)

            if node_id and len(node_id) != 1:
                old_rp_node = Node.get_node_instance(node_id)
                if old_rp_node:
                    old_rp_parent_node = old_rp_node.parent
                    old_rp_parent_node.replace_child(old_rp_node, rp_node)
                else:
                    msg = f"No node found in the node store with node id {node_id}"
                    raise Exception(msg)
            else:
                add_child(parent_node, rp_node)

            save_both_formats(filename=filename, eml_node=eml_node)
            # flash(f"Changes to the '{node_name}' element have been saved.")

            # There is at most only one publisher element, so we don't have a
            # list of publishers to navigate back to. Stay on this page after
            # saving changes.
            # FIXME
            if node_name == names.PUBLISHER:
                new_page = PAGE_PUBLICATION_INFO

        if node_name != names.PUBLISHER:
            return redirect(url_for(new_page, filename=filename, node_id=project_node_id))
        else:
            return redirect(url)

    # Process GET
    if node_id == '1':
        form.init_md5()
    else:
        if parent_node:
            rp_nodes = parent_node.find_all_children(child_name=node_name)
            if rp_nodes:
                for rp_node in rp_nodes:
                    if node_id == rp_node.id:
                        populate_responsible_party_form(form, rp_node)

    if project_node_id:
        title = 'Related ' + title
    help = get_helps([node_name])
    return render_template('responsible_party.html', title=title, node_name=node_name,
                           form=form, role=role, next_page=next_page, save_and_continue=save_and_continue, help=help)