From d0b78babd2175ce0ac28661556fcc92156cca077 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 11 Feb 2018 22:46:35 -0600 Subject: [PATCH] Remove legacy 'forms' package and templates yay! --- tailbone/forms/__init__.py | 39 --- tailbone/forms/alchemy.py | 117 ------- tailbone/forms/core.py | 119 ------- tailbone/forms/fields.py | 106 ------ tailbone/forms/renderers/__init__.py | 51 --- tailbone/forms/renderers/batch.py | 103 ------ tailbone/forms/renderers/bouncer.py | 63 ---- tailbone/forms/renderers/common.py | 315 ------------------ tailbone/forms/renderers/core.py | 100 ------ tailbone/forms/renderers/custorders.py | 42 --- tailbone/forms/renderers/employees.py | 49 --- tailbone/forms/renderers/files.py | 102 ------ tailbone/forms/renderers/people.py | 81 ----- tailbone/forms/renderers/products.py | 224 ------------- tailbone/forms/renderers/stores.py | 49 --- tailbone/forms/renderers/users.py | 97 ------ tailbone/forms/renderers/vendors.py | 60 ---- tailbone/forms/simpleform.py | 82 ----- tailbone/forms/validators.py | 153 --------- .../templates/forms/field_autocomplete.mako | 4 - tailbone/templates/forms/fields/date.mako | 10 - tailbone/templates/forms/fieldset.mako | 40 --- .../templates/forms/fieldset_readonly.mako | 7 - tailbone/templates/forms/form.mako | 21 -- tailbone/templates/forms/form_readonly.mako | 7 - tailbone/templates/forms/lib.mako | 10 - 26 files changed, 2051 deletions(-) delete mode 100644 tailbone/forms/__init__.py delete mode 100644 tailbone/forms/alchemy.py delete mode 100644 tailbone/forms/core.py delete mode 100644 tailbone/forms/fields.py delete mode 100644 tailbone/forms/renderers/__init__.py delete mode 100644 tailbone/forms/renderers/batch.py delete mode 100644 tailbone/forms/renderers/bouncer.py delete mode 100644 tailbone/forms/renderers/common.py delete mode 100644 tailbone/forms/renderers/core.py delete mode 100644 tailbone/forms/renderers/custorders.py delete mode 100644 tailbone/forms/renderers/employees.py delete mode 100644 tailbone/forms/renderers/files.py delete mode 100644 tailbone/forms/renderers/people.py delete mode 100644 tailbone/forms/renderers/products.py delete mode 100644 tailbone/forms/renderers/stores.py delete mode 100644 tailbone/forms/renderers/users.py delete mode 100644 tailbone/forms/renderers/vendors.py delete mode 100644 tailbone/forms/simpleform.py delete mode 100644 tailbone/forms/validators.py delete mode 100644 tailbone/templates/forms/field_autocomplete.mako delete mode 100644 tailbone/templates/forms/fields/date.mako delete mode 100644 tailbone/templates/forms/fieldset.mako delete mode 100644 tailbone/templates/forms/fieldset_readonly.mako delete mode 100644 tailbone/templates/forms/form.mako delete mode 100644 tailbone/templates/forms/form_readonly.mako delete mode 100644 tailbone/templates/forms/lib.mako diff --git a/tailbone/forms/__init__.py b/tailbone/forms/__init__.py deleted file mode 100644 index 9982a978..00000000 --- a/tailbone/forms/__init__.py +++ /dev/null @@ -1,39 +0,0 @@ -# -*- coding: utf-8 -*- -################################################################################ -# -# Rattail -- Retail Software Framework -# Copyright © 2010-2017 Lance Edgar -# -# This file is part of Rattail. -# -# Rattail is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along with -# Rattail. If not, see . -# -################################################################################ -""" -Forms -""" - -from __future__ import unicode_literals, absolute_import - -from formencode import Schema - -from .core import Form, Field, FieldSet, GenericFieldSet -from .simpleform import SimpleForm, FormRenderer -from .alchemy import AlchemyForm -from .fields import AssociationProxyField -from .renderers import * - -from . import fields -from . import renderers -from . import validators diff --git a/tailbone/forms/alchemy.py b/tailbone/forms/alchemy.py deleted file mode 100644 index 161d549f..00000000 --- a/tailbone/forms/alchemy.py +++ /dev/null @@ -1,117 +0,0 @@ -# -*- coding: utf-8; -*- -################################################################################ -# -# Rattail -- Retail Software Framework -# Copyright © 2010-2017 Lance Edgar -# -# This file is part of Rattail. -# -# Rattail is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along with -# Rattail. If not, see . -# -################################################################################ -""" -FormAlchemy Forms -""" - -from __future__ import unicode_literals, absolute_import - -from rattail.core import Object - -import formalchemy as fa -from pyramid.renderers import render -from webhelpers2.html import HTML, tags - -from tailbone.db import Session - - -class TemplateEngine(fa.templates.TemplateEngine): - """ - Mako template engine for FormAlchemy. - """ - - def render(self, template, prefix='/forms/', suffix='.mako', **kwargs): - template = ''.join((prefix, template, suffix)) - return render(template, kwargs) - - -class AlchemyForm(Object): - """ - Form to contain a :class:`formalchemy.FieldSet` instance. - """ - id = None - create_label = "Create" - update_label = "Save" - - allow_successive_creates = False - - def __init__(self, request, fieldset, session=None, csrf_field='_csrf', **kwargs): - super(AlchemyForm, self).__init__(**kwargs) - self.request = request - self.fieldset = fieldset - self.session = session - self.csrf_field = csrf_field - - def _get_readonly(self): - return self.fieldset.readonly - def _set_readonly(self, val): - self.fieldset.readonly = val - readonly = property(_get_readonly, _set_readonly) - - @property - def successive_create_label(self): - return "%s and continue" % self.create_label - - def csrf(self, name=None): - """ - NOTE: this method was copied from `pyramid_simpleform.FormRenderer` - - Returns the CSRF hidden input. Creates new CSRF token - if none has been assigned yet. - - The name of the hidden field is **_csrf** by default. - """ - name = name or self.csrf_field - - token = self.request.session.get_csrf_token() - if token is None: - token = self.request.session.new_csrf_token() - - return tags.hidden(name, value=token) - - def csrf_token(self, name=None): - """ - NOTE: this method was copied from `pyramid_simpleform.FormRenderer` - - Convenience function. Returns CSRF hidden tag inside hidden DIV. - """ - return HTML.tag("div", self.csrf(name), style="display:none;") - - def render(self, **kwargs): - kwargs['form'] = self - if self.readonly: - template = '/forms/form_readonly.mako' - else: - template = '/forms/form.mako' - return render(template, kwargs) - - def render_fields(self): - return self.fieldset.render() - - def save(self): - self.fieldset.sync() - self.session.flush() - - def validate(self): - self.fieldset.rebind(data=self.request.params) - return self.fieldset.validate() diff --git a/tailbone/forms/core.py b/tailbone/forms/core.py deleted file mode 100644 index c2702fb7..00000000 --- a/tailbone/forms/core.py +++ /dev/null @@ -1,119 +0,0 @@ -# -*- coding: utf-8 -*- -################################################################################ -# -# Rattail -- Retail Software Framework -# Copyright © 2010-2017 Lance Edgar -# -# This file is part of Rattail. -# -# Rattail is free software: you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation, either version 3 of the License, or (at your option) any later -# version. -# -# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -# details. -# -# You should have received a copy of the GNU General Public License along with -# Rattail. If not, see . -# -################################################################################ -""" -Forms Core -""" - -from __future__ import unicode_literals, absolute_import - -from rattail.util import OrderedDict, prettify - -import formalchemy -from formalchemy.helpers import content_tag -from pyramid.renderers import render - - -class Form(object): - """ - Base class for all forms. - """ - create_label = "Create" - update_label = "Save" - - def __init__(self, request, readonly=False, action_url=None): - self.request = request - self.readonly = readonly - self.action_url = action_url - - def render(self, **kwargs): - kwargs.setdefault('form', self) - if self.readonly: - template = '/forms/form_readonly.mako' - else: - template = '/forms/form.mako' - return render(template, kwargs) - - def render_fields(self, **kwargs): - kwargs.setdefault('fieldset', self.fieldset) - if self.readonly: - template = '/forms/fieldset_readonly.mako' - else: - template = '/forms/fieldset.mako' - return render(template, kwargs) - - -class Field(object): - """ - Manually create instances of this class to populate a simple form. - """ - - def __init__(self, name, value=None, label=None, requires_label=True): - self.name = name - self.value = value - self._label = label or prettify(self.name) - self.requires_label = requires_label - - def is_required(self): - return True - - def label(self): - return self._label - - def label_tag(self, **html_options): - """ - Logic stolen from FormAlchemy so all fields can render their own label. - Original docstring follows. - - return the