Refactor all remaining usage of webhelpers; use webhelpers2 etc. instead

This commit is contained in:
Lance Edgar 2017-07-06 21:07:38 -05:00
parent 018702159d
commit 631665e208
5 changed files with 22 additions and 23 deletions

View file

@ -95,14 +95,9 @@ requires = [
'six', # 1.10.0
'transaction', # 1.2.0
'waitress', # 0.8.1
'WebHelpers', # 1.3
'WebHelpers2', # 2.0
'WTForms', # 2.1
'zope.sqlalchemy', # 0.7
# TODO: Need to figure out what to do about this...
# # This is used to obtain POD image dimensions.
# 'PIL', # 1.1.7
]

View file

@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2014 Lance Edgar
# Copyright © 2010-2017 Lance Edgar
#
# This file is part of Rattail.
#
@ -24,15 +24,15 @@
Template Context Helpers
"""
from __future__ import unicode_literals
from __future__ import unicode_literals, absolute_import
import datetime
from decimal import Decimal
from rattail.util import pretty_quantity
from webhelpers.html import *
from webhelpers.html.tags import *
from webhelpers2.html import *
from webhelpers2.html.tags import *
from tailbone.util import csrf_token, pretty_datetime
@ -41,7 +41,15 @@ def pretty_date(date):
"""
Render a human-friendly date string.
"""
if not date:
return ''
return date.strftime('%a %d %b %Y')
def render_attrs(**attrs):
"""
Convenience wrapper to replace the deprecated
`webhelpers.html.builder.format_attrs()`
"""
HTML.optimize_attrs(attrs)
return HTML.render_attrs(attrs)

View file

@ -31,7 +31,6 @@ from rattail.util import prettify
from pyramid.renderers import render
from webhelpers2.html import HTML, tags
from webhelpers.html.builder import format_attrs
from tailbone.db import Session
from tailbone.newgrids import filters
@ -527,7 +526,6 @@ class Grid(object):
Addition kwargs are passed along as context to the template.
"""
kwargs['grid'] = self
kwargs['format_attrs'] = format_attrs
return render(template, kwargs)
def render_filters(self, template='/newgrids/filters.mako', **kwargs):

View file

@ -1,5 +1,5 @@
## -*- coding: utf-8 -*-
<div ${format_attrs(**grid.get_div_attrs())}>
<div ${h.render_attrs(**grid.get_div_attrs())}>
<table>
<thead>
<tr>
@ -16,12 +16,12 @@
</thead>
<tbody>
% for i, row in enumerate(grid.iter_rows(), 1):
<tr ${format_attrs(**grid.get_row_attrs(row, i))}>
<tr ${h.render_attrs(**grid.get_row_attrs(row, i))}>
% if grid.checkboxes:
<td class="checkbox">${grid.render_checkbox(row)}</td>
% endif
% for column in grid.iter_visible_columns():
<td ${format_attrs(**grid.get_cell_attrs(row, column))}>${grid.render_cell(row, column)}</td>
<td ${h.render_attrs(**grid.get_cell_attrs(row, column))}>${grid.render_cell(row, column)}</td>
% endfor
% if grid.show_actions_column:
<td class="actions">

View file

@ -38,7 +38,7 @@ from rattail.util import pretty_hours, hours_as_decimal
import formencode as fe
from pyramid_simpleform import Form
from webhelpers2.html import HTML
from webhelpers2.html import tags, HTML
from tailbone import forms
from tailbone.db import Session
@ -244,17 +244,15 @@ class TimeSheetView(View):
return Session.query(model.Store).order_by(model.Store.id).all()
def get_store_options(self, stores):
options = [(s.uuid, "{} - {}".format(s.id, s.name)) for s in stores]
options.insert(0, ('', "(all)"))
return options
options = [tags.Option("{} - {}".format(s.id, s.name), s.uuid) for s in stores]
return tags.Options(options, prompt="(all)")
def get_departments(self):
return Session.query(model.Department).order_by(model.Department.name).all()
def get_department_options(self, departments):
options = [(d.uuid, d.name) for d in departments]
options.insert(0, ('', "(all)"))
return options
options = [tags.Option(d.name, d.uuid) for d in departments]
return tags.Options(options, prompt="(all)")
def render_full(self, date=None, employees=None, store=None, department=None, form=None, **kwargs):
"""