Remove some more edbob cruft.

This commit is contained in:
Lance Edgar 2014-11-18 23:00:24 -06:00
parent 9806c7a0a2
commit 8bf292ebac
14 changed files with 136 additions and 124 deletions

View file

@ -26,15 +26,11 @@ Common Field Renderers
from __future__ import unicode_literals from __future__ import unicode_literals
import pytz
import humanize
import formalchemy import formalchemy
from formalchemy.fields import FieldRenderer, SelectFieldRenderer, CheckBoxFieldRenderer from formalchemy.fields import FieldRenderer, SelectFieldRenderer, CheckBoxFieldRenderer
from pyramid.renderers import render from pyramid.renderers import render
from webhelpers.html import HTML
from rattail.time import timezone from tailbone.util import pretty_datetime
class AutocompleteFieldRenderer(FieldRenderer): class AutocompleteFieldRenderer(FieldRenderer):
@ -80,34 +76,6 @@ class AutocompleteFieldRenderer(FieldRenderer):
return unicode(value) return unicode(value)
def pretty_datetime(config, value):
"""
Formats a datetime as a "pretty" human-readable string, with a tooltip
showing the ISO string value.
:param config: Reference to a config object.
:param value: A ``datetime.datetime`` instance. Note that if this instance
is not timezone-aware, its timezone is assumed to be UTC.
"""
if not value:
return ''
# Make sure we're dealing with a tz-aware value. If we're given a naive
# value, we assume it to be local to the UTC timezone.
if not value.tzinfo:
value = pytz.utc.localize(value)
# Convert value to local timezone, and make a naive copy.
local = timezone(config)
value = local.normalize(value.astimezone(local))
naive_value = value.replace(tzinfo=None)
return HTML.tag('span',
title=value.strftime('%Y-%m-%d %H:%M:%S %Z%z'),
c=humanize.naturaltime(naive_value))
class DateTimeFieldRenderer(formalchemy.DateTimeFieldRenderer): class DateTimeFieldRenderer(formalchemy.DateTimeFieldRenderer):
""" """
Custom date/time field renderer, which displays a "pretty" value in Custom date/time field renderer, which displays a "pretty" value in

View file

