Ejemplo n.º 1
0
    def __call__(self, env, start_response):
        """
		env["enkel.reuse.admin.stylesheet"] must contain the
		URL to the XSLT stylesheet.
		"""

        path = env["SCRIPT_NAME"] + env["PATH_INFO"]
        appid = None
        if not path.endswith("start/"):
            match = self.patt.match(path)
            if match:
                appid, action = match.groups()
                app, label, args, kw = self.apps[appid]
            else:
                raise Http404()

        w = XmlWriter(pretty=self.pretty)
        w.pi("xml", version="1.0", encoding=self.encoding)
        w.pi("xml-stylesheet", type="text/xsl", href=self.stylesheet)
        w.start_element("admin", xmlns=XMLNS_ADMIN)
        w.raw_node(self.applist_xml)

        if appid:
            w.empty_element("selected", app=appid, action=action)
        w.start_element("section", xmlns=XMLNS_MARKUP)
        if appid:
            app(env, w, appid, action, label, *args, **kw)
        else:
            self.startpage(env, w)
        w.end_element()

        start_response(
            "200 OK",
            [("content-type", "text/xml; charset=%s" % self.encoding)])
        yield w.create().encode(self.encoding)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
	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()
Ejemplo n.º 4
0
    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()
Ejemplo n.º 5
0
	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()
Ejemplo n.º 6
0
	def __call__(self, env, start_response):
		"""
		env["enkel.reuse.admin.stylesheet"] must contain the
		URL to the XSLT stylesheet.
		"""

		path = env["SCRIPT_NAME"] + env["PATH_INFO"]
		appid = None
		if not path.endswith("start/"):
			match = self.patt.match(path)
			if match:
				appid, action = match.groups()
				app, label, args, kw = self.apps[appid]
			else:
				raise Http404()


		w = XmlWriter(pretty=self.pretty)
		w.pi("xml", version="1.0", encoding=self.encoding)
		w.pi("xml-stylesheet", type="text/xsl", href=self.stylesheet)
		w.start_element("admin", xmlns=XMLNS_ADMIN)
		w.raw_node(self.applist_xml)

		if appid:
			w.empty_element("selected", app=appid, action=action)
		w.start_element("section", xmlns=XMLNS_MARKUP)
		if appid:
			app(env, w, appid, action, label, *args, **kw)
		else:
			self.startpage(env, w)
		w.end_element()

		start_response("200 OK", [
			("content-type", "text/xml; charset=%s" % self.encoding)
		])
		yield w.create().encode(self.encoding)
Ejemplo n.º 7
0
def preprocess(postlist_filename, taglist_filename, posts_folder):
    """ Create a xml-file containing listing all the posts in the cms
	and a file containing all the tags is the cms.

	The format of the file output-files are defined in
	relax-ng/posts.rng and relax-ng/tags.rng.

	@param postlist_filename: The file where the post info is written.
	@param taglist_filename: The file where the tag info is written.
	@param posts_folder: The folder containing all the post-files.
	"""
    tags = {}
    w = XmlWriter(pretty=True)

    w.start_element("posts")
    for post_id in listdir(posts_folder):
        path = join(posts_folder, post_id)
        w.empty_element("post",
                        id=str(post_id),
                        src=abspath(path),
                        mtime=strftime("%Y-%m-%d %H:%M",
                                       gmtime(getmtime(path))))

        parser = make_parser()
        parser.setContentHandler(PostHandler(post_id, tags))
        parser.parse(path)
    w.end_element()

    # write post list
    postslist = w.create().encode("utf-8")
    log.debug("%s: %s" % (postlist_filename, postslist))
    open(postlist_filename, "wb").write(postslist)

    # write tag list
    w = XmlWriter(pretty=True)
    w.start_element("tags")
    for tag_id in tags:
        tag_name, posts = tags[tag_id]
        w.start_element("tag", id=tag_id, name=tag_name)
        for post_id in posts:
            path = abspath(join(posts_folder, post_id))
            w.empty_element("post",
                            id=post_id,
                            src=path,
                            mtime=strftime("%Y-%m-%d %H:%M",
                                           gmtime(getmtime(path))))
        w.end_element()
    w.end_element()
    taglist = w.create().encode("utf-8")
    log.debug("%s: %s" % (taglist_filename, taglist))
    open(taglist_filename, "wb").write(taglist)
