Rebranded to Tailbone.
This commit is contained in:
parent
47944767dc
commit
40efd8a3bc
111 changed files with 188 additions and 209 deletions
99
tailbone/forms/renderers/__init__.py
Normal file
99
tailbone/forms/renderers/__init__.py
Normal file
|
@ -0,0 +1,99 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2012 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 Affero 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 Affero General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
"""
|
||||
FormAlchemy Field Renderers
|
||||
"""
|
||||
|
||||
from webhelpers.html import literal
|
||||
from webhelpers.html import tags
|
||||
|
||||
import formalchemy
|
||||
|
||||
from edbob.pyramid.forms import pretty_datetime
|
||||
from edbob.pyramid.forms.formalchemy.renderers import YesNoFieldRenderer
|
||||
|
||||
from .common import AutocompleteFieldRenderer, EnumFieldRenderer
|
||||
from .products import GPCFieldRenderer, ProductFieldRenderer
|
||||
from .users import UserFieldRenderer
|
||||
|
||||
|
||||
__all__ = ['AutocompleteFieldRenderer', 'EnumFieldRenderer', 'YesNoFieldRenderer',
|
||||
'GPCFieldRenderer', 'PersonFieldRenderer', 'PriceFieldRenderer',
|
||||
'PriceWithExpirationFieldRenderer', 'ProductFieldRenderer', 'UserFieldRenderer']
|
||||
|
||||
|
||||
def PersonFieldRenderer(url):
|
||||
|
||||
BaseRenderer = AutocompleteFieldRenderer(url)
|
||||
|
||||
class PersonFieldRenderer(BaseRenderer):
|
||||
|
||||
def render_readonly(self, **kwargs):
|
||||
person = self.raw_value
|
||||
if not person:
|
||||
return ''
|
||||
return tags.link_to(
|
||||
str(person),
|
||||
self.request.route_url('person.read', uuid=person.uuid))
|
||||
|
||||
return PersonFieldRenderer
|
||||
|
||||
|
||||
class PriceFieldRenderer(formalchemy.TextFieldRenderer):
|
||||
"""
|
||||
Renderer for fields which reference a :class:`ProductPrice` instance.
|
||||
"""
|
||||
|
||||
def render_readonly(self, **kwargs):
|
||||
price = self.field.raw_value
|
||||
if price:
|
||||
if price.price is not None and price.pack_price is not None:
|
||||
if price.multiple > 1:
|
||||
return literal('$ %0.2f / %u ($ %0.2f / %u)' % (
|
||||
price.price, price.multiple,
|
||||
price.pack_price, price.pack_multiple))
|
||||
return literal('$ %0.2f ($ %0.2f / %u)' % (
|
||||
price.price, price.pack_price, price.pack_multiple))
|
||||
if price.price is not None:
|
||||
if price.multiple > 1:
|
||||
return '$ %0.2f / %u' % (price.price, price.multiple)
|
||||
return '$ %0.2f' % price.price
|
||||
if price.pack_price is not None:
|
||||
return '$ %0.2f / %u' % (price.pack_price, price.pack_multiple)
|
||||
return ''
|
||||
|
||||
|
||||
class PriceWithExpirationFieldRenderer(PriceFieldRenderer):
|
||||
"""
|
||||
Price field renderer which also displays the expiration date, if present.
|
||||
"""
|
||||
|
||||
def render_readonly(self, **kwargs):
|
||||
res = super(PriceWithExpirationFieldRenderer, self).render_readonly(**kwargs)
|
||||
if res:
|
||||
price = self.field.raw_value
|
||||
if price.ends:
|
||||
res += ' (%s)' % pretty_datetime(price.ends, from_='utc')
|
||||
return res
|
80
tailbone/forms/renderers/common.py
Normal file
80
tailbone/forms/renderers/common.py
Normal file
|
@ -0,0 +1,80 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2012 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 Affero 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 Affero General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
"""
|
||||
Common Field Renderers
|
||||
"""
|
||||
|
||||
from formalchemy.fields import FieldRenderer, SelectFieldRenderer
|
||||
|
||||
|
||||
__all__ = ['AutocompleteFieldRenderer', 'EnumFieldRenderer']
|
||||
|
||||
|
||||
def AutocompleteFieldRenderer(service_url, field_value=None, field_display=None, width='300px'):
|
||||
"""
|
||||
Returns a custom renderer class for an autocomplete field.
|
||||
"""
|
||||
|
||||
class AutocompleteFieldRenderer(FieldRenderer):
|
||||
|
||||
@property
|
||||
def focus_name(self):
|
||||
return self.name + '-textbox'
|
||||
|
||||
@property
|
||||
def needs_focus(self):
|
||||
return not bool(self.value or field_value)
|
||||
|
||||
def render(self, **kwargs):
|
||||
kwargs.setdefault('field_name', self.name)
|
||||
kwargs.setdefault('field_value', self.value or field_value)
|
||||
kwargs.setdefault('field_display', self.raw_value or field_display)
|
||||
kwargs.setdefault('service_url', service_url)
|
||||
kwargs.setdefault('width', width)
|
||||
return render('/forms/field_autocomplete.mako', kwargs)
|
||||
|
||||
return AutocompleteFieldRenderer
|
||||
|
||||
|
||||
def EnumFieldRenderer(enum):
|
||||
"""
|
||||
Adds support for enumeration fields.
|
||||
"""
|
||||
|
||||
class Renderer(SelectFieldRenderer):
|
||||
|
||||
def render_readonly(self, **kwargs):
|
||||
value = self.raw_value
|
||||
if value is None:
|
||||
return ''
|
||||
if value in enum:
|
||||
return enum[value]
|
||||
return str(value)
|
||||
|
||||
def render(self, **kwargs):
|
||||
opts = [(enum[x], x) for x in sorted(enum)]
|
||||
return SelectFieldRenderer.render(self, opts, **kwargs)
|
||||
|
||||
return Renderer
|
56
tailbone/forms/renderers/products.py
Normal file
56
tailbone/forms/renderers/products.py
Normal file
|
@ -0,0 +1,56 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2012 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 Affero 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 Affero General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
"""
|
||||
Product Field Renderers
|
||||
"""
|
||||
|
||||
from formalchemy import TextFieldRenderer
|
||||
from rattail.gpc import GPC
|
||||
|
||||
|
||||
__all__ = ['GPCFieldRenderer', 'ProductFieldRenderer']
|
||||
|
||||
|
||||
class GPCFieldRenderer(TextFieldRenderer):
|
||||
"""
|
||||
Renderer for :class:`rattail.gpc.GPC` fields.
|
||||
"""
|
||||
|
||||
@property
|
||||
def length(self):
|
||||
# Hm, should maybe consider hard-coding this...?
|
||||
return len(str(GPC(0)))
|
||||
|
||||
|
||||
class ProductFieldRenderer(TextFieldRenderer):
|
||||
"""
|
||||
Renderer for fields which represent :class:`rattail.db.Product` instances.
|
||||
"""
|
||||
|
||||
def render_readonly(self, **kwargs):
|
||||
product = self.raw_value
|
||||
if product is None:
|
||||
return ''
|
||||
return product.full_description
|
44
tailbone/forms/renderers/users.py
Normal file
44
tailbone/forms/renderers/users.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
################################################################################
|
||||
#
|
||||
# Rattail -- Retail Software Framework
|
||||
# Copyright © 2010-2012 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 Affero 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 Affero General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
################################################################################
|
||||
|
||||
"""
|
||||
User Field Renderers
|
||||
"""
|
||||
|
||||
from formalchemy.fields import TextFieldRenderer
|
||||
|
||||
|
||||
__all__ = ['UserFieldRenderer']
|
||||
|
||||
|
||||
class UserFieldRenderer(TextFieldRenderer):
|
||||
"""
|
||||
Renderer for fields which represent ``User`` instances.
|
||||
"""
|
||||
|
||||
def render_readonly(self, **kwargs):
|
||||
user = self.raw_value
|
||||
if user is None:
|
||||
return u''
|
||||
return unicode(user.display_name)
|
Loading…
Add table
Add a link
Reference in a new issue