@ -30,7 +30,8 @@ from formalchemy import TextFieldRenderer
from rattail.gpc import GPC from rattail.gpc import GPC
from .common import AutocompleteFieldRenderer from .common import AutocompleteFieldRenderer
from webhelpers.html import literal from webhelpers.html import literal
from edbob.pyramid.forms import pretty_datetime
from tailbone.util import pretty_datetime
__all__ = ['ProductFieldRenderer', 'GPCFieldRenderer', __all__ = ['ProductFieldRenderer', 'GPCFieldRenderer',
@ -122,5 +123,6 @@ class PriceWithExpirationFieldRenderer(PriceFieldRenderer):
if result: if result:
price = self.field.raw_value price = self.field.raw_value
if price.ends: if price.ends:
result += '  (%s)' % pretty_datetime(price.ends, from_='utc') result = '{0}  ({1})'.format(
result, pretty_datetime(self.request.rattail_config, price.ends))
return result return result

View file

@ -1,9 +1,8 @@
#!/usr/bin/env python # -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2012 Lance Edgar # Copyright © 2010-2014 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -21,18 +20,19 @@
# along with Rattail. If not, see <http://www.gnu.org/licenses/>. # along with Rattail. If not, see <http://www.gnu.org/licenses/>.
# #
################################################################################ ################################################################################
""" """
Template Context Helpers Template Context Helpers
""" """
from __future__ import unicode_literals
import datetime import datetime
from decimal import Decimal from decimal import Decimal
from webhelpers.html import * from webhelpers.html import *
from webhelpers.html.tags import * from webhelpers.html.tags import *
from edbob.pyramid.forms import pretty_datetime from tailbone.util import pretty_datetime
def pretty_date(date): def pretty_date(date):

View file

@ -1,9 +1,8 @@
#!/usr/bin/env python # -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2012 Lance Edgar # Copyright © 2010-2014 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -21,13 +20,12 @@
# along with Rattail. If not, see <http://www.gnu.org/licenses/>. # along with Rattail. If not, see <http://www.gnu.org/licenses/>.
# #
################################################################################ ################################################################################
""" """
Static Assets Static Assets
""" """
from __future__ import unicode_literals
def includeme(config): def includeme(config):
# TODO: Remove edbob.
config.include('edbob.pyramid.static')
config.add_static_view('tailbone', 'tailbone:static') config.add_static_view('tailbone', 'tailbone:static')

View file

@ -0,0 +1,32 @@
/******************************
* Permission Lists
******************************/
div.field-wrapper.permissions div.field div.group {
margin-bottom: 10px;
}
div.field-wrapper.permissions div.field div.group p {
font-weight: bold;
}
div.field-wrapper.permissions div.field label {
float: none;
font-weight: normal;
}
div.field-wrapper.permissions div.field label input {
margin-left: 15px;
margin-right: 10px;
}
div.field-wrapper.permissions div.field div.group p.perm {
font-weight: normal;
margin-left: 15px;
}
div.field-wrapper.permissions div.field div.group p.perm span {
font-family: monospace;
margin-right: 10px;
}

View file

@ -4,10 +4,10 @@
<head> <head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Working...</title> <title>Working...</title>
${h.javascript_link(request.static_url('edbob.pyramid:static/js/jquery.js'))} ${h.javascript_link(request.static_url('tailbone:static/js/lib/jquery-1.9.1.min.js'))}
${h.javascript_link(request.static_url('edbob.pyramid:static/js/edbob.js'))} ${h.javascript_link(request.static_url('tailbone:static/js/tailbone.js'))}
${h.stylesheet_link(request.static_url('edbob.pyramid:static/css/base.css'))} ${h.stylesheet_link(request.static_url('tailbone:static/css/base.css'))}
${h.stylesheet_link(request.static_url('edbob.pyramid:static/css/layout.css'))} ${h.stylesheet_link(request.static_url('tailbone:static/css/layout.css'))}
<style type="text/css"> <style type="text/css">
#container { #container {

View file

@ -1,9 +1,9 @@
## -*- coding: utf-8 -*- ## -*- coding: utf-8 -*-
<%inherit file="edbob.pyramid:templates/crud.mako" /> <%inherit file="/crud.mako" />
<%def name="head_tags()"> <%def name="head_tags()">
${parent.head_tags()} ${parent.head_tags()}
${h.stylesheet_link(request.static_url('edbob.pyramid:static/css/perms.css'))} ${h.stylesheet_link(request.static_url('tailbone:static/css/perms.css'))}
</%def> </%def>
<%def name="context_menu_items()"> <%def name="context_menu_items()">

62
tailbone/util.py Normal file
View file

@ -0,0 +1,62 @@
# -*- coding: utf-8 -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2014 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/>.
#
################################################################################
"""
Utilities
"""
from __future__ import unicode_literals
import pytz
import humanize
from webhelpers.html import HTML
from rattail.time import timezone
def pretty_datetime(config, value):
"""
Formats a datetime as a "pretty" human-readable string, with a tooltip
showing the ISO string value.
:param config: Reference to a config object.
:param value: A ``datetime.datetime`` instance. Note that if this instance
is not timezone-aware, its timezone is assumed to be UTC.
"""
if not value:
return ''
# Make sure we're dealing with a tz-aware value. If we're given a naive
# value, we assume it to be local to the UTC timezone.
if not value.tzinfo:
value = pytz.utc.localize(value)
# Convert value to local timezone, and make a naive copy.
local = timezone(config)
value = local.normalize(value.astimezone(local))
naive_value = value.replace(tzinfo=None)
return HTML.tag('span',
title=value.strftime('%Y-%m-%d %H:%M:%S %Z%z'),
c=humanize.naturaltime(naive_value))

View file

@ -1,9 +1,8 @@
#!/usr/bin/env python # -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2012 Lance Edgar # Copyright © 2010-2014 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -21,11 +20,12 @@
# along with Rattail. If not, see <http://www.gnu.org/licenses/>. # along with Rattail. If not, see <http://www.gnu.org/licenses/>.
# #
################################################################################ ################################################################################
""" """
Auth Views Auth Views
""" """
from __future__ import unicode_literals
from pyramid.httpexceptions import HTTPFound from pyramid.httpexceptions import HTTPFound
from pyramid.security import remember, forget, authenticated_userid from pyramid.security import remember, forget, authenticated_userid
@ -36,7 +36,8 @@ import formencode
from pyramid_simpleform import Form from pyramid_simpleform import Form
from ..forms.simpleform import FormRenderer from ..forms.simpleform import FormRenderer
import edbob from rattail.time import localtime
from ..db import Session from ..db import Session
from rattail.db.auth import authenticate_user, set_user_password from rattail.db.auth import authenticate_user, set_user_password
@ -85,20 +86,13 @@ def login(request):
form.data['username'], form.data['username'],
form.data['password']) form.data['password'])
if user: if user:
request.session.flash("%s logged in at %s" % ( request.session.flash("{0} logged in at {1}".format(
user.display_name, user, localtime(request.rattail_config).strftime('%I:%M %p')))
edbob.local_time().strftime('%I:%M %p')))
headers = remember(request, user.uuid) headers = remember(request, user.uuid)
return HTTPFound(location=referrer, headers=headers) return HTTPFound(location=referrer, headers=headers)
request.session.flash("Invalid username or password") request.session.flash("Invalid username or password")
url = request.rattail_config.get('edbob.pyramid', 'login.logo_url', return {'form': FormRenderer(form), 'referrer': referrer}
default=request.static_url('edbob.pyramid:static/img/logo.jpg'))
kwargs = eval(request.rattail_config.get('edbob.pyramid', 'login.logo_kwargs',
default="dict(width=500)"))
return {'form': FormRenderer(form), 'referrer': referrer,
'logo_url': url, 'logo_kwargs': kwargs}
def logout(request): def logout(request):

