Пример #1
0
def _set_widget_template_path():
    from deform import (Form, widget)

    Form.set_zpt_renderer(default_search_paths, translator=translator)

    registry = widget.ResourceRegistry()
    registry.set_js_resources(
        'json2', None, 'c2cgeoform:static/js/json2.min.js')
    registry.set_js_resources(
        'openlayers', '3.0.0', 'c2cgeoform:static/js/ol.js')
    registry.set_css_resources(
        'openlayers', '3.0.0', 'c2cgeoform:static/js/ol.css')
    registry.set_js_resources(
        'c2cgeoform.deform_map', None,
        'c2cgeoform:static/deform_map/controls.js')
    registry.set_css_resources(
        'c2cgeoform.deform_map', None,
        'c2cgeoform:static/deform_map/style.css')
    registry.set_js_resources(
        'typeahead', '0.10.5',
        'c2cgeoform:static/js/typeahead.bundle-0.10.5.min.js')
    registry.set_css_resources(
        'typeahead', '0.10.5',
        'c2cgeoform:static/js/typeaheadjs.css')
    registry.set_js_resources(
        'c2cgeoform.deform_search', None,
        'c2cgeoform:static/deform_search/search.js')
    Form.set_default_resource_registry(registry)
Пример #2
0
def init_deform(root_package):
    Form.set_zpt_renderer(default_search_paths, translator=translator)

    node_modules_root = '{}:node_modules'.format(root_package)

    registry = widget.default_resource_registry
    registry.set_js_resources(
        'openlayers', '3.0.0',
        '{}/openlayers/dist/ol.js'.format(node_modules_root))
    registry.set_css_resources(
        'openlayers', '3.0.0',
        '{}/openlayers/dist/ol.css'.format(node_modules_root))
    registry.set_js_resources(
        'c2cgeoform.deform_map', None,
        'c2cgeoform:static/deform_map/controls.js')
    registry.set_css_resources(
        'c2cgeoform.deform_map', None,
        'c2cgeoform:static/deform_map/style.css')
    registry.set_js_resources(
        'typeahead', '0.10.5',
        '{}/typeahead.js/dist/typeahead.bundle.min.js'.
        format(node_modules_root))
    registry.set_css_resources(
        'typeahead', '0.10.5',
        'c2cgeoform:static/js/typeaheadjs.css')
    registry.set_js_resources(
        'c2cgeoform.deform_search', None,
        'c2cgeoform:static/deform_search/search.js')

    widget.MappingWidget.fields_template = 'mapping_fields'
    widget.FormWidget.fields_template = 'mapping_fields'
Пример #3
0
def init_deform(root_package):
    Form.set_zpt_renderer(default_search_paths, translator=translator)

    node_modules_root = '{}:node_modules'.format(root_package)

    registry = widget.default_resource_registry
    registry.set_js_resources(
        'openlayers', '3.0.0',
        '{}/openlayers/dist/ol.js'.format(node_modules_root))
    registry.set_css_resources(
        'openlayers', '3.0.0',
        '{}/openlayers/dist/ol.css'.format(node_modules_root))
    registry.set_js_resources('c2cgeoform.deform_map', None,
                              'c2cgeoform:static/deform_map/controls.js')
    registry.set_css_resources('c2cgeoform.deform_map', None,
                               'c2cgeoform:static/deform_map/style.css')
    registry.set_js_resources(
        'typeahead', '0.10.5',
        '{}/typeahead.js/dist/typeahead.bundle.min.js'.format(
            node_modules_root))
    registry.set_css_resources('typeahead', '0.10.5',
                               'c2cgeoform:static/js/typeaheadjs.css')
    registry.set_js_resources('c2cgeoform.deform_search', None,
                              'c2cgeoform:static/deform_search/search.js')

    widget.MappingWidget.fields_template = 'mapping_fields'
    widget.FormWidget.fields_template = 'mapping_fields'
Пример #4
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    db.configure(bind=engine)
    Base.metadata.bind = engine
    config = Configurator(settings=settings,root_factory=get_root)

    deform_templates = resource_filename('deform', 'templates')
    deform_search_path = (resolve('charsheet:templates/deform'), deform_templates)
    Form.set_zpt_renderer(deform_search_path)

    config.include('pyramid_persona')
    config.set_authentication_policy(AuthTktAuthenticationPolicy(
        settings.get('persona.secret', None),
        hashalg='sha512',
        callback=get_groups,
        ))

    config.include('pyramid_mako')

    config.add_static_view('static/charsheet', 'charsheet:static', cache_max_age=3600)
    config.add_static_view('static/deform', 'deform:static', cache_max_age=3600)
    config.scan()
    return config.make_wsgi_app()
