<commit_before>## $Id$
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

__revision__ = "$Id$"

import cPickle
import marshal
import os
import sre
import time

from invenio.bibedit_config import CFG_BIBEDIT_TMPFILENAMEPREFIX
from invenio.bibedit_dblayer import marc_to_split_tag
from invenio.bibrecord import record_xml_output, create_record, create_records, \
    field_add_subfield, record_add_field, record_has_field, record_get_field_value
from invenio.bibtask import task_low_level_submission
from invenio.config import CFG_BINDIR, CFG_TMPDIR, CFG_BIBEDIT_TIMEOUT, \
    CFG_BIBEDIT_LOCKLEVEL, CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG as OAIID_TAG, \
    CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG as SYSNO_TAG
from invenio.dateutils import convert_datetext_to_dategui
from invenio.dbquery import run_sql
from invenio.shellutils import run_shell_command
from invenio.search_engine import print_record, record_exists, get_fieldvalues
import invenio.template

bibedit_templates = invenio.template.load('bibedit')

## precompile some often-used regexp for speed reasons:
re_tasks = sre.compile('ID="(\d+)"')
re_file_option = sre.compile(r'^/')
re_filename_suffix = sre.compile('_(\d+)\.xml$')
re_date = sre.compile('\.(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)')

def perform_request_index(ln, recid, cancel, delete, confirm_delete, uid, temp, format_tag, edit_tag,
                          delete_tag, num_field, add, dict_value=None):
    """Returns the body of main page. """

    errors   = []
    warnings = []
    body     = ''

    if cancel != 0:
        os.system("rm %s.tmp" % get_file_path(cancel))

    if delete != 0:
        if confirm_delete != 0:
            body = bibedit_templates.tmpl_confirm(ln, 1, delete, temp, format_tag)
        else:
            (record, junk) = get_record(ln, delete, uid, "false")
            add_field(delete, uid, record, "980", "", "", "c", "DELETED")
            save_temp_record(record, uid, "%s.tmp" % get_file_path(delete))
            save_xml_record(delete)
            body = bibedit_templates.tmpl_confirm(ln)

    else:
        if recid != 0 :
            if record_exists(recid) > 0:
                (record, body) = get_record(ln, recid, uid, temp)

                if record != '' and not record_locked_p(recid):
                    if add == 3:
                        body = ''

                    if edit_tag is not None and dict_value is not None:
                        record = edit_record(recid, uid, record, edit_tag, dict_value, num_field)

                    if delete_tag is not None and num_field is not None:
                        record = delete_field(recid, uid, record, delete_tag, num_field)

                    if add == 4:

                        tag     = dict_value.get("add_tag"    , '')
                        ind1    = dict_value.get("add_ind1"   , '')
                        ind2    = dict_value.get("add_ind2"   , '')
                        subcode = dict_value.get("add_subcode", '')
                        value   = dict_value.get("add_value"  , '')
                        another = dict_value.get("addanother" , '')

                        if tag != '' and subcode != '' and value != '':
                            #add these in the record, take the instance number
                            tag = tag[:3]
                            new_field_number = record_add_field(record, tag, ind1, ind2, [(subcode,value)])
                            record  = add_subfield(recid, uid, tag, record, new_field_number, subcode, value)
                            if another and another != '':
                                #if the user pressed 'another' instead of 'done', take to editing
                                return perform_request_edit(ln, recid, uid, tag, new_field_number, 0, 'marc', True, None, 0, dict_value)

                    body += bibedit_templates.tmpl_table_header(ln, "record", recid, temp, format_tag, add=add)

                    keys = record.keys()<commit_msg>BibEdit: fix adding a field<commit_after>## $Id$
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.

__revision__ = "$Id$"

import cPickle
import marshal
import os
import sre
import time

from invenio.bibedit_config import CFG_BIBEDIT_TMPFILENAMEPREFIX
from invenio.bibedit_dblayer import marc_to_split_tag
from invenio.bibrecord import record_xml_output, create_record, create_records, \
    field_add_subfield, record_add_field, record_has_field, record_get_field_value
from invenio.bibtask import task_low_level_submission
from invenio.config import CFG_BINDIR, CFG_TMPDIR, CFG_BIBEDIT_TIMEOUT, \
    CFG_BIBEDIT_LOCKLEVEL, CFG_BIBUPLOAD_EXTERNAL_OAIID_TAG as OAIID_TAG, \
    CFG_BIBUPLOAD_EXTERNAL_SYSNO_TAG as SYSNO_TAG
from invenio.dateutils import convert_datetext_to_dategui
from invenio.dbquery import run_sql
from invenio.shellutils import run_shell_command
from invenio.search_engine import print_record, record_exists, get_fieldvalues
import invenio.template

bibedit_templates = invenio.template.load('bibedit')

## precompile some often-used regexp for speed reasons:
re_tasks = sre.compile('ID="(\d+)"')
re_file_option = sre.compile(r'^/')
re_filename_suffix = sre.compile('_(\d+)\.xml$')
re_date = sre.compile('\.(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)')

def perform_request_index(ln, recid, cancel, delete, confirm_delete, uid, temp, format_tag, edit_tag,
                          delete_tag, num_field, add, dict_value=None):
    """Returns the body of main page. """

    errors   = []
    warnings = []
    body     = ''

    if cancel != 0:
        os.system("rm %s.tmp" % get_file_path(cancel))

    if delete != 0:
        if confirm_delete != 0:
            body = bibedit_templates.tmpl_confirm(ln, 1, delete, temp, format_tag)
        else:
            (record, junk) = get_record(ln, delete, uid, "false")
            add_field(delete, uid, record, "980", "", "", "c", "DELETED")
            save_temp_record(record, uid, "%s.tmp" % get_file_path(delete))
            save_xml_record(delete)
            body = bibedit_templates.tmpl_confirm(ln)

    else:
        if recid != 0 :
            if record_exists(recid) > 0:
                (record, body) = get_record(ln, recid, uid, temp)

                if record != '' and not record_locked_p(recid):
                    if add == 3:
                        body = ''

                    if edit_tag is not None and dict_value is not None:
                        record = edit_record(recid, uid, record, edit_tag, dict_value, num_field)

                    if delete_tag is not None and num_field is not None:
                        record = delete_field(recid, uid, record, delete_tag, num_field)

                    if add == 4:

                        tag     = dict_value.get("add_tag"    , '')
                        ind1    = dict_value.get("add_ind1"   , '')
                        ind2    = dict_value.get("add_ind2"   , '')
                        subcode = dict_value.get("add_subcode", '')
                        value   = dict_value.get("add_value"  , '')
                        another = dict_value.get("addanother" , '')

                        if tag != '' and subcode != '' and value != '':
                            #add these in the record, take the instance number
                            tag = tag[:3]
                            new_field_number = record_add_field(record, tag, ind1, ind2, datafield_subfield_code_value_tuples=[(subcode,value)])
                            record  = add_subfield(recid, uid, tag, record, new_field_number, subcode, value)
                            if another and another != '':
                                #if the user pressed 'another' instead of 'done', take to editing
                                return perform_request_edit(ln, recid, uid, tag, new_field_number, 0, 'marc', True, None, 0, dict_value)

                    body += bibedit_templates.tmpl_table_header(ln, "record", recid, temp, format_tag, add=add)

                    keys = record.keys()
{'fraction_non_alphanumeric': 0.1001154370867877, 'fraction_numerical': 0.013222793577500263, 'mean_word_length': 2.4292911119107594, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '233619', 'n_tokens_mistral': 3032, 'n_tokens_neox': 2841, 'n_words': 831}