Ejemplo n.º 8
0
def preprocess(postlist_filename, taglist_filename, posts_folder):
	""" Create a xml-file containing listing all the posts in the cms
	and a file containing all the tags is the cms.

	The format of the file output-files are defined in
	relax-ng/posts.rng and relax-ng/tags.rng.

	@param postlist_filename: The file where the post info is written.
	@param taglist_filename: The file where the tag info is written.
	@param posts_folder: The folder containing all the post-files.
	"""
	tags = {}
	w = XmlWriter(pretty=True)

	w.start_element("posts")
	for post_id in listdir(posts_folder):
		path = join(posts_folder, post_id)
		w.empty_element("post",
			id = str(post_id),
			src = abspath(path),
			mtime = strftime("%Y-%m-%d %H:%M", gmtime(getmtime(path)))
		)

		parser = make_parser()
		parser.setContentHandler(PostHandler(post_id, tags))
		parser.parse(path)
	w.end_element()

	# write post list
	postslist = w.create().encode("utf-8")
	log.debug("%s: %s" % (postlist_filename, postslist))
	open(postlist_filename, "wb").write(postslist)

	# write tag list
	w = XmlWriter(pretty=True)
	w.start_element("tags")
	for tag_id in tags:
		tag_name, posts = tags[tag_id]
		w.start_element("tag", id=tag_id, name=tag_name)
		for post_id in posts:
			path = abspath(join(posts_folder, post_id))
			w.empty_element("post",
				id = post_id,
				src = path,
				mtime = strftime("%Y-%m-%d %H:%M", gmtime(getmtime(path)))
			)
		w.end_element()
	w.end_element()
	taglist = w.create().encode("utf-8")
	log.debug("%s: %s" % (taglist_filename, taglist))
	open(taglist_filename, "wb").write(taglist)
Ejemplo n.º 9
0
class Admin(object):
	""" A administration-panel interface using exml. """
	def __init__(self, stylesheet, encoding=settings.encoding,
				pretty=False, startpage=default_startpage):
		"""
		@param stylesheet: The URL to a XSLT document to associate
			with the output.
		@param encoding: The encoding to output in. Defaults
			to L{enkel.settings.encoding}.
		@param pretty: Forwarded to
			L{enkel.xmlutils.writer.XmlWriter.__init__}.
		@param startpage: A function which creates the startpage.
			Defaults to L{default_startpage}.
		"""
		self.apps = {}
		self.pretty = pretty
		self.applist = XmlWriter(pretty=pretty)
		self.applist.start_element("applist")
		self.encoding = encoding
		self.stylesheet = stylesheet
		self.startpage = startpage

	def add(self, id, app, label, *args, **kw):
		"""
		@type id: str
		@param id: A unique indentifier for the app within
				this Admin object.
		@param app: A L{AdminApp} instance.
		@type label: unicode.
		@param label: The label to show to the user when referencing
				the app.
		@param args: Arguments to the app.__init__.
		@param kw: Keyword arguments to the app.__init__.
		"""
		self.apps[id] = app, label, args, kw

		self.applist.start_element("app", id=id, label=label)
		for action in app.INDEX:
			self.applist.empty_element("action", id=action,
					label=app.ACTIONS[action])
		self.applist.end_element()


	def compile(self):
		""" Compile the route. Must be called once after
		all AdminApp's has been L{add}ed. """
		ids = "|".join(self.apps.keys())
		self.patt = compile(".*(?P<appid>(?:%s))/(?P<action>\w+)$" % ids)
		self.applist_xml = self.applist.create()
		del self.applist


	def __call__(self, env, start_response):
		"""
		env["enkel.reuse.admin.stylesheet"] must contain the
		URL to the XSLT stylesheet.
		"""

		path = env["SCRIPT_NAME"] + env["PATH_INFO"]
		appid = None
		if not path.endswith("start/"):
			match = self.patt.match(path)
			if match:
				appid, action = match.groups()
				app, label, args, kw = self.apps[appid]
			else:
				raise Http404()


		w = XmlWriter(pretty=self.pretty)
		w.pi("xml", version="1.0", encoding=self.encoding)
		w.pi("xml-stylesheet", type="text/xsl", href=self.stylesheet)
		w.start_element("admin", xmlns=XMLNS_ADMIN)
		w.raw_node(self.applist_xml)

		if appid:
			w.empty_element("selected", app=appid, action=action)
		w.start_element("section", xmlns=XMLNS_MARKUP)
		if appid:
			app(env, w, appid, action, label, *args, **kw)
		else:
			self.startpage(env, w)
		w.end_element()

		start_response("200 OK", [
			("content-type", "text/xml; charset=%s" % self.encoding)
		])
		yield w.create().encode(self.encoding)
