예제 #1
0
파일: formgen.py 프로젝트: espenak/enkel
    def handle_field_body(self, prefix, fieldname, field, value, uvalue, meta, display):
        commonattr = dict(name=prefix + fieldname, id=prefix + fieldname)

        readonly = display.get("readonly")
        if readonly:
            if isinstance(field, ds.DatasourceField):
                raise ValueError("%s: DatasourceField cannot be readonly." % fieldname)
            commonattr["disabled"] = "disabled"

        if isinstance(field, ds.DatasourceField):
            datasource = field.datasource

            size = 0
            opt = XmlWriter(oldhtmlcomp=self.oldhtmlcomp, pretty=self.pretty)
            for uval, label in datasource.ds_iter_unicode():
                attr = {}
                if (isinstance(field, ds.Many) and uval in uvalue) or (isinstance(field, ds.One) and uval == uvalue):
                    attr["selected"] = "selected"

                attr["value"] = uval
                opt.start_element("option", **attr)
                opt.text_node(label)
                opt.end_element()
                size += 1

            attr = commonattr.copy()
            if isinstance(field, ds.Many):
                attr["multiple"] = "multiple"
            if size > 10:
                size = 10
            self.w.start_element("select", size=str(size), **attr)
            self.w.raw_node(opt.create())
            self.w.end_element()

        else:
            if isinstance(field, String):
                maxlength = field.maxlength
                if maxlength > 50:
                    self.w.start_element("textarea", cols="70", rows="3", **commonattr)
                    self.w.text_node(uvalue)
                    self.w.end_element()
                else:
                    self.w.empty_element("input", type="text", maxlength=str(maxlength), value=uvalue, **commonattr)

            elif isinstance(field, Text):
                self.w.start_element("textarea", cols="70", rows="12", **commonattr)
                self.w.text_node(uvalue)
                self.w.end_element()

            elif isinstance(field, Bool):
                attr = commonattr.copy()
                if value == True:
                    attr["checked"] = "checked"
                self.w.empty_element("input", type="checkbox", value="yes", **attr)

            else:
                self.w.empty_element("input", type="text", value=uvalue, **commonattr)
예제 #2
0
파일: writer.py 프로젝트: espenak/enkel
	def setUp(self):
		w = XmlWriter()

		w.pi("xml", version="1.0")
		w.pi_raw("pros", "shit")
		w.start_element("html")
		w.start_element("body")
		w.text_node(u"\u00e5ge")
		w.empty_element("div", attrdict={"class":"test"})
		w.end_element(2)
		self.w = w
		self.b = w.create()
예제 #3
0
파일: writer.py 프로젝트: espenak/enkel
    def setUp(self):
        w = XmlWriter()

        w.pi("xml", version="1.0")
        w.pi_raw("pros", "shit")
        w.start_element("html")
        w.start_element("body")
        w.text_node(u"\u00e5ge")
        w.empty_element("div", attrdict={"class": "test"})
        w.end_element(2)
        self.w = w
        self.b = w.create()
예제 #4
0
파일: edit.py 프로젝트: espenak/enkel
	def save(self):
		manip = forminput_to_manip(self.MODEL, FormInput(self.env), "e_")
		try:
			manip.validate()
		except base.FieldValidationError:
			self._create_edit_form(manip, validate=True)
		else:
			p = XmlWriter(pretty=True)
			p.pi("xml", version="1.0", encoding=ENCODING)
			p.start_element("post", xmlns=XMLNS_STATICBLOG)

			p.start_element("summary")
			p.text_node(manip.summary)
			p.end_element()

			for tag in manip.tags.split(","):
				p.start_element("tag")
				p.text_node(tag.strip())
				p.end_element()

			p.start_element("section", xmlns=XMLNS_MARKUP,
					attrdict={"xmlns:s": XMLNS_STATICBLOG})
			p.start_element("h")
			p.text_node(manip.heading)
			p.end_element()
			p.raw_node(manip.post)
			p.end_element()

			p.end_element() # </post>

			path = join(self.posts_folder, manip.id)

			post = self.UNIVERSAL_NEWLINE_PATT.sub(r"\n", p.create())
			codecs.open(path, "wb", ENCODING).write(post)

			self.w.start_element("p")
			self.w.text_node(N_("Save successful"))
			self.w.end_element()
예제 #5
0
파일: formgen.py 프로젝트: espenak/enkel
	def handle_field_body(self, prefix, fieldname, field, value,
				uvalue, meta, display):
		commonattr = dict(name=prefix+fieldname, id=prefix+fieldname)

		readonly = display.get("readonly")
		if readonly:
			if isinstance(field, ds.DatasourceField):
				raise ValueError(
					"%s: DatasourceField cannot be readonly." % fieldname)
			commonattr["disabled"] = "disabled"

		if isinstance(field, ds.DatasourceField):
			datasource = field.datasource

			size = 0
			opt = XmlWriter(oldhtmlcomp=self.oldhtmlcomp,
					pretty=self.pretty)
			for uval, label in datasource.ds_iter_unicode():
				attr = {}
				if \
						(isinstance(field, ds.Many) and\
							uval in uvalue) or\
						(isinstance(field, ds.One) and\
							uval == uvalue):
					attr["selected"] = "selected"

				attr["value"] = uval
				opt.start_element("option", **attr)
				opt.text_node(label)
				opt.end_element()
				size += 1

			attr = commonattr.copy()
			if isinstance(field, ds.Many):
				attr["multiple"] = "multiple"
			if size > 10:
				size = 10
			self.w.start_element("select", size=str(size), **attr)
			self.w.raw_node(opt.create())
			self.w.end_element()


		else:
			if isinstance(field, String):
				maxlength = field.maxlength
				if maxlength > 50:
					self.w.start_element("textarea", cols="70", rows="3",
							**commonattr)
					self.w.text_node(uvalue)
					self.w.end_element()
				else:
					self.w.empty_element("input",
							type = "text",
							maxlength = str(maxlength),
							value = uvalue,
							**commonattr)

			elif isinstance(field, Text):
				self.w.start_element("textarea", cols="70", rows="12",
						**commonattr)
				self.w.text_node(uvalue)
				self.w.end_element()

			elif isinstance(field, Bool):
				attr = commonattr.copy()
				if value == True:
					attr["checked"] = "checked"
				self.w.empty_element("input",
						type = "checkbox",
						value = "yes",
						**attr)

			else:
				self.w.empty_element("input",
						type = "text",
						value = uvalue,
						**commonattr)