def test_get_next_cnum(self):
            from invenio.sequtils_cnum import CnumSeq

            cnum_seq = CnumSeq()
            res = cnum_seq.next_value('xx')
            self.assertEqual(res, 'C50-09-14')
            res = cnum_seq.next_value('xx')
            self.assertEqual(res, 'C50-09-14.1')

            # Clean DB entries
            run_sql(""" DELETE FROM seqSTORE
                        WHERE seq_name="cnum"
                        AND seq_value IN ("C50-09-14", "C50-09-14.1") """)
        def test_get_next_cnum(self):
            from invenio.sequtils_cnum import CnumSeq

            cnum_seq = CnumSeq()
            res = cnum_seq.next_value('xx')
            self.assertEqual(res, 'C50-09-14')
            res = cnum_seq.next_value('xx')
            self.assertEqual(res, 'C50-09-14.1')

            # Clean DB entries
            run_sql(""" DELETE FROM seqSTORE
                        WHERE seq_name="cnum"
                        AND seq_value IN ("C50-09-14", "C50-09-14.1") """)
Beispiel #3
0
def add_record_cnum(recid, uid):
    """
    Check if the record has already a cnum. If not generate a new one
    and return the result

    @param recid: recid of the record under check. Used to retrieve cache file
    @type recid: int

    @param uid: id of the user. Used to retrieve cache file
    @type uid: int

    @return: None if cnum already present, new cnum otherwise
    @rtype: None or string
    """
    # Import placed here to avoid circular dependency
    from invenio.sequtils_cnum import CnumSeq, ConferenceNoStartDateError

    record_revision, record, pending_changes, deactivated_hp_changes, \
    undo_list, redo_list = get_cache_file_contents(recid, uid)[1:]

    record_strip_empty_volatile_subfields(record)

    # Check if record already has a cnum
    tag_111__g_content = record_get_field_value(record, "111", " ", " ", "g")
    if tag_111__g_content:
        return
    else:
        cnum_seq = CnumSeq()
        try:
            new_cnum = cnum_seq.next_value(
                xml_record=wash_for_xml(print_rec(record)))
        except ConferenceNoStartDateError:
            return None
        field_add_subfield(record['111'][0], 'g', new_cnum)
        update_cache_file_contents(recid, uid, record_revision,
                                   record, \
                                   pending_changes, \
                                   deactivated_hp_changes, \
                                   undo_list, redo_list)
        return new_cnum
Beispiel #4
0
def add_record_cnum(recid, uid):
    """
    Check if the record has already a cnum. If not generate a new one
    and return the result

    @param recid: recid of the record under check. Used to retrieve cache file
    @type recid: int

    @param uid: id of the user. Used to retrieve cache file
    @type uid: int

    @return: None if cnum already present, new cnum otherwise
    @rtype: None or string
    """
    # Import placed here to avoid circular dependency
    from invenio.sequtils_cnum import CnumSeq, ConferenceNoStartDateError

    record_revision, record, pending_changes, deactivated_hp_changes, \
    undo_list, redo_list = get_cache_contents(recid, uid)[1:]

    record_strip_empty_volatile_subfields(record)

    # Check if record already has a cnum
    tag_111__g_content = record_get_field_value(record, "111", " ", " ", "g")
    if tag_111__g_content:
        return
    else:
        cnum_seq = CnumSeq()
        try:
            new_cnum = cnum_seq.next_value(xml_record=wash_for_xml(print_rec(record)))
        except ConferenceNoStartDateError:
            return None
        field_add_subfield(record['111'][0], 'g', new_cnum)
        update_cache_contents(recid, uid, record_revision,
                                   record,
                                   pending_changes,
                                   deactivated_hp_changes,
                                   undo_list, redo_list)
        return new_cnum
def CONFSUBMIT_CNum_Generation(parameters, curdir, form, user_info=None):
    """
    This function creates a reference for the submitted
    document and saves it in the specified 'edsrn' file.

    After generating the reference, also sets the global variable 'rn'
    containing this reference.

    Parameters:

      * cnum: name of the file in which the cnum is saved
      * sdat: name of the file in which the start-date is saved
    """
    fp = open("%s/%s" % (curdir,parameters['sdat']),"r")
    start_date = fp.read()
    fp.close()

    cnum_seq = CnumSeq()
    new_cnum = cnum_seq.next_value(start_date=start_date.strip())
    # The program must automatically generate the report number
    # The file cnumfile is created in the submission directory, and it stores the c-number
    fp = open("%s/%s" % (curdir, parameters['cnum']), "w")
    fp.write(new_cnum)
    fp.close()