Пример #5
0
    def request_account(self):
        ###

        ###
        # instantiate our colander schema
        schema = AddAccountSchema().bind(
            country_codes_data=country_codes,
            us_states_data=us_states,
            title_prefix_data=title_prefixes,
            has_account=has_account,
        )
        # self.request.session.flash('')
        request = self.request
        session = request.session
        Form.set_zpt_renderer(search_path)

        # see if a user submitted the form
        submitted = "submit" in request.POST

        # get the user email from the POST request, if present
        user_email = request.POST.get("email", "")

        # get the form control field names and values as a list of tuples
        controls = request.POST.items()

        # create a deform form object from the schema
        form = Form(schema, action=request.route_url("request_account"), form_id="deformRegform")

        if submitted:
            # it's a submission, process it
            controls = self.request.POST.items()
            captured = None

            # schema = schema(validator=uid_validator)
            # create a deform form object from the schema
            sform = Form(schema, action=request.route_url("request_account"), form_id="deformRegform")

            try:
                # try to validate the submitted values
                captured = sform.validate(controls)

            except ValidationFailure as e:
                # the submitted values could not be validated
                flash_msg = u"Please address the errors indicated below!"
                self.request.session.flash(flash_msg)
                return dict(form=sform, page_title=self.title)

            unid = _add_new_request(captured, request)
            title = "Request Successfully submitted "
            view_url = request.route_url("request_received_view", unid=unid, page_title=title)
            return HTTPFound(view_url)
            # return HTTPMovedPermanently(location=view_url)
            # return self.request_received_view()
            # return view_url

        else:
            # not submitted, render form
            return dict(form=form, page_title=self.title)
Пример #6
0
def includeme(config):
    # override deform templates
    deform_templates = resource_filename('deform', 'templates')
    resolver = AssetResolver('yithlibraryserver')
    search_path = (
        resolver.resolve('templates').abspath(),
        deform_templates,
        )
    Form.set_zpt_renderer(search_path)

    config.add_route('home', '/')
    config.add_route('contact', '/contact')
    config.add_route('tos', '/tos')
Пример #7
0
def includeme(config):
    # override deform templates
    deform_templates = resource_filename('deform', 'templates')
    resolver = AssetResolver('yithlibraryserver')
    search_path = (
        resolver.resolve('templates').abspath(),
        deform_templates,
    )

    Form.set_zpt_renderer(search_path, translator=deform_translator)

    # setup views
    config.add_route('home', '/')
    config.add_route('contact', '/contact')
    config.add_route('tos', '/tos')
    config.add_route('faq', '/faq')
    config.add_route('credits', '/credits')
Пример #8
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    # pyramid_beaker add-on
    session_factory = session_factory_from_settings(settings)

    engine = engine_from_config(settings, "sqlalchemy.")
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    config = Configurator(settings=settings, session_factory=session_factory)
    config.include("pyramid_chameleon")
    config.include("pyramid_jinja2")
    config.add_jinja2_search_path("templates")
    config.include(add_routes)
    config.scan()

    # adding custom deform templates
    deform_templates = resource_filename("deform", "templates")
    search_path = (os.path.join(os.getcwd(), "codular/templates/forms"), deform_templates)

    Form.set_zpt_renderer(search_path)
    return config.make_wsgi_app()
Пример #9
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    # add custom deform template search path
    deform_templates = resource_filename('deform', 'templates')
    votingmachine_templates = resource_filename('votingmachine', 'templates')
    search_path = (votingmachine_templates, deform_templates)
    Form.set_zpt_renderer(search_path)
    zodb_uri = settings['zodb_uri']
    finder = PersistentApplicationFinder(zodb_uri, appmaker)

    def get_root(request):
        return finder(request.environ)

    authn_policy = AuthTktAuthenticationPolicy(
        secret='seekrit',
        callback=groupfinder,
    )
    authz_policy = ACLAuthorizationPolicy()
    # pyramid configuration
    config = Configurator(
        root_factory=get_root,
        settings=settings,
        authentication_policy=authn_policy,
        authorization_policy=authz_policy,
    )
    # subscriber for base template setup
    config.add_subscriber(
        'votingmachine.subscribers.add_base_template',
        'pyramid.events.BeforeRender')
    # add static views for this app and deform
    config.add_static_view(
        'static', 'votingmachine:static', cache_max_age=3600)
    config.add_static_view(
        'deform_static', 'deform:static', cache_max_age=3600)
    # find views
    config.scan('votingmachine')
    return config.make_wsgi_app()