Ejemplo n.º 10
0
	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)
Ejemplo n.º 11
0
class Admin(object):
    """ A administration-panel interface using exml. """
    def __init__(self,
                 stylesheet,
                 encoding=settings.encoding,
                 pretty=False,
                 startpage=default_startpage):
        """
		@param stylesheet: The URL to a XSLT document to associate
			with the output.
		@param encoding: The encoding to output in. Defaults
			to L{enkel.settings.encoding}.
		@param pretty: Forwarded to
			L{enkel.xmlutils.writer.XmlWriter.__init__}.
		@param startpage: A function which creates the startpage.
			Defaults to L{default_startpage}.
		"""
        self.apps = {}
        self.pretty = pretty
        self.applist = XmlWriter(pretty=pretty)
        self.applist.start_element("applist")
        self.encoding = encoding
        self.stylesheet = stylesheet
        self.startpage = startpage

    def add(self, id, app, label, *args, **kw):
        """
		@type id: str
		@param id: A unique indentifier for the app within
				this Admin object.
		@param app: A L{AdminApp} instance.
		@type label: unicode.
		@param label: The label to show to the user when referencing
				the app.
		@param args: Arguments to the app.__init__.
		@param kw: Keyword arguments to the app.__init__.
		"""
        self.apps[id] = app, label, args, kw

        self.applist.start_element("app", id=id, label=label)
        for action in app.INDEX:
            self.applist.empty_element("action",
                                       id=action,
                                       label=app.ACTIONS[action])
        self.applist.end_element()

    def compile(self):
        """ Compile the route. Must be called once after
		all AdminApp's has been L{add}ed. """
        ids = "|".join(self.apps.keys())
        self.patt = compile(".*(?P<appid>(?:%s))/(?P<action>\w+)$" % ids)
        self.applist_xml = self.applist.create()
        del self.applist

    def __call__(self, env, start_response):
        """
		env["enkel.reuse.admin.stylesheet"] must contain the
		URL to the XSLT stylesheet.
		"""

        path = env["SCRIPT_NAME"] + env["PATH_INFO"]
        appid = None
        if not path.endswith("start/"):
            match = self.patt.match(path)
            if match:
                appid, action = match.groups()
                app, label, args, kw = self.apps[appid]
            else:
                raise Http404()

        w = XmlWriter(pretty=self.pretty)
        w.pi("xml", version="1.0", encoding=self.encoding)
        w.pi("xml-stylesheet", type="text/xsl", href=self.stylesheet)
        w.start_element("admin", xmlns=XMLNS_ADMIN)
        w.raw_node(self.applist_xml)

        if appid:
            w.empty_element("selected", app=appid, action=action)
        w.start_element("section", xmlns=XMLNS_MARKUP)
        if appid:
            app(env, w, appid, action, label, *args, **kw)
        else:
            self.startpage(env, w)
        w.end_element()

        start_response(
            "200 OK",
            [("content-type", "text/xml; charset=%s" % self.encoding)])
        yield w.create().encode(self.encoding)