|
1 | 1 | # This file is part of Invenio.
|
2 |
| -# Copyright (C) 2012, 2013 CERN. |
| 2 | +# Copyright (C) 2012, 2013, 2015, 2016 CERN. |
3 | 3 | #
|
4 | 4 | # Invenio is free software; you can redistribute it and/or
|
5 | 5 | # modify it under the terms of the GNU General Public License as
|
|
46 | 46 | from invenio.webinterface_handler import wash_urlargd, WebInterfaceDirectory
|
47 | 47 | from invenio.urlutils import make_canonical_urlargd, redirect_to_url
|
48 | 48 | from invenio.messages import gettext_set_language
|
49 |
| -from invenio.search_engine import \ |
50 |
| - guess_primary_collection_of_a_record, get_colID, record_exists, \ |
51 |
| - create_navtrail_links, check_user_can_view_record, record_empty, \ |
52 |
| - is_user_owner_of_record |
| 49 | +from invenio.search_engine import ( |
| 50 | + check_user_can_view_record, |
| 51 | + create_navtrail_links, |
| 52 | + get_colID, |
| 53 | + get_merged_recid, |
| 54 | + guess_primary_collection_of_a_record, |
| 55 | + is_user_owner_of_record, |
| 56 | + record_empty, |
| 57 | + record_exists |
| 58 | +) |
53 | 59 | from invenio.bibdocfile import BibRecDocs, normalize_format, file_strip_ext, \
|
54 | 60 | stream_restricted_icon, BibDoc, InvenioBibDocFileError, \
|
55 | 61 | get_subformat_from_format
|
@@ -105,6 +111,21 @@ def getfile(req, form):
|
105 | 111 | navmenuid='submit')
|
106 | 112 |
|
107 | 113 | if record_exists(self.recid) < 1:
|
| 114 | + # Check if the record of the file has been merged |
| 115 | + # if the /record/1 has been merged to /record/2 then |
| 116 | + # /record/1/files/foo.pdf will redirect to /record/2/files/foo.pdf |
| 117 | + merged_recid = get_merged_recid(self.recid) |
| 118 | + if merged_recid: |
| 119 | + # Build the url for the file in merged record |
| 120 | + url = "{0}/{1}/{2}/files/{3}".format( |
| 121 | + CFG_SITE_URL, |
| 122 | + CFG_SITE_RECORD, |
| 123 | + merged_recid, |
| 124 | + filename |
| 125 | + ) |
| 126 | + return redirect_to_url( |
| 127 | + req, url, redirection_type=apache.HTTP_MOVED_PERMANENTLY |
| 128 | + ) |
108 | 129 | msg = "<p>%s</p>" % _("Requested record does not seem to exist.")
|
109 | 130 | return warning_page(msg, req, ln)
|
110 | 131 |
|
|
0 commit comments