Пример #10
0
    def setUp(self):  # noqa
        curdir = os.path.dirname(os.path.abspath(__file__))
        configfile = os.path.realpath(
            os.path.join(curdir, '../../development.ini'))
        settings = get_appsettings(configfile)
        apply_local_settings(settings)
        engine = engine_from_config(settings, 'sqlalchemy.')
        DBSession.configure(bind=engine)

        from models_test import Person, EmploymentStatus, Tag  # noqa
        Base.metadata.create_all(engine)
        self.cleanup()

        # fill some test data into the `EmploymentStatus` and `Tags` table
        DBSession.add(EmploymentStatus(id=0, name='Worker'))
        DBSession.add(EmploymentStatus(id=1, name='Employee'))
        DBSession.add(
            EmploymentStatus(id=2, name='Self-employed and contractor'))
        DBSession.add(EmploymentStatus(id=3, name='Director'))
        DBSession.add(EmploymentStatus(id=4, name='Office holder'))

        DBSession.add(Tag(id=0, name='Tag A'))
        DBSession.add(Tag(id=1, name='Tag B'))
        DBSession.add(Tag(id=2, name='Tag C'))
        DBSession.add(Tag(id=3, name='Tag D'))
        DBSession.add(Tag(id=4, name='Tag E'))

        self.request = testing.DummyRequest(post=MultiDict())
        testing.setUp(request=self.request)

        config = testing.setUp()
        config.add_route('form', '/{schema}/form/')
        config.add_route('view_user', '/{schema}/form/{hash}')
        config.add_route('confirm', '/{schema}/form/confirm')
        from deform import Form
        Form.set_zpt_renderer(default_search_paths)
Пример #11
0
def _set_widget_template_path():
    from deform import (Form, widget)

    Form.set_zpt_renderer(default_search_paths, translator=translator)

    registry = widget.ResourceRegistry()
    registry.set_js_resources('json2', None,
                              'c2cgeoform:static/js/json2.min.js')
    registry.set_js_resources('openlayers', '3.0.0',
                              'c2cgeoform:static/js/ol.js')
    registry.set_css_resources('openlayers', '3.0.0',
                               'c2cgeoform:static/js/ol.css')
    registry.set_js_resources('c2cgeoform.deform_map', None,
                              'c2cgeoform:static/deform_map/controls.js')
    registry.set_css_resources('c2cgeoform.deform_map', None,
                               'c2cgeoform:static/deform_map/style.css')
    registry.set_js_resources(
        'typeahead', '0.10.5',
        'c2cgeoform:static/js/typeahead.bundle-0.10.5.min.js')
    registry.set_css_resources('typeahead', '0.10.5',
                               'c2cgeoform:static/js/typeaheadjs.css')
    registry.set_js_resources('c2cgeoform.deform_search', None,
                              'c2cgeoform:static/deform_search/search.js')
    Form.set_default_resource_registry(registry)
Пример #12
0
from kotti import get_settings
from kotti import DBSession
from kotti.resources import Node
from kotti.resources import Document
from kotti.security import view_permitted
from kotti.views.util import template_api
from kotti.views.util import addable_types
from kotti.views.util import title_to_name
from kotti.views.util import disambiguate_name
from kotti.views.util import ensure_view_selector
from kotti.views.util import FormController

deform_templates = resource_filename('deform', 'templates')
kotti_templates = resource_filename('kotti', 'templates/edit/widgets')
search_path = (kotti_templates, deform_templates)
Form.set_zpt_renderer(search_path)

class ContentSchema(colander.MappingSchema):
    title = colander.SchemaNode(colander.String())
    description = colander.SchemaNode(
        colander.String(),
        widget=TextAreaWidget(cols=40, rows=5),
        missing=u"",
        )

class DocumentSchema(ContentSchema):
    body = colander.SchemaNode(
        colander.String(),
        widget=RichTextWidget(theme='advanced', width=790, height=500),
        missing=u"",
        )
from schema import Charakteristika

if 'CHARAKTERISTIKA_DEBUG' in os.environ:
  app.debug = True

from local_settings import active_config
config = active_config(app)
app.secret_key = config.secret

deform_bp = Blueprint('deform', 'deform', static_folder='static', url_prefix='/deform')
app.register_blueprint(deform_bp)

form_deform_templates = resource_filename('deform', 'templates')
form_my_templates = resource_filename(__name__, 'templates')
form_template_path = (form_my_templates, form_deform_templates)
Form.set_zpt_renderer(form_template_path)

