]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
webish: implement delete (for files only, not directories)
authorBrian Warner <warner@lothar.com>
Tue, 5 Dec 2006 02:27:38 +0000 (19:27 -0700)
committerBrian Warner <warner@lothar.com>
Tue, 5 Dec 2006 02:27:38 +0000 (19:27 -0700)
allmydata/filetable.py
allmydata/vdrive.py
allmydata/web/directory.xhtml
allmydata/webish.py

index e93413c1717cd03f4047d5f0c7c2acf6af49d21a..bb96b02ad5804e5cff52131d26443cade3b1c4c9 100644 (file)
@@ -90,6 +90,7 @@ class MutableDirectoryNode(Referenceable):
             os.unlink(absname)
         else:
             raise BadFileError("Cannot delete non-existent file '%s'" % name)
+    remote_remove = remove
 
 
 class GlobalVirtualDrive(service.MultiService):
index c0eed1fb57ba6d0296f17b0523a4e176f8d439db..22e012d08888cdaaac74a4eb1e31aca2ecd30371 100644 (file)
@@ -106,8 +106,23 @@ class VDrive(service.MultiService):
         d.addCallback(lambda parent: parent.callRemote("add_directory", name))
         return d
 
-    def remove(self, something): # TODO
-        pass
+    def remove(self, parent, name):
+        assert not isinstance(parent, str)
+        log.msg("vdrive removing %s" % name)
+        # first find the verifierid
+        d = self.get_verifierid_from_parent(parent, name)
+        def _got_verifierid(vid):
+            # TODO: delete the file's shares using this
+            pass
+        d.addCallback(_got_verifierid)
+        def _delete_from_parent(res):
+            return parent.callRemote("remove", name)
+        d.addCallback(_delete_from_parent)
+        def _done(res):
+            log.msg("vdrive done removing %s" % name)
+        d.addCallback(_done)
+        return d
+
 
     def get_file(self, dir_and_name_or_path, download_target):
         """Retrieve a file from the virtual drive and put it somewhere.
index 47f8cd473b653eb4e24b39cdddbc508264cc8883..5b4d9c7aa27914fa33fb6235ab6e983c548c2760 100644 (file)
     <td>Filename</td>
     <td>Type</td>
     <td>fileid</td>
+    <td></td>
   </tr>
   <tr n:pattern="item" n:render="row">
     <td><n:slot name="filename"/></td>
     <td><n:slot name="type"/></td>
     <td><n:slot name="fileid"/></td>
+    <td><n:slot name="delete"/></td>
   </tr>
 
   <tr n:pattern="empty"><td>directory is empty!</td></tr>
index 43e5772acaf08d7f393d0b654e37056f9ec3cd73..4d41cbc06a60a048332810771efd5f1f118ef4d6 100644 (file)
@@ -86,11 +86,23 @@ class Directory(rend.Page):
             ctx.fillSlots("filename", T.a(href=dlurl)[name])
             ctx.fillSlots("type", "FILE")
             ctx.fillSlots("fileid", idlib.b2a(target))
+
+            # this creates a button which will cause our child__delete method
+            # to be invoked, which deletes the file and then redirects the
+            # browser back to this directory
+            del_url = url.here.child("_delete")
+            #del_url = del_url.add("verifierid", idlib.b2a(target))
+            del_url = del_url.add("name", name)
+            delete = T.form(action=del_url, method="post")[
+                T.input(type='submit', value='del', name="del"),
+                ]
+            ctx.fillSlots("delete", delete)
         else:
             # directory
             ctx.fillSlots("filename", T.a(href=name)[name])
             ctx.fillSlots("type", "DIR")
             ctx.fillSlots("fileid", "-")
+            ctx.fillSlots("delete", "-")
         return ctx.tag
 
     child_webform_css = webform.defaultCSS
@@ -153,6 +165,16 @@ class Directory(rend.Page):
         d.addCallback(_done)
         return d
 
+    def child__delete(self, ctx):
+        # perform the delete, then redirect back to the directory page
+        args = inevow.IRequest(ctx).args
+        vdrive = self._client.getServiceNamed("vdrive")
+        d = vdrive.remove(self._dirnode, args["name"][0])
+        def _deleted(res):
+            return url.here.up()
+        d.addCallback(_deleted)
+        return d
+
 class WebDownloadTarget:
     implements(IDownloadTarget)
     def __init__(self, req):