Skip to main content

Helpful utilities for Pyramid projects

Project description

Introduction

This package is a collection of utility code to make building Pyramid applications backed by SQLAlchemy easier. It includes:

  • A TemplateAPI class to inject variables into all your templates

  • A Deform CSRF-validation schema

  • A Deform Recaptcha widget

  • SQLAlchemy DBSession and declarative_base stubs

Extra Models

If you have models that you would like the main initialize_db script to create, they need to inherit from sixfeetup.bowab.db.Base. Then add the following to your config:

bowab.models =
    dotted.python.path.to.models

Using the TemplateAPI

If you would like to include the sixfeetup.bowab.api.TemplateAPI class as is, you simply need to include this in your Pyramid app configuration:

config.include('sixfeetup.bowab')

This will add an event subscriber to the pyramid.events.BeforeRender event. This means that all templates will have access to an api variable that represents the TemplateAPI instance.

Google Analytics

The TemplateAPI class supports extracting Google Analytics settings from the Pyramid settings registry. The following keys are supported:

gaq.account

Property ID from Google

gaq.allow_linker

http://code.google.com/apis/analytics/docs/gaJS/gaJSApiDomainDirectory.html#_gat.GA_Tracker_._setAllowLinker

gaq.domain_name

explicit domain name to use

gaq.single_push

boolean; use a push per setting, or one single push

To use this in your project, update base.pt to include:

<!-- Google Analytics -->
<tal:gaq condition="api.gaq">
    <tal:code replace="structure api.gaq.as_html()" />
</tal:gaq>

Customizing the TemplateAPI

Often, you will want to use the sixfeetup.bowab.api.TemplateAPI class as a base for your own API instances, since you may have extra variables that should be available to templates.

To do this, you need to include sixfeetup.bowab as specified in the ‘Using the TemplateAPI’ section.

Then, create a subclass within your project that inherits from sixfeetup.bowab.api.TemplateAPI:

from sixfeetup.bowab.api import TemplateAPI

class MyTemplateAPI(TemplateAPI):
    def __init__(self, request, rendering_val):
        super(MyTemplateAPI, self).__init__(request, rendering_val)
        # Any custom initalization

    def my_func(self):
        return 'my func'

Then, in your paster.ini file, include the following:

bowab.api_class = my_project.MyTemplateAPI

Make sure the bowab.api_class variable points to the full dotted path of your custom class. This class will then be registered by the sixfeetup.bowab include process.

Using the Recaptcha Widget

The Recaptcha widget needs the private and public keys for your Recaptcha account. These can be set in your config file using the bowab.recaptcha_private_key and bowab.recaptcha_public_key values, respectively.

Using the SpectrumColorPickerWidget

The spectrum color picker widget can be used to convert text inputs expecting ‘#’-prefixed hexidecimal values to a nice jquery-based color picker input.

If the widget is initialized with a ‘default’ color value, that value will be presented as a pallet swatch to ease returning to default. If initialized with a ‘color’ value, that will be the initial color displayed.

Forms using the color picker widget will need to use the colorpicker_registry in order to ensure that the color picker js and css files are found. Alternatively, the resources may be imported and loaded into a custom registry, or into the deform default_resource_registry.

If you have more than one color field in a form, and wish to have separate values used for color and default, import the build_color_widget function which is suitable for use inside a defered widget generator. (See speak_friend.forms.profiles.Domain for an example).

Contributors

  • David Blewett

  • Nolan Brubaker

  • Cris Ewing

  • Chrissy Wainwright

  • Clayton Parker

Changelog

0.8 (xxxx-xx-xx)

0.7

  • Initial implementation

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sixfeetup.bowab-0.13.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

sixfeetup.bowab-0.13-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

Details for the file sixfeetup.bowab-0.13.tar.gz.

File metadata

  • Download URL: sixfeetup.bowab-0.13.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for sixfeetup.bowab-0.13.tar.gz
Algorithm Hash digest
SHA256 9c910054c4bf9727da43b472a358de1ab8d605ba94f84e2cc31a641ef860e6d1
MD5 035cef7e75f6b67a2effa4f335cd9720
BLAKE2b-256 7a0a5abf637840d727274437c348a90c15ceeb4a4adeb2483df53cca23d2ae06

See more details on using hashes here.

File details

Details for the file sixfeetup.bowab-0.13-py3-none-any.whl.

File metadata

  • Download URL: sixfeetup.bowab-0.13-py3-none-any.whl
  • Upload date:
  • Size: 14.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.8.1

File hashes

Hashes for sixfeetup.bowab-0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 ddff6e139e0466702893452f6064610060325c9c532d11475b841a25eaaf4e14
MD5 ea4d45856805b7e57260a92153d7d2e0
BLAKE2b-256 4ef0ee3d191648e8f6d86ec614a6e8f47357b802c475f325f8753136f12eeaa7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page