diff --git a/modules/bibedit/lib/bibedit_engine.py b/modules/bibedit/lib/bibedit_engine.py index 6e33c8954..fccbdf300 100644 --- a/modules/bibedit/lib/bibedit_engine.py +++ b/modules/bibedit/lib/bibedit_engine.py @@ -1,520 +1,517 @@ ## $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. # pylint: disable-msg=C0103 """bibedit engine.""" __revision__ = "$Id$" import cPickle import difflib import os import sre import time import zlib from invenio.bibedit_dblayer import get_marcxml_of_record_revision, \ get_record_revisions, marc_to_split_tag from invenio.bibedit_utils import get_file_path, get_tmp_file_owner, \ get_tmp_record, record_in_use_p, record_locked_p from invenio.bibrecord import record_xml_output, create_record, \ field_add_subfield, record_add_field from invenio.bibtask import task_low_level_submission from invenio.config import CFG_BIBEDIT_TIMEOUT from invenio.dateutils import convert_datetext_to_dategui from invenio.search_engine import print_record, record_exists import invenio.template # Precompile regexp: re_revid_split = sre.compile('^(\d+)\.(\d{14})$') re_revdate_split = sre.compile('^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)') bibedit_templates = invenio.template.load('bibedit') -def perform_request_index(ln, recid, cancel, delete, confirm_delete, uid, temp, format_tag, edit_tag, +def perform_request_index(ln, recid, cancel, delete, confirm_delete, uid, 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)) + os.system("rm -f %s.tmp" % get_file_path(cancel)) if delete != 0: if confirm_delete != 0: - body = bibedit_templates.confirm(ln, 'delete', delete, temp, format_tag) + body = bibedit_templates.confirm(ln, 'delete', delete, format_tag) else: - (record, junk) = get_record(ln, delete, uid, "false") + (record, junk) = get_record(delete, uid) add_field(delete, uid, record, "980", "", "", "c", "DELETED") save_temp_record(record, uid, "%s.tmp" % get_file_path(delete)) return perform_request_submit(ln, delete, deleting=True) else: if recid != 0 : if record_exists(recid) > 0: - (record, body) = get_record(ln, recid, uid, temp) + body = '' + (record, original_record) = get_record(recid, uid) 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: #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) - + # Compare original record with version in tmp file, to + # determine if it has been edited. + if record != original_record: + tmp = True + body = bibedit_templates.editor_warning_temp_file(ln) + else: + tmp = False revisions = len(get_record_revision_ids(recid)) - 1 - body += bibedit_templates.editor_table_header(ln, "record", recid, temp, format_tag, add=add, revisions=revisions) + body += bibedit_templates.editor_table_header(ln, "record", recid, tmp, format_tag, add=add, revisions=revisions) keys = record.keys() keys.sort() for tag in keys: fields = record.get(str(tag), "empty") if fields != "empty": for field in fields: if field[0]: # Only display if has subfield(s) body += bibedit_templates.editor_table_value(ln, recid, tag, field, format_tag, "record", add) if add == 3: body += bibedit_templates.editor_table_value(ln, recid, '', [], format_tag, "record", add, 1) body += bibedit_templates.editor_table_footer(ln, "record", add, 1) elif not record: body = bibedit_templates.record_choice_box(ln, 3) else: body = bibedit_templates.record_choice_box(ln, 4) os.system("rm %s.tmp" % get_file_path(recid)) else: if record_exists(recid) == -1: body = bibedit_templates.record_choice_box(ln, 2) else: body = bibedit_templates.record_choice_box(ln, 1) else: body = bibedit_templates.record_choice_box(ln, 0) return (body, errors, warnings) def perform_request_edit(ln, recid, uid, tag, num_field, num_subfield, - format_tag, temp, act_subfield, add, dict_value): + format_tag, act_subfield, add, dict_value): """Returns the body of edit page.""" errors = [] warnings = [] body = '' - (record, junk) = get_record(ln, recid, uid, temp) + (record, junk) = get_record(recid, uid) if act_subfield is not None: if act_subfield == 'delete': record = delete_subfield(recid, uid, record, tag, num_field, num_subfield) if act_subfield == 'move_up': record = move_subfield('move_up', recid, uid, record, tag, num_field, num_subfield) if act_subfield == 'move_down': record = move_subfield('move_down', recid, uid, record, tag, num_field, num_subfield) if add == 2: subcode = dict_value.get("add_subcode", "empty") value = dict_value.get("add_value" , "empty") if subcode == '': subcode = "empty" if value == '': value = "empty" if value != "empty" and subcode != "empty": record = add_subfield(recid, uid, tag, record, num_field, subcode, value) - body += bibedit_templates.editor_table_header(ln, "edit", recid, temp=temp, + + body += bibedit_templates.editor_table_header(ln, "edit", recid, False, tag=tag, num_field=num_field, add=add) tag = tag[:3] fields = record.get(str(tag), 'empty') if fields != "empty": for field in fields: if field[4] == int(num_field) : body += bibedit_templates.editor_table_value(ln, recid, tag, field, format_tag, "edit", add) break body += bibedit_templates.editor_table_footer(ln, "edit", add) return (body, errors, warnings) def save_temp_record(record, uid, file_path): - """Save record dict in temp file.""" + """Save record dict in tmp file.""" file_temp = open(file_path, "w") cPickle.dump([uid, record], file_temp) file_temp.close() -def get_record(ln, recid, uid, temp): - """Returns a record dict, and warning message in case of error.""" - - warning_temp_file = '' +def get_record(recid, uid): + """ + Returns original and tmp record dict. If returned tmp record dict is + empty, that indicates another user editing the record. + """ + original_record = create_record(print_record(recid, 'xm'))[0] + tmp_record = '' file_path = get_file_path(recid) - if temp != "false": - warning_temp_file = bibedit_templates.editor_warning_temp_file(ln) - if os.path.isfile("%s.tmp" % file_path): - - (uid_record_temp, record) = get_tmp_record(recid) - if uid_record_temp != uid: - + (tmp_record_uid, tmp_record) = get_tmp_record(recid) + if tmp_record_uid != uid: time_tmp_file = os.path.getmtime("%s.tmp" % file_path) time_out_file = int(time.time()) - CFG_BIBEDIT_TIMEOUT - if time_tmp_file < time_out_file : os.system("rm %s.tmp" % file_path) - record = create_record(print_record(recid, 'xm'))[0] - save_temp_record(record, uid, "%s.tmp" % file_path) - + tmp_record = original_record + save_temp_record(tmp_record, uid, "%s.tmp" % file_path) else: - record = {} - - else: - warning_temp_file = bibedit_templates.editor_warning_temp_file(ln) - + tmp_record = {} else: - record = create_record(print_record(recid, 'xm'))[0] - save_temp_record(record, uid, "%s.tmp" % file_path) + tmp_record = original_record + save_temp_record(tmp_record, uid, "%s.tmp" % file_path) - return (record, warning_temp_file) + return tmp_record, original_record ######### EDIT ######### def edit_record(recid, uid, record, edit_tag, dict_value, num_field): """Edits value of a record.""" - for num_subfield in range( len(dict_value.keys())/3 ): # Iterate over subfield indices of field new_subcode = dict_value.get("subcode%s" % num_subfield, None) old_subcode = dict_value.get("old_subcode%s" % num_subfield, None) new_value = dict_value.get("value%s" % num_subfield, None) old_value = dict_value.get("old_value%s" % num_subfield, None) if new_value is not None and old_value is not None \ and new_subcode is not None and old_subcode is not None: # Make sure we actually get these values if new_value != '' and new_subcode != '': # Forbid empty values if new_value != old_value or \ new_subcode != old_subcode: # only change when necessary edit_tag = edit_tag[:5] record = edit_subfield(record, edit_tag, new_subcode, new_value, num_field, num_subfield) save_temp_record(record, uid, "%s.tmp" % get_file_path(recid)) return record def edit_subfield(record, tag, new_subcode, new_value, num_field, num_subfield): """Edits the value of a subfield.""" new_value = bibedit_templates.clean_value(str(new_value), "html") (tag, ind1, ind2, junk) = marc_to_split_tag(tag) fields = record.get(str(tag), None) if fields is not None: i = -1 for field in fields: i += 1 if field[4] == int(num_field): subfields = field[0] j = -1 for subfield in subfields: j += 1 if j == num_subfield: # Rely on counted index to identify subfield to edit... record[tag][i][0][j] = (new_subcode, new_value) break break return record ######### ADD ######## def add_field(recid, uid, record, tag, ind1, ind2, subcode, value_subfield): """Adds a new field to the record.""" tag = tag[:3] new_field_number = record_add_field(record, tag, ind1, ind2) record = add_subfield(recid, uid, tag, record, new_field_number, subcode, value_subfield) save_temp_record(record, uid, "%s.tmp" % get_file_path(recid)) return record def add_subfield(recid, uid, tag, record, num_field, subcode, value): """Adds a new subfield to a field.""" tag = tag[:3] fields = record.get(str(tag)) i = -1 for field in fields: i += 1 if field[4] == int(num_field) : subfields = field[0] field_add_subfield(record[tag][i], subcode, value) break save_temp_record(record, uid, "%s.tmp" % get_file_path(recid)) return record ######### DELETE ######## def delete_field(recid, uid, record, tag, num_field): """Deletes field in record.""" (tag, junk, junk, junk) = marc_to_split_tag(tag) tmp = [] for field in record[tag]: if field[4] != int(num_field) : tmp.append(field) if tmp != []: record[tag] = tmp else: del record[tag] save_temp_record(record, uid, "%s.tmp" % get_file_path(recid)) return record def delete_subfield(recid, uid, record, tag, num_field, num_subfield): """Deletes subfield of a field.""" (tag, junk, junk, subcode) = marc_to_split_tag(tag) tmp = [] i = -1 deleted = False for field in record[tag]: i += 1 if field[4] == int(num_field): j = 0 for subfield in field[0]: if j != num_subfield: #if subfield[0] != subcode or deleted == True: tmp.append((subfield[0], subfield[1])) #else: # deleted = True j += 1 break record[tag][i] = (tmp, record[tag][i][1], record[tag][i][2], record[tag][i][3], record[tag][i][4]) save_temp_record(record, uid, "%s.tmp" % get_file_path(recid)) return record def move_subfield(direction, recid, uid, record, tag, num_field, num_subfield): """Moves a subfield up in the field.""" (tag, junk, junk, subcode) = marc_to_split_tag(tag) i = -1 for field in record[tag]: i += 1 if field[4] == int(num_field): j = -1 mysubfields = field[0] for subfield in mysubfields: j += 1 if direction == 'move_up' and num_subfield == j and j > 0: #swap this and the previous.. prevsubfield = field[0][j-1] field[0][j-1] = subfield field[0][j] = prevsubfield if direction == 'move_down' and num_subfield == j and j < len(mysubfields): #swap this and the next.. nextsubfield = field[0][j+1] field[0][j+1] = subfield field[0][j] = nextsubfield save_temp_record(record, uid, "%s.tmp" % get_file_path(recid)) return record def perform_request_submit(ln, recid, xml_record='', deleting=False): """Submits record to the database. """ if xml_record: save_xml_record(recid, xml_record) else: save_xml_record(recid) errors = [] warnings = [] if deleting: body = bibedit_templates.record_choice_box(ln, 6) else: body = bibedit_templates.record_choice_box(ln, 5) return (body, errors, warnings) def save_xml_record(recid, xml_record=''): """Saves XML record file to database.""" file_path = get_file_path(recid) os.system("rm -f %s.xml" % file_path) file_temp = open("%s.xml" % file_path, 'w') if xml_record: file_temp.write(xml_record) else: file_temp.write(record_xml_output(get_tmp_record(recid)[1])) os.system("rm %s.tmp" % file_path) file_temp.close() task_low_level_submission('bibupload', 'bibedit', '-P', '5', '-r', '%s.xml' % file_path) def perform_request_history(ln, recid, revid, revid_cmp, action, uid, format_tag): """Performs historic operations on a record.""" errors = [] warnings = [] body = '' if action == 'revert' and revid: body = bibedit_templates.confirm( ln, 'revert', recid, format_tag=format_tag, revid=revid, revdate=split_revid(revid, 'dategui')[1]) return (body, errors, warnings) if action == 'confirm_revert' and revid: # Is the record locked for editing? if record_locked_p(recid): body = bibedit_templates.record_choice_box(ln, 4) return (body, errors, warnings) # Is the record being edited? if record_in_use_p(recid): if get_tmp_file_owner(recid) != uid: body = bibedit_templates.record_choice_box(ln, 3) return (body, errors, warnings) else: os.system("rm -f %s" % ('%s.tmp' % get_file_path(recid))) # Submit the revision. return perform_request_submit(ln, recid, get_marcxml_of_revision_id(revid)) revids = get_record_revision_ids(recid) if not revid: revid = revids[0] body = bibedit_templates.history_container('header') revdates = [split_revid(some_revid, 'dategui')[1] for some_revid in revids] revdate = split_revid(revid, 'dategui')[1] if action == 'compare' and revid_cmp: revdate_cmp = split_revid(revid_cmp, 'dategui')[1] xml1 = get_marcxml_of_revision_id(revid) xml2 = get_marcxml_of_revision_id(revid_cmp) comparison = bibedit_templates.clean_value( get_xml_comparison(revid, revid_cmp, xml1, xml2), 'text').replace('\n', '<br />\n ') body += bibedit_templates.history_comparebox(ln, revdate, revdate_cmp, comparison) forms = bibedit_templates.history_forms(ln, recid, revids, - revdates, 'compare', revid, revid_cmp) + revdates, 'compare', revid, format_tag, revid_cmp) else: current = revid == revids[0] revision = create_record(get_marcxml_of_revision_id( revid))[0] body += bibedit_templates.history_viewbox(ln, 'header', current, recid, revid, revdate) - body += bibedit_templates.history_revision(ln, recid, + body += bibedit_templates.history_revision(ln, recid, format_tag, revision) body += bibedit_templates.history_viewbox(ln, 'footer', current, recid, revid, revdate) forms = bibedit_templates.history_forms(ln, recid, revids, - revdates, 'view', revid) + revdates, 'view', revid, format_tag) body += forms body += bibedit_templates.history_container('footer') return (body, errors, warnings) def get_marcxml_of_revision_id(revid): """ Return MARCXML string with corresponding to revision REVID (=RECID.REVDATE) of a record. Return empty string if revision does not exist. REVID is assumed to be washed already. """ res = "" (recid, job_date) = split_revid(revid, 'datetext') tmp_res = get_marcxml_of_record_revision(recid, job_date) if tmp_res: for row in tmp_res: res += zlib.decompress(row[0]) + "\n" return res def get_record_revision_ids(recid): """ Return list of all known record revision ids (=RECID.REVDATE) for record RECID in chronologically decreasing order (latest first). """ res = [] tmp_res = get_record_revisions(recid) for row in tmp_res: res.append("%s.%s" % (row[0], row[1])) return res def get_xml_comparison(header1, header2, xml1, xml2): """ Return diffs of two MARCXML records. """ return "".join(difflib.unified_diff(xml1.splitlines(1), xml2.splitlines(1), header1, header2)) def split_revid(revid, dateformat=''): """ Split revid and return tuple with (recid, revdate). Optional dateformat can be datetext or dategui. """ (recid, revdate) = re_revid_split.search(revid).groups() if dateformat: datetext = '%s-%s-%s %s:%s:%s' % re_revdate_split.search( revdate).groups() if dateformat == 'datetext': revdate = datetext elif dateformat == 'dategui': revdate = convert_datetext_to_dategui(datetext, secs=True) return (recid, revdate) def revision_format_valid_p(revid): """Predicate to test validity of revision ID format (=RECID.REVDATE).""" if re_revid_split.match(revid): return True return False \ No newline at end of file diff --git a/modules/bibedit/lib/bibedit_templates.py b/modules/bibedit/lib/bibedit_templates.py index 7b5cf7fae..d6b763001 100644 --- a/modules/bibedit/lib/bibedit_templates.py +++ b/modules/bibedit/lib/bibedit_templates.py @@ -1,869 +1,854 @@ ## $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$" from invenio.bibedit_dblayer import get_name_tag, get_tag_name, \ marc_to_split_tag, split_tag_to_marc from invenio.config import CFG_SITE_URL from invenio.messages import gettext_set_language ## Link of edit, move up and delete button: btn_delete_url = CFG_SITE_URL + "/img/iconcross.gif" btn_moveup_url = CFG_SITE_URL + "/img/arrow_up.gif" btn_movedown_url = CFG_SITE_URL + "/img/arrow_down.gif" btn_edit_url = CFG_SITE_URL + "/img/iconpen.gif" bibediturl = "%s/admin/bibedit/bibeditadmin.py" % CFG_SITE_URL class Template: def clean_value(self, value, format): """ This function clean value for HTML interface and inverse. """ if format != "html": value = value.replace('"', '"') value = value.replace('<', '<') value = value.replace('>', '>') else: value = value.replace('"', '"') value = value.replace('<', '<') value = value.replace('>', '>') return value - def confirm(self, ln, message='', recid='', temp='', format_tag='', revid='', revdate=''): + def confirm(self, ln, message='', recid='', format_tag='', revid='', revdate=''): """ Ask for confirmation of or confirm some critical action. """ _ = gettext_set_language(ln) if message == 'delete': return """ %(message)s <div style="float:left;"> <form action="%(bibediturl)s/index?delete=%(recid)s" method="POST"> %(input_ln)s %(input_button_yes)s </form> </div> <div style="float:left;"> - <form action="%(bibediturl)s/index?recid=%(recid)s&temp=%(temp)s&format_tag=%(format_tag)s" method="POST"> + <form action="%(bibediturl)s/index?recid=%(recid)s&format_tag=%(format_tag)s" method="POST"> %(input_ln)s %(input_button_no)s </form> </div> """ % {'message' : _("Do you really want to delete this record?"), 'bibediturl' : bibediturl, 'recid' : str(recid), 'input_ln' : self.input('hidden', ln, 'ln'), 'input_button_yes' : self.input('submit', _("Yes"), class_css='formbutton'), 'input_button_no' : self.input('submit', _("No"), class_css='formbutton'), - 'temp' : temp, 'format_tag' : format_tag} if message == 'revert': question = _('Do you really want to revert to revision %(revdate)s of record #%(recid)s?' ) % {'revdate': revdate, 'recid': recid} warning_1 = _('The current version will be replaced with a copy of revision %(revdate)s' ) % {'revdate': revdate} warning_2 = _('You will also lose any unsubmitted changes for this record!') return """ %(question)s<br /> <b>%(warning_1)s</b><br /> <b>%(warning_2)s</b><br /><br /> <div style="float:left;"> <form action="%(bibediturl)s/history?recid=%(recid)s&revid=%(revid)s&action=confirm_revert" method="POST"> %(input_ln)s %(input_button_yes)s </form> </div> <div style="float:left;"> <form action="%(bibediturl)s/history?recid=%(recid)s&revid=%(revid)s&format_tag=%(format_tag)s" method="POST"> %(input_ln)s %(input_button_no)s </form> </div> """ % {'question' : question, 'warning_1' : warning_1, 'warning_2' : warning_2, 'bibediturl' : bibediturl, 'revid' : revid, 'recid' : recid, 'input_ln' : self.input('hidden', ln, 'ln'), 'input_button_yes': self.input('submit', _("Yes"), class_css='formbutton'), 'input_button_no' : self.input('submit', _("No"), class_css='formbutton'), - 'temp' : temp, 'format_tag' : format_tag} def input(self, type_input, value='', name='', maxlength='', size='', class_css='', style=''): """ Return a input form. """ if value != '': value = 'value="%s"' % str(value) if name != '': name = 'name="%s"' % str(name) if maxlength != '': maxlength = 'maxlength="%s"' % str(maxlength) if size != '': size = 'size="%s"' % str(size) if class_css != '': class_css = 'class="%s"' % str(class_css) if style != '': style = 'style="%s"' % str(style) out = '<input type="%(type)s" %(name)s %(value)s %(size)s %(maxlength)s %(class_css)s %(style)s />' out %= {'type' : type_input, 'value' : value, 'name' : name, 'maxlength' : maxlength, 'size' : size, 'class_css' : class_css, 'style' : style} return out def link(self, ln, text, url, dest, dict_args='', ancre=''): """ Return a link. """ if dict_args == '': link_args = '' else: link_args = '?' list_args = dict_args.items() for arg in list_args: link_args += "%(name)s=%(value)s&" % {'name' : str(arg[0]), 'value' : str(arg[1])} link_args += "ln=%s" % ln if ancre != '': ancre = '#' + ancre return '<a href="%(url)s/%(dest)s%(args)s%(ancre)s">%(text)s</a>' % {'text' : text, 'url' : url, 'dest' : dest, 'args' : link_args, 'ancre' : ancre} def record_choice_box(self, ln, msgid): """Return the 'main page' with the record selection box, and an optional message.""" _ = gettext_set_language(ln) result = '' if msgid: messages = (_('This record does not exist. Please try another record ' 'ID.'), _('Cannot edit deleted record."'), _('This record is currently being edited by another ' 'user. Please try again later.'), _('The record is locked because of unfinished upload ' 'tasks. Please try again in a few minutes.'), _('Your modifications have now been submitted. They will ' 'be processed as soon as the task queue is empty.'), _('The record will be deleted as soon as the task queue ' 'is empty.')) message = messages[msgid-1] if msgid < 5: result += """ <span class="errorbox"> <b> %(message)s </b> </span><br/><br/> """ % {'message' : message} else: header = _("Edit another record") result += '''%s<br /><br /> <h2>%s</h2>''' % (message, header) - view_history_action = "document.selectForm.action='%s/history';" % bibediturl - input_button_history = '<input type="submit" name="view_history" value="View history" class="formbutton" onClick="%s">' % view_history_action + input_button_history = '<input type="submit" name="view_history" value="View history" class="formbutton">' result += """ <form name="selectForm" action="%(bibediturl)s/index" method="POST"> %(input_ln)s <span style="background-color: #ddd; padding: 5px;"> %(message)s: %(input_recid)s %(input_button_edit)s %(input_button_history)s </span> </form> """ % {'bibediturl' : bibediturl, 'message' : _("Please enter the ID of the record you want to edit"), 'input_ln' : self.input('hidden', ln, 'ln'), 'input_recid' : self.input('text' , '', 'recid'), 'input_button_edit' : self.input('submit', _("Edit"), class_css='formbutton'), 'input_button_history' : input_button_history} return result def subfields(self, ln, recid='', tag_subfield='', value='', tag_field='', format_tag='marc', type_table='', num_value='', num_field='', len_subfields='', add=0): """ This function return the content of subfield. """ _ = gettext_set_language(ln) if add == 1 or add == 3: print_tag_subfield = " $$ " + self.input('text', '', 'add_subcode', 1, 1) else: if type_table != "record": print_tag_subfield = " $$ " + self.input('text', tag_subfield, 'subcode%s' % str(num_value), 1, 1) elif format_tag != 's': print_tag_subfield = "$$%s" % tag_subfield else: print_tag_subfield = "%s%s" % (tag_field[:-1], tag_subfield) if get_name_tag(print_tag_subfield) != print_tag_subfield: print_tag_subfield = get_name_tag(print_tag_subfield) else: print_tag_subfield = "$$%s" % tag_subfield value = self.clean_value(value, "record") print_value = '' print_old_value = '' print_btn = '' print_bgcolor = '' print_old_subcode = '' if type_table != "record" or add == 3: if add == 1 or add == 3: print_value = self.input('text', '', 'add_value', size="115%c" % '%') else: print_old_subcode = self.input('hidden', tag_subfield, 'old_subcode%s' % str(num_value)) print_old_value = self.input('hidden', value, 'old_value%s' % str(num_value)) if len(value) < 75: print_value = self.input('text', value, 'value%s' % str(num_value), style="width:100%;") else: print_value = '<textarea name="value%(num_value)s" cols="70" rows="5" style="width:100%%;">%(value)s</textarea>' print_value %= {'num_value' : str(num_value), 'value' : value} if len_subfields > 1: print_btn = "<td>%s</td>" \ % self.link(ln, '<img border="0" src="%s" alt="%s" />' % (btn_delete_url, _("Delete")), bibediturl, 'edit', {'recid' : str(recid), 'tag' : tag_field[:-1]+ tag_subfield, 'num_field' : num_field, 'format_tag' : format_tag, - 'temp' : 'true', 'act_subfield' : 'delete', #delete 'num_subfield' : num_value}) if num_value > 0: print_btn += "<td>%s</td>" \ % self.link(ln, '<img border="0" src="%s" alt="%s" />' % (btn_moveup_url, _("Move up")), bibediturl, 'edit', {'recid' : str(recid), 'tag' : tag_field[:-1]+ tag_subfield, 'num_field' : num_field, 'format_tag' : format_tag, - 'temp' : 'true', 'act_subfield' : 'move_up', #move up 'num_subfield' : num_value}) else: print_btn += "<td> </td>" if num_value < len_subfields-1: print_btn += "<td>%s</td>" \ % self.link(ln, '<img border="0" src="%s" alt="%s" />' % (btn_movedown_url, _("Move down")), bibediturl, 'edit', {'recid' : str(recid), 'tag' : tag_field[:-1]+ tag_subfield, 'num_field' : num_field, 'format_tag' : format_tag, - 'temp' : 'true', 'act_subfield' : 'move_down', 'num_subfield' : num_value}) else: print_value = value print_bgcolor = " background: #FFF;" return """ <td style="background: #F5F5F5" class="admintdright"> %(print_tag_subfield)s %(print_old_subcode)s </td> <td style="padding: 0px 5px 0px 5px; %(print_bgcolor)s width:700px"> <span style="font-size:small;"> %(print_value)s </span> %(print_old_value)s </td> %(print_btn)s <td></td> """ % {'print_tag_subfield' : print_tag_subfield, 'print_old_subcode' : print_old_subcode, 'print_bgcolor' : print_bgcolor, 'print_value' : print_value, 'print_old_value' : print_old_value, 'print_btn' : print_btn} - def editor_table_header(self, ln, type_table, recid, temp="false", format_tag='marc', + def editor_table_header(self, ln, type_table, recid, tmp, format_tag='marc', tag='', num_field=None, add=0, revisions=0): """ Return the Header of table. """ _ = gettext_set_language(ln) (tag, ind1, ind2, junk) = marc_to_split_tag(tag) tag = tag + ind1 + ind2 + "%" if type_table != "record": if add == 1: print_input_add_form = self.input('hidden', 2, 'add') else: print_input_add_form = '' print_action_add_subfield = print_input_add_form + self.input('hidden', str(num_field), 'num_field') print_action_edit_100 = print_input_add_form + self.input('hidden', str(num_field), 'num_field') if add != 1: link_add_subfields = self.link(ln, _("Add Subfield"), bibediturl, 'edit', {'recid' : str(recid), 'tag' : tag[:3], 'num_field' : str(num_field), 'format_tag' : format_tag, - 'temp' : 'true', 'add' : 1}) link_edit_100 = "" print_action_edit_100 = "" #tag[:3] == 100x is never true, of course. This functionality TBD #and will be used in enrichment editing if str(tag[:3]) == "100x": #FIXME link_edit_100 = self.link( ln, _("Edit institute"), bibediturl, 'edit', {'recid' : str(recid), 'tag' : tag[:3], 'num_field' : str(num_field), 'format_tag' : format_tag, - 'temp' : 'true', 'add' : 1}) print_action_edit_100 = """ %(field)s: %(link_edit_100)s """ % {'field' : _("Field"), 'link_edit_100' : link_edit_100} print_action_add_subfield = """ %(field)s: %(link_add_subfields)s """ % {'field' : _("Field"), 'link_add_subfields' : link_add_subfields} if add == 1: link_form = "edit" else: link_form = "index" formcontents = """ <form action="%(bibediturl)s/%(link_form)s" method="POST"> %(input_recid)s - %(input_temp)s %(input_ln)s <div class="bibEditCellRight" style="font-weight: normal;"> %(print_action_add_subfield)s %(print_action_edit_100)s </div> """ % {'bibediturl' : bibediturl, 'input_recid' : self.input('hidden', recid, 'recid'), - 'input_temp' : self.input('hidden', 'true', 'temp'), 'input_ln' : self.input('hidden', ln, 'ln'), 'link_form' : link_form, 'print_action_add_subfield' : print_action_add_subfield, 'print_action_edit_100' : print_action_edit_100} result = formcontents else: link_submit = '' link_add_field = self.link(ln, _("Add Field"), bibediturl, 'index', {'recid' : str(recid), 'tag' : tag[:3], 'format_tag' : format_tag, - 'temp' : 'true', 'add' : 3}, 'add') + " | " link_diplay_verbose = self.link(ln, _("Verbose"), bibediturl, 'index', {'recid' : str(recid), - 'format_tag' : 's', - 'temp' : temp}) + 'format_tag' : 's'}) link_diplay_marc = self.link(ln, "MARC", bibediturl, 'index', {'recid' : str(recid), - 'format_tag' : 'marc', - 'temp' : temp}) + 'format_tag' : 'marc'}) - if temp != "false" and add != 3: + if tmp and add != 3: link_submit = self.link(ln, _("Submit"), bibediturl, 'submit', {'recid' : str(recid)}) + " | " if add == 3: link_add_field = '' result = '' else: link_cancel = self.link(ln, _("Cancel"), bibediturl, 'index', {'cancel' : str(recid)}) link_delete = self.link(ln, _("Delete"), bibediturl, 'index', {'delete' : str(recid), - 'confirm_delete' :1, - 'temp' : temp}) + 'confirm_delete' :1}) result = """ <div class="bibEditCellRight" style="font-weight: normal"> %(action)s: %(link_submit)s%(link_cancel)s %(record)s: %(link_add_field)s%(link_delete)s %(display)s: %(link_diplay_verbose)s | %(link_diplay_marc)s </div> """ % {'action' : _("Action"), 'record' : _("Record"), 'display' : _("Display"), 'link_submit' : link_submit, 'link_add_field' : link_add_field, 'link_diplay_verbose' : link_diplay_verbose, 'link_diplay_marc' : link_diplay_marc, 'link_cancel' : link_cancel, 'link_delete' : link_delete} history_link = '' if revisions: - history_dest = 'history?ln=%s&recid=%s' % (ln, recid) + history_dest = 'history?ln=%s&recid=%s&format_tag=%s' % ( + ln, recid, format_tag) if revisions == 1: history_link_text = _('(%s previous revision)') % revisions else: history_link_text = _('(%s previous revisions)') % revisions history_link = self.link(ln, history_link_text, bibediturl, history_dest) return """ <table class="bibEditTable"> <tr> <th colspan="6"> %(record)s #%(recid)s %(history_link)s %(result)s %(num_field)s </th> </tr> """ % {'record' : _("Record"), 'recid' : str(recid), 'history_link': history_link, 'result' : result, 'num_field': self.input('hidden', str(num_field), 'num_field')} def editor_table_value(self, ln, recid, tag, field, format_tag, type_table, add, form_add=0): """ Return a field to print in table. """ if form_add == 0: subfields = field[0] num_field = field[4] tag_field = split_tag_to_marc(tag, field[1], field[2]) if format_tag != 's': print_tag_field = tag_field[:-1] else: tag_field = tag_field[:-1] + '%' if get_name_tag(tag_field) != tag_field: print_tag_field = get_name_tag(tag_field) else: print_tag_field = tag_field[:-1] len_subfields = len(subfields) if type_table == "record" and add != 3: print_link_function = self.editor_link_function(ln, len_subfields, recid, tag, num_field, format_tag) print_tag_form = '' else: print_link_function = '' if add == 1: print_tag_form = self.input('hidden', get_tag_name(print_tag_field), 'tag') else: print_tag_form = self.input('hidden', get_tag_name(print_tag_field), 'edit_tag') if add == 1: len_subfields += 1 type_table = "record" try: result = """<td rowspan="%(len_subfields)s" class="bibEditCellTag"> %(print_tag_field)s %(print_tag_form)s </td> %(subfield)s %(print_link_function)s """ % {'len_subfields' : len_subfields, 'print_tag_field' : print_tag_field, 'print_tag_form' : print_tag_form, 'subfield' : self.subfields(ln, recid, subfields[0][0], subfields[0][1], tag_field, format_tag, type_table, 0, num_field, len_subfields), 'print_link_function' : print_link_function} except IndexError: raise "FIXME: BibEdit does not seem to be able to edit records with controlfields." if len_subfields != 1: num_value = -1 for subfield in subfields: num_value += 1 if num_value != 0: result += """ <tr> %s </tr> """ % self.subfields(ln, recid, subfield[0], subfield[1], tag_field, format_tag, type_table, num_value, num_field, len_subfields) if add == 1: result += """ <tr> %s </tr> """ % self.subfields(ln, add=add) else: #click on "add field" link on the top of index page. result = """ <td class="bibEditCellTag"> <form action="%(bibediturl)s/index" method="GET"> %(input_recid)s - %(input_temp)s %(input_ln)s %(input_add)s <b> <a name="add">Tag</a>: <input type="text" name="add_tag" maxlength="3" size="3" /> ind1: <input type="text" name="add_ind1" maxlength="1" size="1" /> ind2: <input type="text" name="add_ind2" maxlength="1" size="1" /> </b> </td> """ % {'bibediturl' : bibediturl, 'input_recid' : self.input('hidden', recid, 'recid'), - 'input_temp' : self.input('hidden', 'true', 'temp'), 'input_add' : self.input('hidden', 4, 'add'), 'input_ln' : self.input('hidden', ln, 'ln'), 'recid' : str(recid), 'ln' : ln} result += "%s" % self.subfields(ln, add=add) return """ <tr><td></td></tr> <tr> %s </tr> """ % result def editor_table_footer(self, ln, type_table, add=0, another=0): """ Return a footer of table. """ _ = gettext_set_language(ln) dbutton = _("Done") abutton = _("Add another subfield") if type_table != "record" or add == 3: #add a done button and 'add another subfield' button in the form form = self.input('submit', dbutton, class_css='formbutton') + "<br/>" if another: form += self.input('submit', abutton, 'addanother', class_css='formbutton') + "<br>" form += _("Tags and values should be filled before pressing Done or Add another subfield") form += "</form>" else: form = '' return """ <tr> <td align="right" colspan="6"> %(form)s </td> </tr> </table> """ % {'form' : form} def editor_link_function(self, ln, len_subfields, recid, tag, num_field, format_tag): """ Print button function to edit and delete information. """ _ = gettext_set_language(ln) btn_edit = self.link(ln, '<img style="border:0px" src="%s" alt="%s" />' % (btn_edit_url, _("Edit")), bibediturl, 'edit', {'recid' : str(recid), 'tag' : tag, 'num_field' : num_field, - 'format_tag' : format_tag, - 'temp' : 'true'}) + 'format_tag' : format_tag}) btn_delete = self.link(ln, '<img style="border: 0px" src="%s" alt="%s" />' % (btn_delete_url, _("Delete")), bibediturl, 'index', {'recid' : str(recid), 'delete_tag' : tag, 'num_field' : num_field, - 'format_tag' : format_tag, - 'temp' : 'true'}) + 'format_tag' : format_tag}) return """ <td rowspan="%(len_subfields)s" style="text-align:center;vertical-align:top;"> %(btn_edit)s </td> <td rowspan="%(len_subfields)s" style="text-align:center;vertical-align:top;"> %(btn_delete)s </td> """ % {'len_subfields' : len_subfields, 'btn_edit' : btn_edit, 'btn_delete' : btn_delete} def editor_warning_temp_file(self, ln): - """ Return a warning message for user who use a temp file. """ + """ Return a warning message for user who use a tmp file. """ _ = gettext_set_language(ln) return """ <span style="color: #000; background: #fcc; padding: 1px; font-weight: bold; border-spacing: 3px; border: 2px solid #900;"> %(message1)s %(message2)s </span><br/><br/> """ % {'message1' : _("Your changes are TEMPORARY."), 'message2' : _("To save this record, please click on submit.")} def history_container(self, part): """ Display the bibedit history page container. """ if part == 'header': out = ''' <div>''' if part == 'footer': out = ''' </div> ''' return out def history_viewbox(self, ln, part, current=None, recid=None, revid=None, revdate=None): """ Display the bibedit history viewbox. """ _ = gettext_set_language(ln) if part == 'header': title = _("Revision %(revdate)s" ) % {'revdate': revdate} if current: parant = _('current version') else: text = _('revert to this revision') dest = '''history?recid=%(recid)s&revid=%(revid)s&action=revert''' % { 'recid': recid, 'revid': revid} parant = self.link(ln, text, bibediturl, dest) out = ''' <div class="bibEditHistView"> <table class="bibEditTable"> <th colspan="4"> %s (%s) </th>''' % (title, parant) elif part == 'footer': out = ''' <tr> <td align="right" colspan="6"> </td> </tr> </table> </div>''' return out - def history_revision(self, ln, recid, revision): + def history_revision(self, ln, recid, format_tag, revision): """ Display the content of a record in the bibedit history. """ out = '' keys = revision.keys() keys.sort() for tag in keys: fields = revision.get(str(tag), "empty") if fields != "empty": for field in fields: if field[0]: # Only display if has subfield(s) - out += self.history_table_value(ln, recid, tag, field) + out += self.history_table_value(ln, recid, + format_tag, tag, field) return out - def history_table_value(self, ln, recid, tag, field): + def history_table_value(self, ln, recid, format_tag, tag, field): """ Return a field to print in table, like editor_table_value, but without the edit and delete buttons.""" #FIXME: We should refactor to get a more generic printing of these fields. - - format_tag = 'marc' type_table = 'record' subfields = field[0] num_field = field[4] tag_field = split_tag_to_marc(tag, field[1], field[2]) print_tag_field = tag_field[:-1] len_subfields = len(subfields) try: result = """ <td rowspan="%(len_subfields)s" class="bibEditCellTag"> %(print_tag_field)s </td> %(subfield)s """ % {'len_subfields' : len_subfields, 'print_tag_field' : print_tag_field, 'subfield' : self.subfields(ln, recid, subfields[0][0], subfields[0][1], tag_field, format_tag, type_table, 0, num_field, len_subfields)} except IndexError: raise "FIXME: BibEdit does not seem to be able to edit records with controlfields." if len_subfields != 1: num_value = -1 for subfield in subfields: num_value += 1 if num_value != 0: result += """ <tr> %s </tr>""" % self.subfields(ln, recid, subfield[0], subfield[1], tag_field, format_tag, type_table, num_value, num_field, len_subfields) return """ <tr> <td> </td> </tr> <tr> %s </tr> """ % result def history_comparebox(self, ln, revdate, revdate_cmp, comparison): """ Display the bibedit history comparison box. """ _ = gettext_set_language(ln) title = '<b>%(comp)s</b><br />%(rev)s %(revdate)s<br />%(rev)s %(revdate_cmp)s' % { 'comp': _('Comparison of:'), 'rev': _('Revision'), 'revdate': revdate, 'revdate_cmp': revdate_cmp} return ''' <div class="bibEditHistCompare"> <p>%s</p> <p> %s </p> </div>''' % (title, comparison) - def history_forms(self, ln, recid, revids, revdates, page_type, revid, revid_cmp=None): + def history_forms(self, ln, recid, revids, revdates, page_type, revid, + format_tag, revid_cmp=None): """ Display the bibedit history option forms. """ _ = gettext_set_language(ln) # Hidden input fields input_ln = self.input('hidden', value=ln, name='ln') input_recid = self.input('hidden', value=recid, name='recid') + input_format_tag = self.input('hidden', value=format_tag, name='format_tag') input_compare = self.input('hidden', value='compare', name='action') input_revert = self.input('hidden', value='revert', name='action') # Buttons edit_button = _("Edit current version") view_button = _("View revision") compare_button = _("Compare revisions") revert_button = _("Revert to revision") back_button = _("Back to bibedit") input_edit_submit = self.input('submit', edit_button, class_css='formbutton', style='width: 200px;') input_view_submit = self.input('submit', view_button, class_css='formbutton', style='width: 200px; margin-top: 20px;') input_compare_submit = self.input('submit', compare_button, class_css='formbutton', style='width: 200px; margin-top: 20px;') input_revert_submit = self.input('submit', revert_button, class_css='formbutton', style='width: 200px; margin-top: 20px;') input_back_submit = self.input('submit', back_button, class_css='formbutton', style='width: 200px; margin-top: 30px;') # Option lists optlist = self.history_select(revids, revdates) optlist_revert = self.history_select(revids[1:], revdates[1:]) if page_type == 'view': optlist_view = self.history_select(revids, revdates, revid) else: optlist_view = optlist if page_type == 'compare': optlist_cmp1 = self.history_select(revids, revdates, revid) optlist_cmp2 = self.history_select(revids, revdates, revid_cmp) else: optlist_cmp1 = optlist_cmp2 = optlist default_actionurl = bibediturl + '/history' edit_form = self.history_form(bibediturl + '/index', input_edit_submit, - hidden_fields=(input_ln, input_recid)) + hidden_fields=(input_ln, input_recid, input_format_tag)) view_form = self.history_form(default_actionurl, input_view_submit, - ('revid',), (optlist_view,), (input_ln, input_recid)) + ('revid',), (optlist_view,), (input_ln, input_recid, + input_format_tag)) compare_form = self.history_form(default_actionurl, input_compare_submit, ('revid', 'revid_cmp'), (optlist_cmp1, optlist_cmp2), (input_ln, - input_recid, input_compare)) + input_recid, input_format_tag, input_compare)) revert_form = self.history_form(default_actionurl, input_revert_submit, ('revid',), (optlist_revert,), (input_ln, input_recid, - input_revert)) + input_format_tag, input_revert)) back_form = self.history_form(bibediturl + '/index', input_back_submit, hidden_fields=(input_ln,)) return ''' <div class="bibEditHistForm"> <table> %(edit_form)s %(view_form)s %(compare_form)s %(revert_form)s %(back_form)s </table> </div>''' % { 'edit_form': edit_form, 'view_form': view_form, 'compare_form': compare_form, 'revert_form': revert_form, 'back_form': back_form} def history_form(self, actionurl, submit_button, select_names=None, optlists=None, hidden_fields=None): """ Display a bibedit history option form with specified parameters. """ form = '<form action="%s" method="post">' % actionurl button = '''<tr> <td> %s </td> </tr> ''' % submit_button selects = '' if select_names: for i in range(len(select_names)): selects += '''<tr> <td> <select style="width: 200px; margin-top: 5px;" name=%s> %s </select> </td> </tr> ''' % (select_names[i], optlists[i]) hiddens = '' if hidden_fields: for i in range(len(hidden_fields)): hiddens += '''<tr> <td> %s </td> </tr> ''' % (hidden_fields[i]) return '''%(form)s %(button)s %(selects)s %(hiddens)s </form>''' % { 'form': form, 'button': button, 'selects': selects, 'hiddens': hiddens} def history_select(self, revids, revdates, preselect=None): """ Create bibedit history options. """ out = '''<option value=""></option>''' for i in range(len(revids)): if revids[i] == preselect: out += ''' <option selected value="%(revid)s">%(revdate)s</option>''' % { 'revid': revids[i], 'revdate': revdates[i]} else: out += ''' <option value="%(revid)s">%(revdate)s</option>''' % { 'revid': revids[i], 'revdate': revdates[i]} return out \ No newline at end of file diff --git a/modules/bibedit/web/admin/bibeditadmin.py b/modules/bibedit/web/admin/bibeditadmin.py index 46b7d32ad..9005c3b4f 100644 --- a/modules/bibedit/web/admin/bibeditadmin.py +++ b/modules/bibedit/web/admin/bibeditadmin.py @@ -1,204 +1,209 @@ ## $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. # pylint: disable-msg=C0103 """CDS Invenio BibEdit Administrator Interface.""" __revision__ = "$Id$" __lastupdated__ = """$Date$""" from invenio.access_control_engine import acc_authorize_action from invenio.bibedit_engine import perform_request_index, \ perform_request_edit, perform_request_submit, perform_request_history from invenio.config import CFG_SITE_LANG, CFG_SITE_URL from invenio.messages import gettext_set_language, wash_language from invenio.search_engine import record_exists, \ guess_primary_collection_of_a_record from invenio.urlutils import wash_url_argument, redirect_to_url from invenio.webpage import page from invenio.webuser import getUid, page_not_authorized, collect_user_info navtrail = (' <a class="navtrail" href=\"%s/help/admin\">Admin Area</a> ' ) % CFG_SITE_URL -def index(req, ln=CFG_SITE_LANG, recid=None, temp="false", format_tag='marc', +def index(req, ln=CFG_SITE_LANG, recid=None, format_tag='marc', edit_tag=None, delete_tag=None, num_field=None, add=0, cancel=0, - delete=0, confirm_delete=0, **args): + delete=0, confirm_delete=0, view_history=None, **args): """BibEdit Admin interface.""" + if view_history: + redirect_to_url(req, 'history?ln=%s&recid=%s' % (ln, recid)) ln = wash_language(ln) _ = gettext_set_language(ln) uid = getUid(req) recid = wash_url_argument(recid, "int") add = wash_url_argument(add, "int") cancel = wash_url_argument(cancel, "int") delete = wash_url_argument(delete, "int") confirm_delete = wash_url_argument(confirm_delete, "int") if recid == 0: # do not display the introductory recID selection box to guest # users (as it used to be with v0.99.0): user_info = collect_user_info(req) if user_info['email'] == 'guest': (auth_code, auth_message) = acc_authorize_action(req, 'runbibedit') return page_not_authorized(req=req, text=auth_message, navtrail=navtrail) else: # the user is logged in, so display the box: (body, errors, warnings) = perform_request_index(ln, recid, - cancel, delete, confirm_delete, uid, temp, format_tag, + cancel, delete, confirm_delete, uid, format_tag, edit_tag, delete_tag, num_field, add, args) else: (auth_code, auth_message) = acc_authorize_action(req, 'runbibedit', collection=guess_primary_collection_of_a_record(recid)) if auth_code != 0: (auth_code, auth_message) = acc_authorize_action(req, 'runbibedit') if auth_code == 0: (body, errors, warnings) = perform_request_index(ln, recid, - cancel, delete, confirm_delete, uid, temp, format_tag, + cancel, delete, confirm_delete, uid, format_tag, edit_tag, delete_tag, num_field, add, args) else: return page_not_authorized(req=req, text=auth_message, navtrail=navtrail) if recid != 0: title = _("Record") + " #" + str(recid) if add == 3: title = _("Record %s - Add a field") % ('#' + str(recid)) else: title = _("BibEdit Admin Interface") return page(title = title, body = body, errors = errors, warnings = warnings, uid = getUid(req), language = ln, navtrail = navtrail, lastupdated = __lastupdated__, req = req) def edit(req, recid=None, tag=None, num_field='0', num_subfield=0, - format_tag='marc', act_subfield=None, temp="false", add=0, + format_tag='marc', act_subfield=None, add=0, ln=CFG_SITE_LANG, **args): """Edit Field page.""" ln = wash_language(ln) _ = gettext_set_language(ln) uid = getUid(req) recid = wash_url_argument(recid, "int") num_field = wash_url_argument(num_field, "int") add = wash_url_argument(add, "int") num_subfield = wash_url_argument(num_subfield, "int") if (recid and tag and (record_exists(recid)>0)): (auth_code, auth_message) = acc_authorize_action(req, 'runbibedit', collection=guess_primary_collection_of_a_record(recid)) if auth_code != 0: (auth_code, auth_message) = acc_authorize_action(req, 'runbibedit') if auth_code == 0: (body, errors, warnings) = perform_request_edit(ln, recid, uid, - tag, num_field, num_subfield, format_tag, temp, act_subfield, + tag, num_field, num_subfield, format_tag, act_subfield, add, args) else: return page_not_authorized(req=req, text=auth_message, navtrail=navtrail) else: redirect_to_url(req, 'index?ln=' + ln) title = _("Edit record %(x_recid)s, field %(x_field)s") % { 'x_recid': '#' + str(recid), 'x_field': '#' + str(tag[:3])} if add == 1: title = _("Edit record %(x_recid)s, field %(x_field)s - Add a " "subfield") % {'x_recid': '#' + str(recid), 'x_field': '#' + str(tag[:3])} return page(title = title, body = body, errors = errors, warnings = warnings, uid = getUid(req), language = ln, navtrail = navtrail, lastupdated = __lastupdated__, req = req) def submit(req, recid='', ln=CFG_SITE_LANG): """Submit temp record to database.""" ln = wash_language(ln) _ = gettext_set_language(ln) recid = wash_url_argument(recid, "int") if (recid and (record_exists(recid)>0)): (auth_code, auth_message) = acc_authorize_action(req, 'runbibedit', collection=guess_primary_collection_of_a_record(recid)) if auth_code != 0: (auth_code, auth_message) = acc_authorize_action(req, 'runbibedit') if auth_code == 0: (body, errors, warnings) = perform_request_submit(ln, recid) else: return page_not_authorized(req=req, text=auth_message, navtrail=navtrail) else: redirect_to_url(req, 'index?ln=' + ln) return page(title = _("Submit and save record %s") % ( '#' + str(recid)), body = body, errors = errors, warnings = warnings, uid = getUid(req), language = ln, navtrail = navtrail, lastupdated = __lastupdated__, req = req) def history(req, ln=CFG_SITE_LANG, recid=None, revid=None, revid_cmp=None, action=None, format_tag=None): """ Bibedit history interface. """ ln = wash_language(ln) _ = gettext_set_language(ln) uid = getUid(req) recid = wash_url_argument(recid, "int") + debug = open('/opt/cds-invenio/var/tmp/debug2', 'w') + debug.write(str(recid)) + debug.close() if (recid and (record_exists(recid)>0)): (auth_code, auth_message) = acc_authorize_action(req, 'runbibedit', collection=guess_primary_collection_of_a_record(recid)) if auth_code != 0: (auth_code, auth_message) = acc_authorize_action(req, 'runbibedit') if auth_code == 0: (body, errors, warnings) = perform_request_history(ln, recid, revid, revid_cmp, action, uid, format_tag) else: return page_not_authorized(req=req, text=auth_message, navtrail=navtrail) else: - redirect_to_url(req, 'index') + redirect_to_url(req, 'index?ln=' + ln) title = _("Record") + " #" + str(recid) return page(title = title, body = body, errors = errors, warnings = warnings, uid = getUid(req), language = ln, navtrail = navtrail, lastupdated = __lastupdated__, req = req) \ No newline at end of file diff --git a/modules/bibedit/web/test_bibedit_reedit_warning.html b/modules/bibedit/web/test_bibedit_reedit_warning.html index a17eef325..ed1b6b1f8 100644 --- a/modules/bibedit/web/test_bibedit_reedit_warning.html +++ b/modules/bibedit/web/test_bibedit_reedit_warning.html @@ -1,97 +1,102 @@ <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head profile="http://selenium-ide.openqa.org/profiles/test-case"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="selenium.base" href="" /> <title>test_bibedit_reedit_warning</title> </head> <body> <table cellpadding="1" cellspacing="1" border="1"> <thead> <tr><td rowspan="1" colspan="3">test_bibedit_reedit_warning</td></tr> </thead><tbody> <tr> <td>open</td> <td>http://localhost</td> <td></td> </tr> <tr> <td>clickAndWait</td> <td>link=login</td> <td></td> </tr> <tr> <td>type</td> <td>p_un</td> <td>balthasar</td> </tr> <tr> <td>type</td> <td>p_pw</td> <td>b123althasar</td> </tr> <tr> <td>clickAndWait</td> <td>action</td> <td></td> </tr> <tr> <td>open</td> <td>http://localhost/admin/bibedit/bibeditadmin.py?ln=en</td> <td></td> </tr> <tr> <td>type</td> <td>recid</td> <td>2</td> </tr> <tr> <td>clickAndWait</td> <td>//input[@value='Edit']</td> <td></td> </tr> <tr> <td>clickAndWait</td> <td>//img[@alt='Edit']</td> <td></td> </tr> +<tr> + <td>type</td> + <td>value0</td> + <td>asdfasdf</td> +</tr> <tr> <td>clickAndWait</td> <td>//input[@value='Done']</td> <td></td> </tr> <tr> <td>open</td> <td>http://localhost/admin/bibedit/bibeditadmin.py?ln=en</td> <td></td> </tr> <tr> <td>type</td> <td>recid</td> <td>2</td> </tr> <tr> <td>clickAndWait</td> <td>//input[@value='Edit']</td> <td></td> </tr> <tr> <td>verifyTextPresent</td> <td>Your changes are TEMPORARY.</td> <td></td> </tr> <tr> <td>clickAndWait</td> <td>link=Cancel</td> <td></td> </tr> <tr> <td>clickAndWait</td> <td>link=logout</td> <td></td> </tr> </tbody></table> </body> </html>