{ "info": { "author": "Robin Harms Oredsson", "author_email": "robin@betahaus.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Pyramid", "Intended Audience :: Developers", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content" ], "description": ".. image:: https://travis-ci.org/robinharms/betahaus.viewcomponent.png?branch=master\r\n :target: https://travis-ci.org/robinharms/betahaus.viewcomponent\r\n\r\nbetahaus.viewcomponent README\r\n=============================\r\n\r\nReusable components in web pages make them a lot more fun and rewarding to write.\r\nThe goal of this package is to make them easy to add, remove and change.\r\nWhile it's usable in a regular webapp, it's probably more interesting to use\r\nin something that others will extend or change, like a framework.\r\n\r\nIt's written to be flexible and easy to adapt, rather than being the perfect solution to everything.\r\n\r\n\r\nBasic example - adding a logo\r\n-----------------------------\r\n\r\nFirst, create a method that returns an html tag.\r\nWe also need to decorate this method.\r\nThe va positional argument is a ViewAction - we can ignore that\r\nin this example.\r\n\r\n.. code-block:: python\r\n\r\n from betahaus.viewcomponent import view_action\r\n @view_action('stuff', 'logo')\r\n def logo_tag(context, request, va):\r\n return ''\r\n\r\nWhen you run ``config.scan('your-apps-name')`` with this code present,\r\nit will create a ViewGroup with the name 'stuff', that has a ViewAction\r\ncalled 'logo'.\r\n\r\nYou may optionally use a directive of the config object.\r\nYou need to include ``betahaus.viewcomponent`` in that case.\r\n\r\n.. code-block:: python\r\n\r\n #Code in your package\r\n \r\n def logo_tag(context, request, va):\r\n return ''\r\n \r\n def includeme(config):\r\n config.add_view_action(logo_tag, 'stuff', 'logo')\r\n\r\n\r\nThe ViewGroup is an ordered dict-like Utility, that keeps track of ViewActions.\r\n\r\nIf you want to get the result of a ViewGroup, simply do this:\r\n\r\n.. code-block:: python\r\n\r\n from betahaus.viewcomponent import render_view_group\r\n render_view_group(context, request, 'stuff')\r\n\r\nSince there's nothing else in this ViewGroup, only the logo tag will be returned.\r\n\r\nTo get the result of a single ViewAction only, you can call ``render_view_action``:\r\n\r\n.. code-block:: python\r\n\r\n from betahaus.viewcomponent import render_view_action\r\n render_view_action(context, request, 'stuff', 'logo')\r\n\r\n\r\nAnother example - building a menu\r\n---------------------------------\r\n\r\nSo you have a webapp, and you want a menu somewhere. And then package X, Y and Z\r\nworks as plugins, but how do they add to that menu of yours?\r\n(Read the Pyramid docs on how to create views)\r\n\r\nFirst, let's create minimal Python view code:\r\n\r\n.. code-block:: python\r\n\r\n from betahaus.viewcomponent import render_view_group\r\n from pyramid.view import view_config\r\n \r\n @view_config(renderer = 'some/template.pt')\r\n def main_template(context, request):\r\n return dict(render_view_group = render_view_group)\r\n \r\nAnd then the template:\r\n\r\n.. code-block:: html\r\n\r\n \r\n \r\n \r\n \r\n \r\n\r\nThe menu will be simple html strings, a ``
  • `` for each statement.\r\nTo return them, we need decorated methods. Note that the ViewGroup\r\n``menu`` will be created as soon as it's populated. (the first argument in the decorator)\r\n\r\n.. code-block:: python\r\n\r\n from betahaus.viewcomponent import view_action\r\n \r\n \r\n @view_action('menu', 'login')\r\n def login_link(context, request, va):\r\n return '
  • Login
  • '\r\n \r\n @view_action('menu', 'logout')\r\n def logout_link(context, request, va):\r\n return '
  • Logout
  • '\r\n \r\n @view_action('menu', 'my_personal_stuff', permission = 'ViewStuff')\r\n def personal_link(context, request, va):\r\n \"\"\" This will only render if user has permission 'ViewStuff'\"\"\"\r\n return '
  • My stuff
  • '\r\n\r\nAfter your app has been started, you'll have a menu now. Also, other apps may add to it the same way,\r\nor remove your initial alternatives.\r\n\r\n\r\nAdvanced example - a pluggable json renderer\r\n--------------------------------------------\r\n\r\nUsecase: You pull JSON from a database. Some information is sensitive\r\nand should only be visible to some users. Other plugins want to be able\r\nto attach or change information to the JSON response.\r\n\r\nOur context will be a mock user object where the email\r\nfield is to be treated as sensitive information.\r\n\r\n.. code-block:: python\r\n\r\n class User(object):\r\n userid = \"\"\r\n email = \"\"\r\n\r\n #etc...\r\n \r\nFirst, add two view actions for userid and email. The email one will have the permission\r\n``Show secret``.\r\n\r\n.. code-block:: python\r\n\r\n from betahaus.viewcomponent import view_action\r\n \r\n @view_action('json', 'userid')\r\n def get_userid(context, request, va, **kw):\r\n return getattr(context, 'userid', '')\r\n \r\n @view_action('json', 'email', permission = 'Show secret')\r\n def get_email(context, request, va, **kw):\r\n return getattr(context, 'email', '')\r\n\r\nSecond, lets register a regular view, that will return the view group ``json``.\r\n\r\n.. code-block:: python\r\n\r\n from betahaus.viewcomponent import render_view_group\r\n from pyramid.view import view_config\r\n \r\n @view_config(context = 'User', renderer = 'json', name = 'user.json')\r\n def user_view(context, request):\r\n \"\"\" Render json.\"\"\"\r\n return render_view_group(context, request, 'json', as_type='dict', empty_val = '')\r\n\r\nEmail will now only be included if the user/thing requesting the view\r\nhas the ``Show secret`` permission.\r\nThe ``as_type`` argument will render the view results as a dict where the keys\r\nwill be the view actions name. (user and email in this case)\r\n``empty_val`` specifies that any None or empty strings returned should be replaced by this value.\r\nSo even if userid returns '', that value will still be included.\r\n\r\n\r\nBonus: Spacer\r\n-------------\r\n\r\nSpacer will be added when the view action output is joined as a string,\r\nthe default behaviour. It's the same thing as doing spacer.join([view1, view2, etc])\r\n\r\n\r\nBonus: Priority\r\n---------------\r\n\r\nThe priority argument sets the order when a view action is added.\r\nPriority is sorted acending, so 10 is called before 20.\r\n\r\n\r\nRequirements\r\n------------\r\n\r\nThis package currently isn't usable outside of `Pyramid `_, but it could be\r\nchanged to be more generic and only require the basic `Zope Component Architechture `_ .\r\nIt also depends on venusian, which will be fetched by Pyramid.\r\n\r\n\r\nFeedback and features\r\n---------------------\r\n\r\nThe source code of the package is really small, and it should be commented enough so it's\r\neasy to pick up what to do with it. The package is still under development, but used on several\r\nproduction servers today.\r\n\r\nIf you have suggestions, criticism, feedback, ideas - please don't hesitate to contact me\r\nor add an `issue at GitHub `_.\r\n\r\n\r\nCredits\r\n=======\r\n\r\n* Robin Harms Oredsson / robinharms (Initial author)\r\n* Parnell Springmeyer / ixmatus\r\n* Paul Bonser / pib\r\n\r\nA lot of good ideas were taken from Pyramid (http://www.pylonsproject.org) itself and from different repoze software.\r\nThe code itself was written as part of the VoteIT project (http://www.voteit.se).\r\n\r\n\r\nChanges\r\n=======\r\n\r\n0.4.1 (2015-04-04)\r\n------------------\r\n\r\n- Added: Option to return dict, generator or list instead of just joined strings.\r\n- Added: Spacer option for the join statement.\r\n- Added: A config directive ''add_view_action'' to att view actions without scanning.\r\n- Fixed instance when replacing a ViewAction caused the new action to be displayed twice.\r\n- Bugfix: When replacing, the order should be preserved unless priority is set.\r\n- Removed debug panel since the code was outdated and didn't work with\r\n the newer version of pyramid_debugtoolbar\r\n\r\n0.3.1b (2014-05-05)\r\n-------------------\r\n\r\n- Unicode wasn't an allowed string-type... (Brown paperbag for me) [robinharms]\r\n\r\n0.3b (2014-03-19)\r\n-----------------\r\n\r\n- View groups don't catch exceptions any longer. This was a cause of a lot of\r\n odd error messages on Python 2.\r\n- Ordering with bad keys don't cause exceptions - they're logged as warnings instead.\r\n- New argument priority for view actions. [ixmatus]\r\n\r\n\r\n0.2b (2013-06-18)\r\n-----------------\r\n\r\n- Python3 support fixed by pib (Paul Bonser) - thanks a lot!\r\n- Fetch and execution of vas changed - empty result should be ignored,\r\n and yield isn't used now. This should make error messages clearer. [robinharms]\r\n- Checks for containment, interface, permission etc moved to ViewAction object, since\r\n they weren't performed if the object was called directly. [robinharms]\r\n\r\n\r\n0.1b\r\n----\r\n\r\n- Initial version", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/robinharms/betahaus.viewcomponent", "keywords": "web pyramid pylons", "license": "UNKNOWN", "maintainer": "", "maintainer_email": "", "name": "betahaus.viewcomponent", "package_url": "https://pypi.org/project/betahaus.viewcomponent/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/betahaus.viewcomponent/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/robinharms/betahaus.viewcomponent" }, "release_url": "https://pypi.org/project/betahaus.viewcomponent/0.4.1/", "requires_dist": null, "requires_python": null, "summary": "Plugin structure for menus, JSON responses or similar.", "version": "0.4.1" }, "last_serial": 1490793, "releases": { "0.1b": [ { "comment_text": "", "digests": { "md5": "cd31d8ba247fd5a8c534f354dafeb779", "sha256": "a9417f4f9a61f01cebb950422e799a8b4252bb7efd8991f9b198625bc9f49dac" }, "downloads": -1, "filename": "betahaus.viewcomponent-0.1b.tar.gz", "has_sig": false, "md5_digest": "cd31d8ba247fd5a8c534f354dafeb779", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11082, "upload_time": "2011-10-31T23:39:11", "url": "https://files.pythonhosted.org/packages/39/b3/587c243c0f65336c272c708ccc0b1526ed794fe3598a123aa96ad3eea2ab/betahaus.viewcomponent-0.1b.tar.gz" } ], "0.2b": [ { "comment_text": "", "digests": { "md5": "4c98a5838f631061596048a5b4758c60", "sha256": "a9822af60799120c4b0b73fcf825fbbf87599d5514bbca28217384a1a4c4a268" }, "downloads": -1, "filename": "betahaus.viewcomponent-0.2b.tar.gz", "has_sig": false, "md5_digest": "4c98a5838f631061596048a5b4758c60", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12364, "upload_time": "2013-06-18T11:19:28", "url": "https://files.pythonhosted.org/packages/fb/ad/8e92632e786aca1053e9e6321ab0680e86aee412b93f9e3c74ff8a31dce3/betahaus.viewcomponent-0.2b.tar.gz" } ], "0.3.1b": [ { "comment_text": "", "digests": { "md5": "f5a4cbeff595eabc69bc6e15d1ef9c98", "sha256": "b11388e4a39526d49d406ecfa5910fd23d5e9bf6cf4e2a656a803dc057c67592" }, "downloads": -1, "filename": "betahaus.viewcomponent-0.3.1b.tar.gz", "has_sig": false, "md5_digest": "f5a4cbeff595eabc69bc6e15d1ef9c98", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12186, "upload_time": "2014-05-05T13:01:06", "url": "https://files.pythonhosted.org/packages/9c/33/7f4d5012e1bfff5c583deca877a35d1a3ba8fbd451fc9d029fbd237470c4/betahaus.viewcomponent-0.3.1b.tar.gz" } ], "0.3b": [ { "comment_text": "", "digests": { "md5": "c5ca0c9fdec2a9b0bfd9276120ed1001", "sha256": "56c2c3be621a4aca162743fae500ade66c9321170dec962792294c2c358b608a" }, "downloads": -1, "filename": "betahaus.viewcomponent-0.3b.tar.gz", "has_sig": false, "md5_digest": "c5ca0c9fdec2a9b0bfd9276120ed1001", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11891, "upload_time": "2014-03-19T13:30:03", "url": "https://files.pythonhosted.org/packages/ff/cb/5ea67d189c1aa577c3ef1c076f9ec223b10b5cba58eaf1ccbb4c0117de33/betahaus.viewcomponent-0.3b.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "04ef8aa4d92091966a42fdf4f5f3cd68", "sha256": "a64a1dee62f0c3aa3b1bbef18de44b40c798a095a7aee9988801180c32313d14" }, "downloads": -1, "filename": "betahaus.viewcomponent-0.4.1.tar.gz", "has_sig": false, "md5_digest": "04ef8aa4d92091966a42fdf4f5f3cd68", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13321, "upload_time": "2015-04-04T14:21:27", "url": "https://files.pythonhosted.org/packages/39/72/727934b6f2512e8cdbe3478179fea8296a5fea00c313be6d9d6853154844/betahaus.viewcomponent-0.4.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "04ef8aa4d92091966a42fdf4f5f3cd68", "sha256": "a64a1dee62f0c3aa3b1bbef18de44b40c798a095a7aee9988801180c32313d14" }, "downloads": -1, "filename": "betahaus.viewcomponent-0.4.1.tar.gz", "has_sig": false, "md5_digest": "04ef8aa4d92091966a42fdf4f5f3cd68", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13321, "upload_time": "2015-04-04T14:21:27", "url": "https://files.pythonhosted.org/packages/39/72/727934b6f2512e8cdbe3478179fea8296a5fea00c313be6d9d6853154844/betahaus.viewcomponent-0.4.1.tar.gz" } ] }