save point
This commit is contained in:
parent
b1e6b12b71
commit
09053698a1
10 changed files with 64 additions and 26 deletions
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
from sqlalchemy import engine_from_config, MetaData
|
from sqlalchemy import engine_from_config, MetaData
|
||||||
from sqlalchemy.orm import sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
from sqlalchemy.ext.declarative import declarative_base
|
||||||
|
|
||||||
import edbob
|
import edbob
|
||||||
|
|
||||||
|
@ -41,6 +42,7 @@ inited = False
|
||||||
engines = None
|
engines = None
|
||||||
engine = None
|
engine = None
|
||||||
Session = sessionmaker()
|
Session = sessionmaker()
|
||||||
|
Base = declarative_base()
|
||||||
# metadata = None
|
# metadata = None
|
||||||
|
|
||||||
|
|
||||||
|
@ -70,7 +72,6 @@ def init(config):
|
||||||
# from edbob.db import classes
|
# from edbob.db import classes
|
||||||
from edbob.db import model
|
from edbob.db import model
|
||||||
from edbob.db import enum
|
from edbob.db import enum
|
||||||
from edbob.db.model import Base
|
|
||||||
# from edbob.db.model import get_metadata
|
# from edbob.db.model import get_metadata
|
||||||
# from edbob.db.mappers import make_mappers
|
# from edbob.db.mappers import make_mappers
|
||||||
# from edbob.db.extensions import extend_framework
|
# from edbob.db.extensions import extend_framework
|
||||||
|
@ -98,7 +99,6 @@ def init(config):
|
||||||
|
|
||||||
engine = engines.get('default')
|
engine = engines.get('default')
|
||||||
if engine:
|
if engine:
|
||||||
Session.configure(bind=engine)
|
|
||||||
Base.metadata.bind = engine
|
Base.metadata.bind = engine
|
||||||
|
|
||||||
# metadata = get_metadata(bind=engine)
|
# metadata = get_metadata(bind=engine)
|
||||||
|
|
|
@ -27,16 +27,14 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from sqlalchemy import Column, String, Text
|
from sqlalchemy import Column, String, Text
|
||||||
from sqlalchemy.ext.declarative import declarative_base
|
|
||||||
|
|
||||||
import edbob
|
import edbob
|
||||||
# from edbob import Object, get_uuid
|
# from edbob import Object, get_uuid
|
||||||
|
from edbob.db import Base
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['ActiveExtension', 'Setting']
|
__all__ = ['ActiveExtension', 'Setting']
|
||||||
|
|
||||||
Base = declarative_base()
|
|
||||||
|
|
||||||
|
|
||||||
# class ClassWithUuid(Object):
|
# class ClassWithUuid(Object):
|
||||||
# """
|
# """
|
||||||
|
|
|
@ -182,11 +182,12 @@ def get_search_config(name, request, filter_map, **kwargs):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
config = {}
|
config = {}
|
||||||
for field in filter_map:
|
|
||||||
config['include_filter_'+field] = False
|
|
||||||
config.update(kwargs)
|
|
||||||
|
|
||||||
def update_config(dict_, prefix='', exclude_by_default=False):
|
def update_config(dict_, prefix='', exclude_by_default=False):
|
||||||
|
"""
|
||||||
|
Updates the ``config`` dictionary based on the contents of ``dict_``.
|
||||||
|
"""
|
||||||
|
|
||||||
for field in filter_map:
|
for field in filter_map:
|
||||||
if prefix+'include_filter_'+field in dict_:
|
if prefix+'include_filter_'+field in dict_:
|
||||||
include = dict_[prefix+'include_filter_'+field]
|
include = dict_[prefix+'include_filter_'+field]
|
||||||
|
@ -199,12 +200,25 @@ def get_search_config(name, request, filter_map, **kwargs):
|
||||||
if prefix+field in dict_:
|
if prefix+field in dict_:
|
||||||
config[field] = dict_[prefix+field]
|
config[field] = dict_[prefix+field]
|
||||||
|
|
||||||
|
# Update config to exclude all filters by default.
|
||||||
|
for field in filter_map:
|
||||||
|
config['include_filter_'+field] = False
|
||||||
|
|
||||||
|
# Update config with defaults from ``kwargs``.
|
||||||
|
config.update(kwargs)
|
||||||
|
|
||||||
|
# Update config with data cached in Beaker session.
|
||||||
update_config(request.session, prefix=name+'.')
|
update_config(request.session, prefix=name+'.')
|
||||||
|
|
||||||
|
# Update config with data from GET/POST request.
|
||||||
if request.params.get('filters'):
|
if request.params.get('filters'):
|
||||||
update_config(request.params, exclude_by_default=True)
|
update_config(request.params, exclude_by_default=True)
|
||||||
|
|
||||||
|
# Cache filter data in Beaker session.
|
||||||
for key in config:
|
for key in config:
|
||||||
if not key.startswith('filter_factory_'):
|
if not key.startswith('filter_factory_'):
|
||||||
request.session[name+'.'+key] = config[key]
|
request.session[name+'.'+key] = config[key]
|
||||||
|
|
||||||
config['request'] = request
|
config['request'] = request
|
||||||
config['filter_map'] = filter_map
|
config['filter_map'] = filter_map
|
||||||
return config
|
return config
|
||||||
|
|
|
@ -44,8 +44,9 @@ from edbob.util import prettify
|
||||||
from edbob.pyramid import Session
|
from edbob.pyramid import Session
|
||||||
|
|
||||||
|
|
||||||
__all__ = ['AlchemyGrid', 'EnumFieldRenderer', 'PrettyDateTimeFieldRenderer',
|
__all__ = ['AlchemyGrid', 'ChildGridField', 'EnumFieldRenderer',
|
||||||
'make_fieldset', 'required']
|
'PrettyDateTimeFieldRenderer', 'make_fieldset', 'required',
|
||||||
|
'pretty_datetime']
|
||||||
|
|
||||||
|
|
||||||
class TemplateEngine(formalchemy.templates.TemplateEngine):
|
class TemplateEngine(formalchemy.templates.TemplateEngine):
|
||||||
|
@ -142,10 +143,10 @@ class AlchemyGrid(formalchemy.Grid):
|
||||||
return field.render()
|
return field.render()
|
||||||
|
|
||||||
def row_attrs(self, i):
|
def row_attrs(self, i):
|
||||||
return format_attrs(
|
attrs = dict(class_='even' if i % 2 else 'odd')
|
||||||
uuid=self.model.uuid,
|
if hasattr(self.model, 'uuid'):
|
||||||
class_='even' if i % 2 else 'odd',
|
attrs['uuid'] = self.model.uuid
|
||||||
)
|
return format_attrs(**attrs)
|
||||||
|
|
||||||
def url_attrs(self):
|
def url_attrs(self):
|
||||||
return format_attrs(url=self.url_grid,
|
return format_attrs(url=self.url_grid,
|
||||||
|
@ -265,6 +266,18 @@ class AlchemyGrid(formalchemy.Grid):
|
||||||
# return ''
|
# return ''
|
||||||
|
|
||||||
|
|
||||||
|
class ChildGridField(formalchemy.Field):
|
||||||
|
"""
|
||||||
|
Convenience class for including a child grid within a fieldset as a
|
||||||
|
read-only field.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, name, value, *args, **kwargs):
|
||||||
|
super(ChildGridField, self).__init__(name, *args, **kwargs)
|
||||||
|
self.set(value=value)
|
||||||
|
self.set(readonly=True)
|
||||||
|
|
||||||
|
|
||||||
def make_fieldset(model, **kwargs):
|
def make_fieldset(model, **kwargs):
|
||||||
kwargs.setdefault('session', Session())
|
kwargs.setdefault('session', Session())
|
||||||
return FieldSet(model, **kwargs)
|
return FieldSet(model, **kwargs)
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from sqlalchemy.orm import Query
|
from sqlalchemy.orm import Query
|
||||||
|
from sqlalchemy.orm.attributes import InstrumentedAttribute
|
||||||
|
|
||||||
from pyramid.renderers import render
|
from pyramid.renderers import render
|
||||||
from pyramid.response import Response
|
from pyramid.response import Response
|
||||||
|
@ -151,12 +152,19 @@ def get_pager(query, config):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_sort_map(cls, names, **kwargs):
|
def get_sort_map(cls, names=None, **kwargs):
|
||||||
"""
|
"""
|
||||||
Convenience function which returns a sort map.
|
Convenience function which returns a sort map.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
smap = {}
|
smap = {}
|
||||||
|
if names is None:
|
||||||
|
names = []
|
||||||
|
for attr in cls.__dict__:
|
||||||
|
obj = getattr(cls, attr)
|
||||||
|
if isinstance(obj, InstrumentedAttribute):
|
||||||
|
if obj.key != 'uuid':
|
||||||
|
names.append(obj.key)
|
||||||
for name in names:
|
for name in names:
|
||||||
smap[name] = sorter(getattr(cls, name))
|
smap[name] = sorter(getattr(cls, name))
|
||||||
smap.update(kwargs)
|
smap.update(kwargs)
|
||||||
|
|
|
@ -257,7 +257,8 @@ div.grid table {
|
||||||
border-top: 1px solid black;
|
border-top: 1px solid black;
|
||||||
border-left: 1px solid black;
|
border-left: 1px solid black;
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
font-size: 90%;
|
font-size: 9pt;
|
||||||
|
line-height: normal;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
@ -356,7 +357,8 @@ div.pager p.page-links {
|
||||||
|
|
||||||
div.field-couple {
|
div.field-couple {
|
||||||
clear: both;
|
clear: both;
|
||||||
margin-bottom: 10px;
|
overflow: auto;
|
||||||
|
min-height: 30px;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.field-couple div.label,
|
div.field-couple div.label,
|
||||||
|
|
|
@ -165,10 +165,11 @@ $(function() {
|
||||||
div.find('button[type=reset]').show();
|
div.find('button[type=reset]').show();
|
||||||
});
|
});
|
||||||
|
|
||||||
$('div.filters form').live('submit', function() {
|
$('div.filterset form').live('submit', function() {
|
||||||
var div = $(this).parents('table.search-wrapper').next();
|
var div = $('div.grid:first');
|
||||||
|
var data = $(this).serialize() + '&partial=true';
|
||||||
loading(div);
|
loading(div);
|
||||||
$.post(div.attr('url'), $(this).serialize(), function(data) {
|
$.post(div.attr('url'), data, function(data) {
|
||||||
div.replaceWith(data);
|
div.replaceWith(data);
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -49,11 +49,13 @@
|
||||||
## % endfor
|
## % endfor
|
||||||
## </div>
|
## </div>
|
||||||
## % endif
|
## % endif
|
||||||
## <div id="flash-messages">
|
% if request.session.peek_flash():
|
||||||
## %for message in request.session.pop_flash():
|
<div id="flash-messages">
|
||||||
## <div class="flash-message">${message}</div>
|
% for msg in request.session.pop_flash():
|
||||||
## %endfor
|
<div class="flash-message">${msg|n}</div>
|
||||||
## </div>
|
% endfor
|
||||||
|
</div>
|
||||||
|
% endif
|
||||||
${self.body()}
|
${self.body()}
|
||||||
</div><!-- body -->
|
</div><!-- body -->
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<div class="filterset">
|
<div class="filterset">
|
||||||
${search.begin()}
|
${search.begin()}
|
||||||
|
${search.hidden('filters', True)}
|
||||||
<% visible = [] %>
|
<% visible = [] %>
|
||||||
% for f in search.sorted_filters():
|
% for f in search.sorted_filters():
|
||||||
<% f = search.filters[f] %>
|
<% f = search.filters[f] %>
|
||||||
|
|
|
@ -105,7 +105,6 @@ def crud(request, cls, fieldset_factory, home=None, delete=None, post_sync=None,
|
||||||
# return HTTPFound(location=self.request.route_url(objects, action='index'))
|
# return HTTPFound(location=self.request.route_url(objects, action='index'))
|
||||||
|
|
||||||
if not fs.readonly and request.POST:
|
if not fs.readonly and request.POST:
|
||||||
# print self.request.POST
|
|
||||||
fs.rebind(data=request.params)
|
fs.rebind(data=request.params)
|
||||||
if fs.validate():
|
if fs.validate():
|
||||||
with transaction.manager:
|
with transaction.manager:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue