示例#1
0
	def post(self, request):
		page = Page.get_by(id=request.form["page"])
		print request.form
		hbm = Plugin.get_by(name=u"HtmlBlockModule")
		content = HtmlBlock.get_or_create(plugin=hbm, placeholder=request.form["placeholder"], page=page)
		content.body = request.form["body"]
		session.commit()
		return Response(hbm.show(page, content.placeholder))
示例#2
0
	def post(self, request):
		page = Page.get_by(id=request.form["page"])
		vbp = Plugin.get_by(name=u"VideoBlockPlugin")
		video = VideoBlock.get_or_create(plugin=vbp, placeholder=request.form["placeholder"], page=page)
		video.link = request.form["link"]
		video.template=request.form["template"]
		session.commit()
		return Response(vbp.edit(page, video.placeholder))
示例#3
0
	def get(self, request):
		#publish some event
		eventer = Eventer()
		eventer.publish("some event", self)
		if not "foo" in request.session:
			request.session["foo"] = 0
		request.session["foo"] += 1
		blog = Blog(name="super blog", creator="Stas")
		if not Entry.get_by(title="super post"):
			entry = Entry(title="super post", body="saifjo", blog=blog)
		session.commit()
		print Entry.query.all()
		return TemplateResponse("view.html", {
			"foo": request.session["foo"], 
			"users": [{"url": "google.com", "username": "******"}],
			"blog": blog
		})
示例#4
0
	def get(self, request):
		#publish some event
		eventer = Eventer()
		eventer.publish("some event", self)
		if not "foo" in request.session:
			request.session["foo"] = 0
		request.session["foo"] += 1
		blog = Blog(name="super blog", creator="Stas")
		if not Entry.get_by(title="super post"):
			entry = Entry(title="super post", body="saifjo", blog=blog)
		session.commit()
		print Entry.query.all()
		return TemplateResponse("view.html", {
			"foo": request.session["foo"], 
			"users": [{"url": "google.com", "username": "******"}],
			"blog": blog
		})
示例#5
0
    def on_before_init_server(self, application):
        # loading plugins
        for p in application.options["plugins"]["path"]:
            PluginLoader.load(p)
        application.templates_environment.globals["placeholder"] = placeholder

        # adding urls
        application.router.add_urls({"api/(?P<plugin>.+)": ApiRouter})
        application.router.add_urls({"": PageRouter})
        application.router.add_urls({"(?P<url>.+)": PageRouter})

        # creating db
        setup_all()
        drop_all()
        create_all()

        # setting some properties
        for plugin_name, plugin in PluginInterface.plugins_and_names(fullname=False):
            # set application ref to plugin
            plugin.application = application
            plugin_dir = os.path.dirname(Importer.object_path(plugin))
            # adding templates paths
            templates_dir = os.path.join(plugin_dir, "templates")
            if os.path.exists(templates_dir):
                application.templater.add_template_paths([templates_dir], plugin_name.lower())
                plugin.template_path = templates_dir
                # adding static paths
            static_dir = os.path.join(plugin_dir, "static")
            if os.path.exists(static_dir):
                application.add_static([static_dir], url_path="/" + plugin_name.lower())
                plugin.static_path = static_dir
                # adding translation paths
            trans_dir = os.path.join(plugin_dir, "lang")
            if os.path.exists(trans_dir):
                application.templater.add_translation_paths([trans_dir])
                plugin.translation_path = trans_dir
                # register plugin in db
            pl_in_db = Plugin.get_or_create(name=plugin_name)
            plugin.db_instance = pl_in_db
            # calling load in all plugins
        PluginInterface.load_call_all()

        # adding admin page
        admin_page = Page(
            plugin=Plugin.get_by(name=u"AdminPageComponent"),
            title=u"Admin page",
            url=u"admin",
            template="adminpagecomponent/default.html",
        )
        # adding login page
        login_page = Page(
            plugin=Plugin.get_by(name=u"HtmlPageComponent"),
            title=u"Login page",
            url=u"login",
            template="securitycomponent/user/login.html",
        )

        # sample data
        from plugins.modules.html.models import HtmlBlock
        from plugins.modules.video.models import VideoBlock
        from plugins.components.html.models import HtmlPage
        from plugins.modules.menu.models import MenuBlock, MenuItem

        hello_page = HtmlPage(
            plugin=Plugin.get_by(name=u"HtmlPageComponent"),
            title=u"Aloha",
            url=u"",
            template=u"commonresourcesplugin/aloha.html",
        )
        p = HtmlPage(
            plugin=Plugin.get_by(name=u"HtmlPageComponent"),
            title=u"test page",
            url=u"test",
            template=u"htmlpagecomponent/user/default.html",
        )
        HtmlBlock(
            plugin=Plugin.get_by(name=u"HtmlBlockModule"),
            placeholder=u"content1",
            body=u"<h1>test content from db</h1>",
            page=p,
        )
        VideoBlock(
            plugin=Plugin.get_by(name=u"VideoBlockModule"),
            page=p,
            placeholder=u"content2",
            link=u"SLBsGIP6NTg",
            template=u"videoblockmodule/user/youtube.html",
        )
        mb = MenuBlock(
            plugin=Plugin.get_by(name=u"MenuBlockModule"),
            placeholder=u"header",
            title=u"Menu1",
            page=p,
            template=u"menublockmodule/user/hierarchical.html",
        )
        mi1 = MenuItem(title=u"MenuItem 1", menu=mb, page=p)
        MenuItem(title=u"MenuItem 11", page=p, parent=mi1)
        mi12 = MenuItem(title=u"MenuItem 12", page=p, parent=mi1)
        MenuItem(title=u"MenuItem 121", page=p, parent=mi12)
        MenuItem(title=u"MenuItem 2", menu=mb, page=p)

        # security
        manager_group = UserGroup(name="users")
        admin_group = UserGroup(name="admins", parent=manager_group)
        permission_for_admin_page = Permission(resource=admin_page, user_group=manager_group)
        permission_for_plugin = Permission(resource=Plugin.get_by(name=u"HtmlPageAdminApi"), user_group=manager_group)
        admin_user = User(name="admin", user_group=admin_group)
        manager_user = User(name="stas", user_group=manager_group)
        simple_user = User(name="boris")
        session.commit()
        print "Application loaded(%d plugins)" % len(PluginInterface.plugins())
示例#6
0
	def delete(self, request):
		context = {}
		page = HtmlPage.get_by(id=request.params["page"])
		page.delete()
		session.commit()
		return Response("ok")
示例#7
0
	def post(self, request):
		context = {}
		page = HtmlPage(plugin=Plugin.get_by(name=u"HtmlPageComponent"), title=request.form["title"], url=request.form["url"], template="htmlpagecomponent/user/" + request.form["template"])
		session.commit()
		return Response(ComponentInterface.plugin(u"HtmlPageComponent", fullname=False, ignorecase=True).html(page))