View file

@ -1,9 +1,8 @@
#!/usr/bin/env python # -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
################################################################################ ################################################################################
# #
# Rattail -- Retail Software Framework # Rattail -- Retail Software Framework
# Copyright © 2010-2012 Lance Edgar # Copyright © 2010-2014 Lance Edgar
# #
# This file is part of Rattail. # This file is part of Rattail.
# #
@ -21,18 +20,18 @@
# along with Rattail. If not, see <http://www.gnu.org/licenses/>. # along with Rattail. If not, see <http://www.gnu.org/licenses/>.
# #
################################################################################ ################################################################################
""" """
Core Batch Views Core Batch Views
""" """
from __future__ import unicode_literals
from pyramid.httpexceptions import HTTPFound from pyramid.httpexceptions import HTTPFound
from pyramid.renderers import render_to_response from pyramid.renderers import render_to_response
from webhelpers.html import tags from webhelpers.html import tags
from edbob.pyramid.forms import PrettyDateTimeFieldRenderer from tailbone.forms import DateTimeFieldRenderer, EnumFieldRenderer
from ...forms import EnumFieldRenderer
from ...grids.search import BooleanSearchFilter from ...grids.search import BooleanSearchFilter
from .. import SearchableAlchemyGridView, CrudView, View from .. import SearchableAlchemyGridView, CrudView, View
from ...progress import SessionProgress from ...progress import SessionProgress
@ -86,7 +85,6 @@ class BatchesGrid(SearchableAlchemyGridView):
def grid(self): def grid(self):
g = self.make_grid() g = self.make_grid()
g.executed.set(renderer=PrettyDateTimeFieldRenderer(from_='utc'))
g.configure( g.configure(
include=[ include=[
g.source, g.source,
@ -94,7 +92,7 @@ class BatchesGrid(SearchableAlchemyGridView):
g.destination, g.destination,
g.description, g.description,
g.rowcount.label("Row Count"), g.rowcount.label("Row Count"),
g.executed, g.executed.with_renderer(DateTimeFieldRenderer(self.request.rattail_config)),
], ],
readonly=True) readonly=True)
if self.request.has_perm('batches.read'): if self.request.has_perm('batches.read'):
@ -121,7 +119,6 @@ class BatchCrud(CrudView):
def fieldset(self, model): def fieldset(self, model):
fs = self.make_fieldset(model) fs = self.make_fieldset(model)
fs.action_type.set(renderer=EnumFieldRenderer(enum.BATCH_ACTION)) fs.action_type.set(renderer=EnumFieldRenderer(enum.BATCH_ACTION))
fs.executed.set(renderer=PrettyDateTimeFieldRenderer(from_='utc'))
fs.configure( fs.configure(
include=[ include=[
fs.source, fs.source,
@ -130,7 +127,7 @@ class BatchCrud(CrudView):
fs.action_type, fs.action_type,
fs.description, fs.description,
fs.rowcount.label("Row Count").readonly(), fs.rowcount.label("Row Count").readonly(),
fs.executed.readonly(), fs.executed.with_renderer(DateTimeFieldRenderer(self.request.rattail_config)).readonly(),
]) ])
return fs return fs

