def test_get_next_cnum(self): from invenio.modules.sequencegenerator.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 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.modules.sequencegenerator.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