Changeset 1408
- Timestamp:
- 02/14/08 10:52:20 (9 months ago)
- Location:
- trunk/pylucid/PyLucid/plugins_internal/filemanager
- Files:
-
- 3 modified
-
filemanager.py (modified) (28 diffs)
-
internal_pages/filelist.css (modified) (1 diff)
-
internal_pages/filelist.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/pylucid/PyLucid/plugins_internal/filemanager/filemanager.py
r1407 r1408 1 1 #!/usr/bin/python 2 2 # -*- coding: UTF-8 -*- 3 4 3 5 4 """ … … 48 47 __version__= "$Rev: $" 49 48 50 import os, cgi, sys, stat 51 from time import localtime, strftime49 import os, cgi, sys, stat, dircache 50 from datetime import datetime 52 51 53 52 from django.http import Http404 … … 60 59 from PyLucid.system.BasePlugin import PyLucidBasePlugin 61 60 62 # ----------------------------------------------------------------------------- 61 #______________________________________________________________________________ 62 # Build a list and a dict from the basepaths 63 # The dict key is a string, not a integer. (GET/POST Data always returned 64 # numbers as strings) 63 65 64 66 BASE_PATHS = [ … … 67 69 BASE_PATHS_DICT = dict(BASE_PATHS) 68 70 69 # -----------------------------------------------------------------------------71 #______________________________________________________________________________ 70 72 # We use more than one html form in a filelist page. So we need some unique 71 73 # action values for a easier distinguish the POST data. … … 75 77 ACTION_DELETEFILE = "3" 76 78 77 # -----------------------------------------------------------------------------79 #______________________________________________________________________________ 78 80 79 81 def make_dirlist(path, result=[]): 80 82 """ 83 Helper function for building a directory link line. 84 used in filemanager.make_dir_links() 85 81 86 >>> make_dirlist("/data/one/two") 82 87 [('data/one/two', 'two'), ('data/one', 'one'), ('data', 'data')] … … 94 99 return result 95 100 96 # -----------------------------------------------------------------------------97 98 BAD_DIR_CHARS = ("..", "//", "\\") 99 BAD_FILE_CHARS = ("..", "/", "\\") 101 #______________________________________________________________________________ 102 103 BAD_DIR_CHARS = ("..", "//", "\\") # Bad characters in directories 104 BAD_FILE_CHARS = ("..", "/", "\\") # Bad characters in a filename 100 105 101 106 def contains_char(text, chars): … … 133 138 class DirnameField(BadCharField): 134 139 """ 135 Verify a dirname140 newforms field for verify a dirname. 136 141 """ 137 142 bad_chars = BAD_DIR_CHARS … … 139 144 class FilenameField(BadCharField): 140 145 """ 141 Verify a filename146 newforms field for verify a filename. 142 147 """ 143 148 bad_chars = BAD_FILE_CHARS 144 149 145 # -----------------------------------------------------------------------------150 #______________________________________________________________________________ 146 151 147 152 class EditFileForm(forms.Form): 148 153 """ Edit a text file form """ 149 154 filename = FilenameField( 150 help_text="Change the filename, if you want to save the content into a new file." 155 help_text=_( 156 u"Change the filename," 157 " if you want to save the content into a new file." 158 ) 151 159 ) 152 160 content = forms.CharField( … … 158 166 base_path = forms.ChoiceField(choices=BASE_PATHS) 159 167 160 # -----------------------------------------------------------------------------168 #______________________________________________________________________________ 161 169 162 170 class ActionField(forms.CharField): … … 181 189 return value 182 190 183 # -----------------------------------------------------------------------------191 #______________________________________________________________________________ 184 192 185 193 class CreateDirForm(forms.Form): … … 218 226 item_name = FilenameField() 219 227 220 # -----------------------------------------------------------------------------228 #______________________________________________________________________________ 221 229 222 230 class Path(dict): 223 231 """ 224 Analyse, check and store the html GET path information. 232 Helper class for analyse, check and store the html GET path information. 233 Used in filemanager() 225 234 226 235 base_no = BASE_PATHS_DICT key (Note: it's a String!) … … 273 282 raise Http404(_("Error: Path '%s' doesn't exist.") % abs_path) 274 283 275 # self.page_msg("base_no:", base_no, "base_path:", base_path)276 # self.page_msg("abs_base_path:", abs_base_path, "rel_path:", rel_path)277 278 284 self["base_no"] = base_no 279 285 self["base_path"] = base_path … … 304 310 self["abs_file_path"] = abs_file_path 305 311 306 # __________________________________________________________________________312 #-------------------------------------------------------------------------- 307 313 308 314 def get_abs_link(self, item=""): … … 312 318 return os.path.join("/", self["base_path"], self["rel_path"], item) 313 319 314 # __________________________________________________________________________320 #-------------------------------------------------------------------------- 315 321 316 322 def debug(self): … … 322 328 self.page_msg(" - %15s: '%s'" % (k,v)) 323 329 324 # -----------------------------------------------------------------------------330 #______________________________________________________________________________ 325 331 326 332 class filemanager(PyLucidBasePlugin): 327 333 """ 334 The PyLucid plugin class. 335 """ 328 336 def __init__(self, context, response): 329 337 super(filemanager, self).__init__(context, response) 330 338 self.path = Path(context) 331 339 332 # __________________________________________________________________________340 #-------------------------------------------------------------------------- 333 341 334 342 def get_filelist(self): … … 341 349 342 350 if self.path["rel_path"] == "": 343 # current dir i t the media Root351 # current dir is the media root 344 352 dirs=[] 345 353 else: … … 367 375 statinfo = os.stat(abs_item_path) 368 376 369 if stat.S_ISDIR(statinfo [stat.ST_MODE]):377 if stat.S_ISDIR(statinfo.st_mode): 370 378 # Is a directory 371 379 is_dir = True 372 380 link = os.path.join(link_prefix, item) + "/" 381 size = len(dircache.listdir( 382 os.path.join(self.path["abs_path"], item) 383 ))-1 373 384 else: 374 385 is_dir = False 375 386 link = self.path.get_abs_link(item) 387 size = statinfo.st_size 388 389 print item, datetime.fromtimestamp(statinfo.st_mtime) 376 390 377 391 item_dict={ … … 380 394 "is_dir": is_dir, 381 395 "title": abs_item_path, 382 "time": strftime("%Y:%m:%M",localtime(statinfo[stat.ST_MTIME])),383 "size": s tatinfo[stat.ST_SIZE],384 "mode": statinfo [stat.ST_MODE],385 "uid": statinfo [stat.ST_UID],386 "gid": statinfo [stat.ST_GID],396 "time": datetime.fromtimestamp(statinfo.st_mtime), 397 "size": size, 398 "mode": statinfo.st_mode, 399 "uid": statinfo.st_uid, 400 "gid": statinfo.st_gid, 387 401 "deletable": True, 388 402 } … … 426 440 return dir_links 427 441 428 # __________________________________________________________________________442 #-------------------------------------------------------------------------- 429 443 # html GET actions: 430 444 … … 476 490 form_link += self.path["filename"] 477 491 492 file_path = self.path.get_abs_link() 493 494 # Change the global page title: 495 self.context["PAGE"].title = _("Edit file - %s" % file_path) 496 478 497 context = { 479 498 "form_link": form_link, … … 481 500 method_name="filelist", args=self.path["url_path"] 482 501 ), 483 "file_path": self.path.get_abs_link(),502 "file_path": file_path, 484 503 "filename": self.path["filename"], 485 504 "form": form, … … 488 507 self._render_template("edit_file", context)#, debug=True) 489 508 490 # __________________________________________________________________________509 #-------------------------------------------------------------------------- 491 510 # html POST actions: 492 511 … … 541 560 self.page_msg.green("File '%s' deleted successfull." % filename) 542 561 543 # __________________________________________________________________________562 #-------------------------------------------------------------------------- 544 563 545 564 def userinfo(self, old_path=""): … … 547 566 Display some user information related to the filemanager functionality. 548 567 """ 568 # Change the global page title: 569 self.context["PAGE"].title = _( 570 "Filemanager - Display some user information" 571 ) 572 549 573 import pwd, grp 550 574 … … 571 595 change the basepath, after send the form, we display the filelist 572 596 """ 597 # Change the global page title: 598 self.context["PAGE"].title = _("Filemanager - Change the basepath") 573 599 # self.page_msg(self.request.POST) 574 600 … … 579 605 new_path = BASE_PATHS_DICT[path_no] 580 606 if not os.path.isdir(new_path): 581 self.page_msg.red("Error: Path '%s' doesn't exist" % new_path) 607 self.page_msg.red( 608 "Error: Path '%s' doesn't exist" % new_path 609 ) 582 610 else: 583 self.page_msg("change dto '%s'." % new_path)611 self.page_msg("change base path to '%s'." % new_path) 584 612 # Display the filelist: 585 613 return self.filelist(path_no + "/") … … 589 617 self._render_template("select_basepath", {"form": form})#, debug=True) 590 618 591 # __________________________________________________________________________619 #-------------------------------------------------------------------------- 592 620 593 621 def filelist(self, path_info=None): … … 605 633 606 634 # Change the global page title: 607 self.context["PAGE"].title = _("File list - %s" % self.path["rel_path"]) 635 path = os.path.join(self.path["base_path"], self.path["rel_path"]) 636 self.context["PAGE"].title = _("File list - %s" % path) 608 637 609 638 # We init all forms before we check the POST, because we only need -
trunk/pylucid/PyLucid/plugins_internal/filemanager/internal_pages/filelist.css
r1407 r1408 56 56 float:left; 57 57 } 58 .filemanager . o, .filemanager .u, .filemanager .g {59 /* mode + uid + gid */58 .filemanager .s, .filemanager .m, .filemanager .o, .filemanager .u, .filemanager .g { 59 /* size + mtime + mode + uid + gid */ 60 60 font-size:0.8em; 61 61 font-weight:lighter; -
trunk/pylucid/PyLucid/plugins_internal/filemanager/internal_pages/filelist.html
r1407 r1408 24 24 </td> 25 25 {% if item.is_dir %} 26 <td class="s"><i><dir></i></td> 26 <td class="s"> 27 {% if item.size %} 28 <i>{{ item.size }} object{{ item.size|pluralize }}</i> 29 {% endif %} 30 </td> 27 31 {% else %} 28 32 <td class="s">{{ item.size|filesizeformat }}</td> 29 33 {% endif %} 30 <td class="m">{{ item.time }}</td>34 <td class="m">{{ item.time|date:_("DATE_WITH_TIME_FULL") }}</td> 31 35 <td class="o" title="octal mode: {{ item.mode|get_oct }}">{{ item.mode|chmod_symbol }}</td> 32 36 <td class="u">{{ item.uid }}</td>
