d.addBoth(self.shouldRedirect, None, statuscode='303')
return d
+ def test_welcome_page_mkdir_button(self):
+ # Fetch the welcome page.
+ d = self.GET("/")
+ def _after_get_welcome_page(res):
+ MKDIR_BUTTON_RE=re.compile('<form action="([^"]*)" method="post".*<input type="hidden" name="t" value="([^"]*)" /><input type="hidden" name="([^"]*)" value="([^"]*)" /><input type="submit" value="create" />', re.I)
+ mo = MKDIR_BUTTON_RE.search(res)
+ formaction = mo.group(1)
+ formt = mo.group(2)
+ formaname = mo.group(3)
+ formavalue = mo.group(4)
+ return (formaction, formt, formaname, formavalue)
+ d.addCallback(_after_get_welcome_page)
+ def _after_parse_form(res):
+ (formaction, formt, formaname, formavalue) = res
+ return self.POST("/%s?t=%s&%s=%s" % (formaction, formt, formaname, formavalue))
+ d.addCallback(_after_parse_form)
+ d.addBoth(self.shouldRedirect, None, statuscode='303')
+ return d
+
def test_POST_mkdir_replace(self): # return value?
d = self.POST(self.public_url + "/foo", t="mkdir", name="sub")
d.addCallback(lambda res: self._foo_node.get("sub"))
return d
if t == "mkdir":
- # "PUT /uri?t=mkdir", to create an unlinked directory.
+ # "POST /uri?t=mkdir", to create an unlinked directory.
d = IClient(ctx).create_empty_dirnode()
redirect = req.args.has_key("redirect_to_result") and boolean_of_arg(req.args["redirect_to_result"][0])
if redirect:
return T.p["personal vdrive not available."]
# this is a form where users can download files by URI
-
def render_download_form(self, ctx, data):
form = T.form(action="uri", method="get",
enctype="multipart/form-data")[
T.fieldset[
- T.legend(class_="freeform-form-label")["Download a file"],
+ T.legend(class_="freeform-form-label")["download a file"],
"URI of file to download: ",
T.input(type="text", name="uri"), " ",
"Filename to download as: ",
T.input(type="text", name="filename"), " ",
- T.input(type="submit", value="Download"),
+ T.input(type="submit", value="download"),
+ ]]
+ return T.div[form]
+
+ # this is a form where users can create new directories
+ def render_mkdir_form(self, ctx, data):
+ form = T.form(action="uri", method="post",
+ enctype="multipart/form-data")[
+ T.fieldset[
+ T.legend(class_="freeform-form-label")["create a directory"],
+ T.input(type="hidden", name="t", value="mkdir"),
+ T.input(type="hidden", name="redirect_to_result", value="true"),
+ T.input(type="submit", value="create"),
]]
return T.div[form]