Changeset 1388
- Timestamp:
- 02/12/08 10:59:36 (9 months ago)
- Location:
- trunk/pylucid/PyLucid
- Files:
-
- 1 added
- 4 modified
-
plugins_internal/filemanager/filemanager.py (modified) (9 diffs)
-
plugins_internal/filemanager/filemanager_cfg.py (modified) (1 diff)
-
plugins_internal/filemanager/internal_pages/filelist.html (modified) (1 diff)
-
plugins_internal/filemanager/internal_pages/select_basepath.html (added)
-
settings_example.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/PyLucid/plugins_internal/filemanager/filemanager.py
r1387 r1388 34 34 from PyLucid.system.BasePlugin import PyLucidBasePlugin 35 35 36 37 ABS_PATH = os.path.abspath(settings.MEDIA_ROOT) 38 36 BASE_PATHS = [ 37 (str(no),path) for no,path in enumerate(settings.FILEMANAGER_BASEPATHS) 38 ] 39 BASE_PATHS_DICT = dict(BASE_PATHS) 39 40 40 41 def make_dirlist(path, result=[]): … … 72 73 73 74 class EditFileForm(forms.Form): 75 """ Edit a text file form """ 74 76 content = forms.CharField() 75 77 78 class SelectBasePathForm(forms.Form): 79 """ change the base path form """ 80 base_path = forms.ChoiceField(choices=BASE_PATHS) 76 81 77 82 78 83 class filemanager(PyLucidBasePlugin): 79 84 80 def getFilesList(self, rel_dir):85 def getFilesList(self, base_no, abs_path, rel_path): 81 86 """ 82 87 Returns all items in the given directory. … … 86 91 files = [] 87 92 88 if not rel_dir:93 if rel_path == ".": 89 94 # current dir it the media Root 90 95 dirs=[] 91 96 else: 92 97 # Add the ".." dir item 93 updir = os.path.split(rel_ dir)[0]98 updir = os.path.split(rel_path)[0] 94 99 dirs = [{ 95 100 "name": "..", 96 101 "link": self.URLs.methodLink( 97 method_name="filelist", args= updir102 method_name="filelist", args=(base_no, updir) 98 103 ), 99 104 "is_dir": True, … … 101 106 }] 102 107 103 # convert the relative path to absolute filesystem path 104 abs_fs_path=os.path.join(ABS_PATH, rel_dir) 105 106 if not abs_fs_path.startswith(ABS_PATH): 107 raise WrongDirectory(abs_fs_path) 108 109 link_prefix = self.URLs.methodLink(method_name="filelist") 110 111 for item in sorted(os.listdir(abs_fs_path)): 108 link_prefix = self.URLs.methodLink(method_name="filelist", args=base_no) 109 110 for item in sorted(os.listdir(abs_path)): 112 111 if item.startswith("."): 113 112 # skip hidden files or directories 114 113 continue 115 114 116 item_abs_fs_path = os.path.join(abs_fs_path, item)117 statinfo = os.stat( item_abs_fs_path)118 119 link = os.path.join(link_prefix, rel_ dir, item)115 abs_item_path = os.path.join(abs_path, item) 116 statinfo = os.stat(abs_item_path) 117 118 link = os.path.join(link_prefix, rel_path, item) 120 119 121 120 if stat.S_ISDIR(statinfo[stat.ST_MODE]): … … 130 129 "link": link, 131 130 "is_dir": is_dir, 132 "title": item_abs_fs_path,131 "title": abs_item_path, 133 132 "time": strftime("%Y:%m:%M",localtime(statinfo[stat.ST_MTIME])), 134 133 "size": statinfo[stat.ST_SIZE], … … 148 147 149 148 150 def make_dir_links(self, path): 151 """ 152 path: /data/one/two 153 154 return [('/data/one/two','two'), ('/data/one','one'),('/data','data')] 155 """ 149 def make_dir_links(self, base_no, base_path, abs_path, rel_path): 150 """ 151 Build the context for the path link line. 152 Use the function make_dirlist(). 153 """ 154 # self.page_msg("base_no:", base_no, "base_path:", base_path) 155 # self.page_msg("abs_path:", abs_path, "rel_path:", rel_path) 156 157 # start with the first base_path entry: 156 158 dir_links = [{ 157 # Display only the short relative path: 158 "name": os.path.normpath(settings.MEDIA_ROOT), 159 "title": ABS_PATH, 160 "link": self.URLs.methodLink(method_name="filelist"), 159 "name": base_path, # use only the short relative path 160 "title": abs_path, 161 "link": self.URLs.methodLink(method_name="filelist", args=base_no), 161 162 }] 162 if path:163 if rel_path != ".": 163 164 # Not in the root 164 dirlist = make_dirlist( path, [])165 dirlist = make_dirlist(rel_path, []) 165 166 for path, name in dirlist: 167 # append every dir "steps" 166 168 dir_links.append({ 167 169 "name": name, 168 "title": os.path.join( ABS_PATH, path),170 "title": os.path.join(base_path, path), 169 171 "link": self.URLs.methodLink( 170 method_name="filelist", args= path172 method_name="filelist", args=(base_no, path) 171 173 ), 172 174 }) … … 201 203 202 204 if self.request.method == 'POST': 203 form = EditFileForm( request.POST)205 form = EditFileForm(self.request.POST) 204 206 if form.is_valid(): 205 207 self.page_msg("Net implemented yet!!!") … … 297 299 self._render_template("userinfo", context)#, debug=True) 298 300 299 def filelist(self, rest=''): 301 def select_basepath(self): 302 """ 303 change the basepath, after send the form, we display the filelist 304 """ 305 # self.page_msg(self.request.POST) 306 307 if self.request.method == 'POST': 308 form = SelectBasePathForm(self.request.POST) 309 if form.is_valid(): 310 path_no = form.cleaned_data["base_path"] 311 new_path = BASE_PATHS_DICT[path_no] 312 if not os.path.isdir(new_path): 313 self.page_msg.red("Error: Path '%s' doesn't exist" % new_path) 314 else: 315 self.page_msg("changed to '%s'." % new_path) 316 # Display the filelist: 317 return self.filelist(path_no + "/") 318 else: 319 form = SelectBasePathForm() 320 321 self._render_template("select_basepath", {"form": form})#, debug=True) 322 323 324 def filelist(self, path_info=None): 300 325 """ 301 326 List dir and file. Some actions. 302 327 rest: path to dir or file 303 328 """ 329 if not path_info: 330 self.select_basepath() 331 return 332 333 # try: 334 base_no, rel_path = path_info.split("/", 1) 335 rel_path = os.path.normpath(rel_path) 336 base_path = os.path.normpath(BASE_PATHS_DICT[base_no]) 337 # except Exception, e: 338 # self.page_msg.red("Path error:", e) 339 # return 340 341 abs_base_path = os.path.abspath(base_path) 342 343 # self.page_msg("base_no:", base_no, "base_path:", base_path) 344 # self.page_msg("abs_base_path:", abs_base_path, "rel_path:", rel_path) 345 304 346 # Change the global page title: 305 347 self.context["PAGE"].title = _("File list") 306 context = {}307 dir_list = []308 files_list = []309 310 dir_string=''311 312 if rest!='':313 # self.page_msg("rest:", rest)314 dir_string=os.path.normpath(rest)315 348 316 349 if self.request.method == 'POST': 317 350 # self.page_msg(self.request.POST) 318 dir_string=os.path.normpath(self.request.POST['dir_string'])351 # dir_string=os.path.normpath(self.request.POST['dir_string']) 319 352 320 353 if self.request.has_key('action'): … … 349 382 ) 350 383 351 abs_path = os.path.join(ABS_PATH, dir_string) 352 353 # self.page_msg("read dir '%s'" % dir_string) 354 dir_list = self.getFilesList(dir_string) 384 abs_path = os.path.normpath(os.path.join(abs_base_path, rel_path)) 385 if not os.path.isdir(abs_path): 386 self.page_msg.red("Error: Path '%s' doesn't exist" % abs_path) 387 return 388 389 # build the directory+file list: 390 dir_list = self.getFilesList(base_no, abs_path, rel_path) 391 392 # Build the path link line: 393 dir_links = self.make_dir_links(base_no, base_path, abs_path, rel_path) 355 394 356 395 context = { 357 396 "url": self.URLs.methodLink("filelist"), 358 "dir": dir_string,359 "dir_links": self.make_dir_links(dir_string),397 "dir": rel_path, 398 "dir_links": dir_links, 360 399 "writeable": os.access(abs_path, os.W_OK), 361 400 "dir_list": dir_list, 362 "abs_path": ABS_PATH,401 "abs_path": abs_path, 363 402 "messages": self.page_msg, 364 403 "userinfo_link": self.URLs.methodLink( 365 method_name="userinfo", args= dir_string404 method_name="userinfo", args=rel_path 366 405 ), 367 406 "edit_link": self.URLs.methodLink( 368 method_name="edit", args=dir_string 407 method_name="edit", args=rel_path 408 ), 409 "change_basepath_link": self.URLs.methodLink( 410 method_name="select_basepath" 369 411 ), 370 412 } -
trunk/pylucid/PyLucid/plugins_internal/filemanager/filemanager_cfg.py
r1387 r1388 36 36 }, 37 37 }, 38 "select_basepath": { 39 "must_login" : True, 40 "must_admin" : True, 41 "internal_page_info" : { 42 "name" : "select_basepath", 43 "description" : "Select a base path (set in settings.py)", 44 "markup" : None 45 }, 46 }, 38 47 "edit": { 39 48 "must_login" : True, -
trunk/pylucid/PyLucid/plugins_internal/filemanager/internal_pages/filelist.html
r1387 r1388 2 2 {% for dir in dir_links %}<a href="{{ dir.link }}" title="{{ dir.title }}">{{ dir.name }}</a>/{% endfor %} 3 3 </legend> 4 5 <p><a href="{{ change_basepath_link }}">{% trans 'change basepath' %}</a></p> 4 6 5 7 <table summary="Directory Listing" cellpadding="0" cellspacing="0"> -
trunk/pylucid/PyLucid/settings_example.py
r1340 r1388 189 189 # Examples-3: "http://django.media.your_domain.net/" 190 190 ADMIN_MEDIA_PREFIX = "/django/contrib/admin/media/" 191 192 # Base path for the filemanager plugin 193 # You can add more path for the plugin. 194 FILEMANAGER_BASEPATHS = ( 195 MEDIA_ROOT, 196 #"./static/", 197 ) 191 198 192 199 """
