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') websubmit_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 = "/youraccount/login" + make_canonical_urlargd( {"ln": argd["ln"], "referer": CFG_SITE_URL + user_info["uri"]}, {} ) return redirect_to_url(req, target) elif auth_code: return page_not_authorized( req, referer="/submit/managedocfiles", 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_TMPDIR, "websubmit_upload_interface_config_" + str(uid), argd["access"]) 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 #%i have been submitted") % argd["recid"] ) elif argd["cancel"]: # Clean temporary directory working_dir = os.path.join(CFG_TMPDIR, "websubmit_upload_interface_config_" + str(uid), argd["access"]) shutil.rmtree(working_dir) body += '<p style="color:#c00">%s</p>' % ( _("Your modifications to record #%i have been cancelled") % argd["recid"] ) if not argd["recid"] or argd["do"] != 0: body += """ <form method="post" action="%(CFG_SITE_URL)s/submit/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, } access = time.strftime("%Y%m%d_%H%M%S") if argd["recid"] and argd["do"] == 0: # Displaying interface to manage files # Prepare navtrail title, description, 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/submit/managedocfiles">%(manage_files)s</a> > %(record)s: %(title)s """ % { "CFG_SITE_URL": CFG_SITE_URL, "title": title, "manage_files": _("Document File Manager"), "record": _("Record #%i") % argd["recid"], } # FIXME: add parameters to `runbibdocfile' in order to # configure the file editor based on role, or at least # move configuration below to some config file. body += create_file_upload_interface( recid=argd["recid"], ln=argd["ln"], doctypes_and_desc=[ ("main", "Main document"), ("latex", "LaTeX"), ("source", "Source"), ("additional", "Additional File"), ("audio", "Audio file"), ("video", "Video file"), ("script", "Script"), ("data", "Data"), ("figure", "Figure"), ("schema", "Schema"), ("graph", "Graph"), ("image", "Image"), ("drawing", "Drawing"), ("slides", "Slides"), ], can_revise_doctypes=["*"], can_comment_doctypes=["*"], can_describe_doctypes=["*"], can_delete_doctypes=["*"], can_keep_doctypes=["*"], can_rename_doctypes=["*"], can_add_format_to_doctypes=["*"], can_restrict_doctypes=["*"], restrictions_and_desc=[("", "Public"), ("restricted", "Restricted")], uid=uid, sbm_access=access, display_hidden_files=True, )[1] body += """<br /> <form method="post" action="%(CFG_SITE_URL)s/submit/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, } body += websubmit_templates.tmpl_page_do_not_leave_submission_js(argd["ln"], enabled=True) return page( title=_("Document File Manager") + (argd["recid"] and (": " + _("Record #%i") % 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", )