class FormTokenConverter(BaseConverter):
  def __init__(self, url_map, *items):
    super(FormTokenConverter, self).__init__(url_map)
    self.regex = r'[A-Za-z0-9]{32}'

app.url_map.converters['token'] = FormTokenConverter

class LoginConverter(BaseConverter):
  def __init__(self, url_map, *items):
    super(LoginConverter, self).__init__(url_map)
    self.regex = r'[A-Za-z0-9]+'

app.url_map.converters['login'] = LoginConverter
Пример #14
0
log = logging.getLogger(__name__)

### Set form template paths

default_template_path = (
        resource_filename('opencore','views/templates/widgets'),
        resource_filename('deform', 'templates')
        )
app_template_path = list(Form.default_renderer.loader.search_path)

# Append opencore and deform template paths to list of app-specific paths
for path in default_template_path:
    if path not in app_template_path:
        app_template_path.append(path)

Form.set_zpt_renderer(app_template_path)

### Helpers

class instantiate:
    """
    A class decorator to make make writing
    schemas in Controller classes easier
    """
    def __init__(self,*args,**kw):
        self.args,self.kw = args,kw
    def __call__(self,class_):
        return class_(*self.args,**self.kw)
    
def _get_manage_actions(community, request):
    # XXX - this isn't very pluggable :-(
Пример #15
0
    def request_account(self):
        ###

        ###
        # instantiate our colander schema
        schema = AddAccountSchema().bind(country_codes_data=country_codes,
                                         us_states_data=us_states,
                                         title_prefix_data=title_prefixes,
                                         has_account=has_account)
        # self.request.session.flash('')
        request = self.request
        session = request.session
        Form.set_zpt_renderer(search_path)

        # see if a user submitted the form
        submitted = 'submit' in request.POST

        # get the user email from the POST request, if present
        user_email = request.POST.get('email', '')

        # get the form control field names and values as a list of tuples
        controls = request.POST.items()

        # create a deform form object from the schema
        form = Form(schema,
                    action=request.route_url('request_account'),
                    form_id='deformRegform')

        if submitted:
            # it's a submission, process it
            controls = self.request.POST.items()
            captured = None

            # schema = schema(validator=uid_validator)
            # create a deform form object from the schema
            sform = Form(schema,
                         action=request.route_url('request_account'),
                         form_id='deformRegform')

            try:
                # try to validate the submitted values
                captured = sform.validate(controls)

            except ValidationFailure as e:
                # the submitted values could not be validated
                flash_msg = u"Please address the errors indicated below!"
                self.request.session.flash(flash_msg)
                return dict(form=sform, page_title=self.title)

            unid = _add_new_request(captured, request)
            title = 'Request Successfully submitted '
            view_url = request.route_url('request_received_view',
                                         unid=unid,
                                         page_title=title)
            return HTTPFound(view_url)
            # return HTTPMovedPermanently(location=view_url)
            # return self.request_received_view()
            # return view_url

        else:
            # not submitted, render form
            return dict(form=form, page_title=self.title)
Пример #16
0
from webob.exc import HTTPFound
from webob.exc import HTTPUnauthorized
from zope.password.password import SSHAPasswordManager

from cartouche.interfaces import IAutoLogin
from cartouche.interfaces import IRegistrations
from cartouche.persistence import ConfirmedRegistrations
from cartouche.persistence import PendingRegistrations
from cartouche.util import getRandomToken
from cartouche.util import localhost_mta
from cartouche.util import sendGeneratedPassword
from cartouche.util import view_url


templates_dir = resource_filename('cartouche', 'templates/')
Form.set_zpt_renderer([templates_dir, deform_templates_dir])


class Signup(Schema):
    email = SchemaNode(String(), validator=Email())


class Confirm(Schema):
    email = SchemaNode(String(),
                       validator=Email(),
                      )
    token = SchemaNode(String(),
                       description="Enter the token from the registration "
                                   "confirmation e-mail you received.")

