def test_generate_entry(self): # generate_entry takes local time, and we test the resulting # rfc822date which is UTC. Result depends on time zone. self.__force_tz() e = generate_entry(req_(), {"foo": "bar"}, "entry body", TIME1) self.__restore_tz() self.eq_(e["foo"], "bar") self.eq_(e["body"], "entry body") self.eq_(e["rfc822date"], "Mon, 21 Jul 2008 16:51 GMT") e = generate_entry(req_(), {"foo": "bar"}, "entry body")
def handle_registry_submit(args): """ Handles showing the new entry form, editing entries, and submitting new entries. """ global SUBMITTRIGGER request = args["request"] pyhttp = request.getHttp() if not pyhttp["PATH_INFO"].startswith(SUBMITTRIGGER): return config = request.getConfiguration() form = pyhttp["form"] data = request.getData() ending = config.get("registryentryending", ".regdat") if readonly(config): output = "<p>This registry is read-only--you are not allowed to " + \ "submit new entries or edit existing ones.</p>" return [generate_entry(request, output, "error")] # if they didn't post, then they're looking for the form if not pyhttp["REQUEST_METHOD"] == "POST": d = {} if form.getvalue("edit"): d = load_values(config["registry_dir"] + form.getvalue("edit") + ending, item) d["title"] = "editing " + form.getvalue("edit") else: d["title"] = "submit new entry" if form.has_key("useform"): d["template_name"] = form["useform"].value else: d["template_name"] = "registry-form" d["nocomments"] = "true" return [base.generate_entry(request, d, "", None)] # we pick up all the data pieces here and fix them up name = "" body = "" category = "" props = {} for mem in form.keys(): if mem == "name": name = form.getvalue(mem) continue if mem == "description": body = form.getvalue(mem) continue if mem == "category": category = form.getvalue(mem) continue props[mem] = form.getvalue(mem) text = name + "\n" for mem in props.keys(): text += "#%s %s\n" % (mem, props[mem]) text = text + body filename = name filename = [mem for mem in filename if mem in string.ascii_letters] filename = "".join(filename) filename = config["registry_dir"] + os.sep + category + os.sep + filename + ".txt-" if os.path.isfile(filename): # ERROR - we already have this file. at the present time # we DON'T over-write it, we just tell the user we've already # got one. output = "<p>There's already a pending submission for that item.</p>" return [generate_entry(request, output, "error")] # write the file to the filesystem.... f = open(filename, "w") f.write(text) f.close() # give them a pretty message output = """ <p> Submission was received. It may take a couple of days to verify the information and add the entry. This is the data you provided us: </p> <pre>%s</pre>""" % text return [generate_entry(request, output, "success!")]
def handle_registry_submit(args): """ Handles showing the new entry form, editing entries, and submitting new entries. """ global SUBMITTRIGGER request = args["request"] pyhttp = request.getHttp() if not pyhttp["PATH_INFO"].startswith(SUBMITTRIGGER): return config = request.getConfiguration() form = pyhttp["form"] data = request.getData() ending = config.get("registryentryending", ".regdat") if readonly(config): output = "<p>This registry is read-only--you are not allowed to " + \ "submit new entries or edit existing ones.</p>" return [generate_entry(request, output, "error")] # if they didn't post, then they're looking for the form if not pyhttp["REQUEST_METHOD"] == "POST": d = {} if form.getvalue("edit"): d = load_values( config["registry_dir"] + form.getvalue("edit") + ending, item) d["title"] = "editing " + form.getvalue("edit") else: d["title"] = "submit new entry" if form.has_key("useform"): d["template_name"] = form["useform"].value else: d["template_name"] = "registry-form" d["nocomments"] = "true" return [base.generate_entry(request, d, "", None)] # we pick up all the data pieces here and fix them up name = "" body = "" category = "" props = {} for mem in form.keys(): if mem == "name": name = form.getvalue(mem) continue if mem == "description": body = form.getvalue(mem) continue if mem == "category": category = form.getvalue(mem) continue props[mem] = form.getvalue(mem) text = name + "\n" for mem in props.keys(): text += "#%s %s\n" % (mem, props[mem]) text = text + body filename = name filename = [mem for mem in filename if mem in string.ascii_letters] filename = "".join(filename) filename = config[ "registry_dir"] + os.sep + category + os.sep + filename + ".txt-" if os.path.isfile(filename): # ERROR - we already have this file. at the present time # we DON'T over-write it, we just tell the user we've already # got one. output = "<p>There's already a pending submission for that item.</p>" return [generate_entry(request, output, "error")] # write the file to the filesystem.... f = open(filename, "w") f.write(text) f.close() # give them a pretty message output = """ <p> Submission was received. It may take a couple of days to verify the information and add the entry. This is the data you provided us: </p> <pre>%s</pre>""" % text return [generate_entry(request, output, "success!")]