View file

@ -33,7 +33,7 @@ from ..forms import AlchemyForm
from formalchemy import FieldSet from formalchemy import FieldSet
from ..db import Session from ..db import Session
from edbob.util import requires_impl, prettify from edbob.util import prettify
__all__ = ['CrudView'] __all__ = ['CrudView']
@ -46,18 +46,16 @@ class CrudView(View):
update_cancel_route = None update_cancel_route = None
@property @property
@requires_impl(is_property=True)
def mapped_class(self): def mapped_class(self):
pass raise NotImplementedError
@property @property
def pretty_name(self): def pretty_name(self):
return self.mapped_class.__name__ return self.mapped_class.__name__
@property @property
@requires_impl(is_property=True)
def home_route(self): def home_route(self):
pass raise NotImplementedError
@property @property
def home_url(self): def home_url(self):

View file

@ -37,7 +37,6 @@ from webhelpers.html.tags import link_to
from pyramid.httpexceptions import HTTPFound from pyramid.httpexceptions import HTTPFound
from pyramid.renderers import render_to_response from pyramid.renderers import render_to_response
import edbob
from . import SearchableAlchemyGridView from . import SearchableAlchemyGridView
import rattail.labels import rattail.labels

View file

@ -35,12 +35,11 @@ from pyramid.response import Response
from ..db import Session from ..db import Session
from edbob.time import local_time
import rattail import rattail
from rattail import enum from rattail import enum
from rattail.db import model from rattail.db import model
from rattail.files import resource_path from rattail.files import resource_path
from rattail.time import localtime
plu_upc_pattern = re.compile(r'^000000000(\d{5})$') plu_upc_pattern = re.compile(r'^000000000(\d{5})$')
@ -112,7 +111,7 @@ class OrderingWorksheet(View):
key = '{0} {1}'.format(brand, product.description) key = '{0} {1}'.format(brand, product.description)
return key return key
now = local_time() now = localtime(self.request.rattail_config)
data = dict( data = dict(
vendor=vendor, vendor=vendor,
costs=costs, costs=costs,
@ -174,7 +173,7 @@ class InventoryWorksheet(View):
q = q.order_by(model.Brand.name, model.Product.description) q = q.order_by(model.Brand.name, model.Product.description)
return q.all() return q.all()
now = local_time() now = localtime(self.request.rattail_config)
data = dict( data = dict(
date=now.strftime('%a %d %b %Y'), date=now.strftime('%a %d %b %Y'),
time=now.strftime('%I:%M %p'), time=now.strftime('%I:%M %p'),

View file

@ -12,12 +12,6 @@ class TestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.config = testing.setUp() self.config = testing.setUp()
# self.config = testing.setUp(settings={
# 'mako.directories': [
# 'rattail.pyramid:templates',
# 'edbob.pyramid:templates',
# ],
# })
def tearDown(self): def tearDown(self):
testing.tearDown() testing.tearDown()
@ -36,34 +30,3 @@ def mock_query():
query.distinct.return_value = query query.distinct.return_value = query
query.order_by.return_value = query query.order_by.return_value = query
return query return query
# class DataTestCase(TestCase):
# """
# Base class for all test suites which require fixture data.
# """
# def setUp(self):
# from sqlalchemy import create_engine
# from edbob import db
# from rattail.pyramid import Session
# from edbob.db.util import install_core_schema
# from edbob.db.extensions import activate_extension
# from rattail.pyramid.tests.fixtures import load_fixtures
# engine = create_engine('postgresql://rattail:1pKglVgdHOP1MYGVdUZr@localhost/rattail.test')
# db.engines = {'default': engine}
# db.engine = engine
# db.Session.configure(bind=engine)
# Session.configure(bind=engine)
# install_core_schema(engine)
# activate_extension('rattail', engine)
# load_fixtures(engine)
# super(DataTestCase, self).setUp()
# # def tearDown(self):
# # from rattail.pyramid import Session
# # super(DataTestCase, self).tearDown()
# # Session.configure(bind=None)