Пример #17
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    session_factory = session_factory_from_settings(settings)
    from szcz.security import groupfinder
    authentication_policy = SessionAuthenticationPolicy(callback=groupfinder)
    authorization_policy = ACLAuthorizationPolicy()

    config = Configurator(settings=settings)
    config.set_authentication_policy(authentication_policy)
    config.set_authorization_policy(authorization_policy)
    config.set_request_property('szcz.security.get_user', name='user', reify=True)
    config.add_request_method('szcz.security.has_permission')

    config.include('pyramid_fanstatic')
    config.include('velruse.providers.google_oauth2')
    config.add_google_oauth2_login_from_settings(prefix='google.')
    config.include('velruse.providers.facebook')
    config.add_facebook_login_from_settings(prefix='facebook.')
    config.include('velruse.providers.twitter')
    config.add_twitter_login_from_settings(prefix='twitter.')
    config.include('pyramid_beaker')
    config.include('deform_bootstrap')
    config.include('js.deform_bootstrap')

    config.include('pyramid_mailer')
    config.include('pyramid_deform')
    config.include('pyramid_zcml')

    deform_templates = resource_filename('deform', 'templates')
    deform_bootstrap_templates = resource_filename('deform_bootstrap', 'templates')
    deform_szcz_templates = resource_filename('szcz', 'templates')
    search_path = (deform_szcz_templates, deform_bootstrap_templates, deform_templates)

    def translator(term):
        return get_localizer(get_current_request()).translate(term)
    Form.set_zpt_renderer(search_path, translator=translator)

    config.add_route('favicon', '/favicon.ico')
    config.add_route('home', '/')
    config.add_route('proxyerror', '/proxyerror')
    config.add_route('logout', '/logout')
    config.add_route('userprofile', '/profile')

    config.add_route('view_book', '/books/{id:\d+}')
    config.add_route('my_books', '/books/only_mine')
    config.add_route('list_books', '/books')

    config.add_route('list_canons', '/canons')
    config.add_route('view_canon', '/canons/{id:\d+}')

    config.add_route('my_groups', '/groups/only_mine')
    config.add_route('list_groups', '/groups')
    config.add_route('add_group', '/groups/+')
    config.add_route('join_group', '/groups/{id:\d+}/join', factory='szcz.groups.GroupContext')
    config.add_route('logo_group', '/groups/{id:\d+}/logo_view', factory='szcz.groups.GroupContext')
    config.add_route('wf_group', '/groups/{id:\d+}/change_state', factory='szcz.groups.GroupContext')
    config.add_route('wf_groupmembership', '/groups/{id:\d+}/member/{email}/change_state', factory='szcz.groups.GroupContext')
    config.add_route('view_group', '/groups/{id:\d+}', factory='szcz.groups.GroupContext')
    config.add_route('edit_group', '/groups/{id:\d+}/edit', factory='szcz.groups.GroupContext')
    config.add_route('add_book', '/groups/{id:\d+}/add_book', factory='szcz.groups.GroupContext')
    config.add_route('print_activation_group', '/groups/{id:\d+}/print_activation', factory='szcz.groups.GroupContext')
    config.add_route('manage_group_members', '/groups/{id:\d+}/manage_group_members', factory='szcz.groups.GroupContext')

    config.add_static_view('deform_static', 'deform:static')
    config.scan()
    config.set_root_factory('szcz.views.Context')
    config.set_session_factory(session_factory)

    config.add_translation_dirs('deform:locale')
    config.add_translation_dirs('colander:locale')
    config.load_zcml('workflow.zcml')

    return config.make_wsgi_app()
Пример #18
0
from webob.exc import HTTPForbidden
from webob.exc import HTTPFound
from webob.exc import HTTPUnauthorized
from zope.password.password import SSHAPasswordManager

from cartouche.interfaces import IAutoLogin
from cartouche.interfaces import IRegistrations
from cartouche.persistence import ConfirmedRegistrations
from cartouche.persistence import PendingRegistrations
from cartouche.util import getRandomToken
from cartouche.util import localhost_mta
from cartouche.util import sendGeneratedPassword
from cartouche.util import view_url

templates_dir = resource_filename('cartouche', 'templates/')
Form.set_zpt_renderer([templates_dir, deform_templates_dir])


class Signup(Schema):
    email = SchemaNode(String(), validator=Email())


class Confirm(Schema):
    email = SchemaNode(
        String(),
        validator=Email(),
    )
    token = SchemaNode(String(),
                       description="Enter the token from the registration "
                       "confirmation e-mail you received.")
Пример #19
0
def init_templates(config):
    deform_templates = resource_filename('deform', 'templates')
    rebecca_templates = resource_filename('rebecca.app.admin', 'widget_templates')
    search_path = (rebecca_templates, deform_templates)

    Form.set_zpt_renderer(search_path)
Пример #20
0
def set_deform_override():
    deform_templates = resource_filename('deform', 'templates')
    form_templates = resource_filename('morpcc',
                                       os.path.join('templates', 'deform'))
    search_path = (form_templates, deform_templates)
    Form.set_zpt_renderer(search_path)