def Move_Uploaded_Files_to_Storage(parameters, curdir, form, user_info=None): """ The function moves files uploaded using the Create_Upload_Files_Interface.py function. It reads the action previously performed by the user on the files and calls the corresponding functions of bibdocfile. @param parameters:(dictionary) - must contain: + iconsizes: sizes of the icons to create (when applicable), separated by commas. Eg: 180>,700> + createIconDoctypes: the list of doctypes for which an icon should be created. Eg: Figure|Graph ('|' separated values) Use '*' for all doctypes + forceFileRevision: when revising attributes of a file (comment, description) without uploading a new file, force a revision of the current version (so that old comment, description, etc. is kept) (1) or not (0). """ global sysno recid = int(sysno) iconsize = parameters.get('iconsize').split(',') create_icon_doctypes = parameters.get('createIconDoctypes').split('|') force_file_revision = (parameters.get('forceFileRevision') == '1') try: bibdocfile_managedocfiles._read_file_revision_interface_configuration_from_disk(curdir) except IOError: return bibdocfile_managedocfiles.move_uploaded_files_to_storage(curdir, recid, iconsize, create_icon_doctypes, force_file_revision)
def managedocfiles(self, req, form): """ Display admin interface to manage files of a record """ argd = wash_urlargd(form, { 'ln': (str, ''), 'access': (str, ''), 'recid': (int, None), 'do': (int, 0), 'cancel': (str, None), }) _ = gettext_set_language(argd['ln']) uid = getUid(req) user_info = collect_user_info(req) # Check authorization (auth_code, auth_msg) = acc_authorize_action(req, 'runbibdocfile') if auth_code and user_info['email'] == 'guest': # Ask to login target = CFG_SITE_SECURE_URL + '/youraccount/login' + \ make_canonical_urlargd({'ln' : argd['ln'], 'referer' : CFG_SITE_SECURE_URL + user_info['uri']}, {}) return redirect_to_url(req, target) elif auth_code: return page_not_authorized(req, referer="/%s/managedocfiles" % CFG_SITE_RECORD, uid=uid, text=auth_msg, ln=argd['ln'], navmenuid="admin") # Prepare navtrail navtrail = '''<a class="navtrail" href="%(CFG_SITE_URL)s/help/admin">Admin Area</a> > %(manage_files)s''' \ % {'CFG_SITE_URL': CFG_SITE_URL, 'manage_files': _("Manage Document Files")} body = '' if argd['do'] != 0 and not argd['cancel']: # Apply modifications working_dir = os.path.join(CFG_TMPSHAREDDIR, 'websubmit_upload_interface_config_' + str(uid), argd['access']) if not os.path.isdir(working_dir): # We accessed the url without preliminary steps # (we did not upload a file) # Our working dir does not exist # Display the file manager argd['do'] = 0 else: move_uploaded_files_to_storage(working_dir=working_dir, recid=argd['recid'], icon_sizes=['180>', '700>'], create_icon_doctypes=['*'], force_file_revision=False) # Clean temporary directory shutil.rmtree(working_dir) # Confirm modifications body += '<p style="color:#0f0">%s</p>' % \ (_('Your modifications to record #%(x_redid)i have been submitted', x_redid=argd['recid'])) elif argd['cancel']: # Clean temporary directory working_dir = os.path.join(CFG_TMPSHAREDDIR, 'websubmit_upload_interface_config_' + str(uid), argd['access']) shutil.rmtree(working_dir) body += '<p style="color:#c00">%s</p>' % \ (_('Your modifications to record #%(x_num)i have been cancelled', x_num=argd['recid'])) if not argd['recid'] or argd['do'] != 0: body += ''' <form method="post" action="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/managedocfiles"> <label for="recid">%(edit_record)s:</label> <input type="text" name="recid" id="recid" /> <input type="submit" value="%(edit)s" class="adminbutton" /> </form> ''' % {'edit': _('Edit'), 'edit_record': _('Edit record'), 'CFG_SITE_URL': CFG_SITE_URL, 'CFG_SITE_RECORD': CFG_SITE_RECORD} access = time.strftime('%Y%m%d_%H%M%S') if argd['recid'] and argd['do'] == 0: # Displaying interface to manage files # Prepare navtrail title, dummy_description, dummy_keywords = websearch_templates.tmpl_record_page_header_content(req, argd['recid'], argd['ln']) navtrail = '''<a class="navtrail" href="%(CFG_SITE_URL)s/help/admin">Admin Area</a> > <a class="navtrail" href="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/managedocfiles">%(manage_files)s</a> > %(record)s: %(title)s ''' \ % {'CFG_SITE_URL': CFG_SITE_URL, 'title': title, 'manage_files': _("Document File Manager"), 'record': _("Record #%(x_rec)i", x_rec=argd['recid']), 'CFG_SITE_RECORD': CFG_SITE_RECORD} body += create_file_upload_interface(\ recid=argd['recid'], ln=argd['ln'], uid=uid, sbm_access=access, display_hidden_files=True, restrictions_and_desc=CFG_BIBDOCFILE_DOCUMENT_FILE_MANAGER_RESTRICTIONS, doctypes_and_desc=CFG_BIBDOCFILE_DOCUMENT_FILE_MANAGER_DOCTYPES, **CFG_BIBDOCFILE_DOCUMENT_FILE_MANAGER_MISC)[1] body += '''<br /> <form method="post" action="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/managedocfiles"> <input type="hidden" name="recid" value="%(recid)s" /> <input type="hidden" name="do" value="1" /> <input type="hidden" name="access" value="%(access)s" /> <input type="hidden" name="ln" value="%(ln)s" /> <div style="font-size:small"> <input type="submit" name="cancel" value="%(cancel_changes)s" /> <input type="submit" onclick="user_must_confirm_before_leaving_page=false;return true;" class="adminbutton" name="submit" id="applyChanges" value="%(apply_changes)s" /> </div></form>''' % \ {'apply_changes': _("Apply changes"), 'cancel_changes': _("Cancel all changes"), 'recid': argd['recid'], 'access': access, 'ln': argd['ln'], 'CFG_SITE_URL': CFG_SITE_URL, 'CFG_SITE_RECORD': CFG_SITE_RECORD} return page(title = _("Document File Manager") + (argd['recid'] and (': ' + _("Record #%(x_rec)i", x_rec=argd['recid'])) or ''), navtrail=navtrail, navtrail_append_title_p=0, metaheaderadd = get_upload_file_interface_javascript(form_url_params='?access='+access) + \ get_upload_file_interface_css(), body = body, uid = uid, language=argd['ln'], req=req, navmenuid='admin')
def managedocfiles(self, req, form): """ Display admin interface to manage files of a record """ argd = wash_urlargd( form, { 'ln': (str, ''), 'access': (str, ''), 'recid': (int, None), 'do': (int, 0), 'cancel': (str, None), }) _ = gettext_set_language(argd['ln']) uid = getUid(req) user_info = collect_user_info(req) # Check authorization (auth_code, auth_msg) = acc_authorize_action(req, 'runbibdocfile') if auth_code and user_info['email'] == 'guest': # Ask to login target = CFG_SITE_SECURE_URL + '/youraccount/login' + \ make_canonical_urlargd({'ln' : argd['ln'], 'referer' : CFG_SITE_SECURE_URL + user_info['uri']}, {}) return redirect_to_url(req, target) elif auth_code: return page_not_authorized(req, referer="/%s/managedocfiles" % CFG_SITE_RECORD, uid=uid, text=auth_msg, ln=argd['ln'], navmenuid="admin") # Prepare navtrail navtrail = '''<a class="navtrail" href="%(CFG_SITE_URL)s/help/admin">Admin Area</a> > %(manage_files)s''' \ % {'CFG_SITE_URL': CFG_SITE_URL, 'manage_files': _("Manage Document Files")} body = '' if argd['do'] != 0 and not argd['cancel']: # Apply modifications working_dir = os.path.join( CFG_TMPSHAREDDIR, 'websubmit_upload_interface_config_' + str(uid), argd['access']) if not os.path.isdir(working_dir): # We accessed the url without preliminary steps # (we did not upload a file) # Our working dir does not exist # Display the file manager argd['do'] = 0 else: move_uploaded_files_to_storage(working_dir=working_dir, recid=argd['recid'], icon_sizes=['180>', '700>'], create_icon_doctypes=['*'], force_file_revision=False) # Clean temporary directory shutil.rmtree(working_dir) # Confirm modifications body += '<p style="color:#0f0">%s</p>' % \ (_('Your modifications to record #%(x_redid)i have been submitted', x_redid=argd['recid'])) elif argd['cancel']: # Clean temporary directory working_dir = os.path.join( CFG_TMPSHAREDDIR, 'websubmit_upload_interface_config_' + str(uid), argd['access']) shutil.rmtree(working_dir) body += '<p style="color:#c00">%s</p>' % \ (_('Your modifications to record #%(x_num)i have been cancelled', x_num=argd['recid'])) if not argd['recid'] or argd['do'] != 0: body += ''' <form method="post" action="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/managedocfiles"> <label for="recid">%(edit_record)s:</label> <input type="text" name="recid" id="recid" /> <input type="submit" value="%(edit)s" class="adminbutton" /> </form> ''' % { 'edit': _('Edit'), 'edit_record': _('Edit record'), 'CFG_SITE_URL': CFG_SITE_URL, 'CFG_SITE_RECORD': CFG_SITE_RECORD } access = time.strftime('%Y%m%d_%H%M%S') if argd['recid'] and argd['do'] == 0: # Displaying interface to manage files # Prepare navtrail title, dummy_description, dummy_keywords = websearch_templates.tmpl_record_page_header_content( req, argd['recid'], argd['ln']) navtrail = '''<a class="navtrail" href="%(CFG_SITE_URL)s/help/admin">Admin Area</a> > <a class="navtrail" href="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/managedocfiles">%(manage_files)s</a> > %(record)s: %(title)s ''' \ % {'CFG_SITE_URL': CFG_SITE_URL, 'title': title, 'manage_files': _("Document File Manager"), 'record': _("Record #%(x_rec)i", x_rec=argd['recid']), 'CFG_SITE_RECORD': CFG_SITE_RECORD} body += create_file_upload_interface(\ recid=argd['recid'], ln=argd['ln'], uid=uid, sbm_access=access, display_hidden_files=True, restrictions_and_desc=CFG_BIBDOCFILE_DOCUMENT_FILE_MANAGER_RESTRICTIONS, doctypes_and_desc=CFG_BIBDOCFILE_DOCUMENT_FILE_MANAGER_DOCTYPES, **CFG_BIBDOCFILE_DOCUMENT_FILE_MANAGER_MISC)[1] body += '''<br /> <form method="post" action="%(CFG_SITE_URL)s/%(CFG_SITE_RECORD)s/managedocfiles"> <input type="hidden" name="recid" value="%(recid)s" /> <input type="hidden" name="do" value="1" /> <input type="hidden" name="access" value="%(access)s" /> <input type="hidden" name="ln" value="%(ln)s" /> <div style="font-size:small"> <input type="submit" name="cancel" value="%(cancel_changes)s" /> <input type="submit" onclick="user_must_confirm_before_leaving_page=false;return true;" class="adminbutton" name="submit" id="applyChanges" value="%(apply_changes)s" /> </div></form>''' % \ {'apply_changes': _("Apply changes"), 'cancel_changes': _("Cancel all changes"), 'recid': argd['recid'], 'access': access, 'ln': argd['ln'], 'CFG_SITE_URL': CFG_SITE_URL, 'CFG_SITE_RECORD': CFG_SITE_RECORD} body += websubmit_templates.tmpl_page_do_not_leave_submission_js( argd['ln'], enabled=True) return page(title = _("Document File Manager") + (argd['recid'] and (': ' + _("Record #%(x_rec)i", x_rec=argd['recid'])) or ''), navtrail=navtrail, navtrail_append_title_p=0, metaheaderadd = get_upload_file_interface_javascript(form_url_params='?access='+access) + \ get_upload_file_interface_css(), body = body, uid = uid, language=argd['ln'], req=req, navmenuid='admin')