예제 #1
0
def grid_panel(context, request, data):
    model_class = data['model_class']
    grid = Grid(model_class, instances=data['items'])

    fields = []
    for column in data['columns']:
        field = column.field or grid._fields.get(column.name)
        if field is None:
            # field = AttributeField(getattr(model_class, column.name), grid)
            field = Field(column.name, fatypes.String)
        field.set(label=column.label)
        fields.append(field)

    # def checkbox(item):
    #     return u"""<input type="checkbox" name="_check" value="%d" />""" % item.id
    # field = Field('check', fatypes.String, checkbox, label=u"")
    # grid.insert(grid["id"], field)
    # fields.insert(0, field)

    model_name = data['model_name']
    def edit_link(item):
        url = request.route_url('admin_edit', model=model_name, id=item.id)
        return EDIT_LINK_TEMPLATE % dict(url=url, label='Edit')
    field = Field('edit', fatypes.String, edit_link)
    grid.append(field)
    fields.append(field)

    grid.configure(pk=1, include=fields)

    return {"grid": grid, "request": request}
예제 #2
0
 def render(self, lang=None):
     if self.readonly:
         html = pretty_html(DefaultGrid.render(self))
         for name, engine in templates.engines.items():
             if isinstance(engine, config.engine.__class__):
                 continue
             html_engine = pretty_html(engine('grid_readonly', collection=self))
             assert html == html_engine, (name, html, html_engine)
         return html
     html = pretty_html(DefaultGrid.render(self))
     for name, engine in templates.engines.items():
         if isinstance(engine, config.engine.__class__):
             continue
         html_engine = pretty_html(engine('grid', collection=self))
         assert html == html_engine, (name, html, html_engine)
     return html
예제 #3
0
 def render(self, lang=None):
     if self.readonly:
         html = pretty_html(DefaultGrid.render(self))
         for name, engine in templates.engines.items():
             if isinstance(engine, config.engine.__class__):
                 continue
             html_engine = pretty_html(
                 engine('grid_readonly', collection=self))
             assert html == html_engine, (name, html, html_engine)
         return html
     html = pretty_html(DefaultGrid.render(self))
     for name, engine in templates.engines.items():
         if isinstance(engine, config.engine.__class__):
             continue
         html_engine = pretty_html(engine('grid', collection=self))
         assert html == html_engine, (name, html, html_engine)
     return html
예제 #4
0
from civicboom import model

from formalchemy.tables import Grid

## Initialize grids
# Not doing this will result in the object list being rendered with
# all fields visible

#FooGrid = Grid(model.Foo)
#ReflectedGrid = Grid(Reflected)

ContentGrid = Grid(model.Content)
ContentGrid.configure(include=[
    ContentGrid.title,
    ContentGrid.creator,
    ContentGrid.update_date.readonly(),
    #ContentGrid.status,
])

ArticleContentGrid = Grid(model.ArticleContent)
ArticleContentGrid.configure(include=[
    ArticleContentGrid.title,
    ArticleContentGrid.creator,
    ArticleContentGrid.update_date.readonly(),
    #ArticleContentGrid.status,
    ArticleContentGrid.attachments.readonly(),
    ArticleContentGrid.tags.readonly(),
])

AssignmentContentGrid = Grid(model.AssignmentContent)
AssignmentContentGrid.configure(include=[
예제 #5
0
from formalchemy.forms import FieldSet
from formalchemy.tables import Grid

from cyberweb import model
from cyberweb.model import meta

## Initialize fieldsets
Group = FieldSet(model.Group)
Group.configure(pk=False,
                exclude=[Group.messages_by_group]
                )

GroupAdd = FieldSet(model.Group)
GroupAdd.configure(pk=False,
                exclude=[GroupAdd.messages_by_group]
                )
## Initialize grids
GroupGrid = Grid(model.Group)
GroupGrid.configure(pk=False,
                exclude=[GroupGrid.messages_by_group]
                )
예제 #6
0
from formalchemy.forms import FieldSet
from formalchemy.tables import Grid

from cyberweb import model
from cyberweb.model import meta

## Initialize fieldsets
QueueInfo = FieldSet(model.QueueInfo)
QueueInfo.configure(pk=False,
                exclude=[QueueInfo.timestamp]
                )

QueueInfoAdd = FieldSet(model.QueueInfo)
QueueInfoAdd.configure(pk=False,
                exclude=[QueueInfoAdd.timestamp]
                )
## Initialize grids
QueueInfoGrid = Grid(model.QueueInfo)
QueueInfoGrid.configure(pk=False,
                exclude=[QueueInfoGrid.timestamp]
                )
예제 #7
0
from formalchemy.tables import Grid

from cyberweb import model
from cyberweb.model import meta

group_definitions = []
for i in meta.Session.query(model.GroupDefinition).all():
    group_definitions.append((i.name,i.id))
    
## Initialize fieldsets
User = FieldSet(model.User)
User.configure(pk=False,
                options=[User.groups.dropdown(options=group_definitions)],
                exclude=[User.password,User.last_login_date,User.created,User.last_login_ip,User.messages_sent,User.messages_by_user]
                )

UserAdd = FieldSet(model.User)
UserAdd.configure(pk=False,
                options=[UserAdd.groups.dropdown(options=group_definitions),
                         UserAdd.verified.checkbox()],
                exclude=[UserAdd.verified,UserAdd.password,UserAdd.last_login_date,UserAdd.created,UserAdd.last_login_ip,UserAdd.messages_sent,UserAdd.messages_by_user]
                )
## Initialize grids
group_definitions = []
for i in model.meta.Session.query(model.GroupDefinition).all():
    group_definitions.append((i.id,i.name))
UserGrid = Grid(model.User)
UserGrid.configure(pk=False,
                options=[UserGrid.groups.dropdown(options=group_definitions)],
                exclude=[UserGrid.password,UserGrid.last_login_date,UserGrid.created,UserGrid.last_login_ip,UserGrid.messages_sent,UserGrid.messages_by_user]
                )
예제 #8
0
from formalchemy.forms import FieldSet
from formalchemy.tables import Grid

from cyberweb import model
from cyberweb.model import meta

## Initialize fieldsets
Service = FieldSet(model.Service)
Service.configure(pk=False, exclude=[Service.timestamp])

ServiceAdd = FieldSet(model.Service)
ServiceAdd.configure(pk=False, exclude=[ServiceAdd.timestamp])
## Initialize grids
ServiceGrid = Grid(model.Service)
ServiceGrid.configure(pk=False, exclude=[ServiceGrid.timestamp])
예제 #9
0
from formalchemy.forms import FieldSet
from formalchemy.tables import Grid

from cyberweb import model
from cyberweb.model import meta

## Initialize fieldsets
GroupDefinition = FieldSet(model.GroupDefinition)
GroupDefinition.configure(pk=False,
                exclude=[GroupDefinition.members]
                )

GroupDefinitionAdd = FieldSet(model.GroupDefinition)
GroupDefinitionAdd.configure(pk=False,
                exclude=[GroupDefinitionAdd.members]
                )
## Initialize grids
GroupDefinitionGrid = Grid(model.GroupDefinition)
GroupDefinitionGrid.configure(pk=False,
                exclude=[GroupDefinitionGrid.members]
                )
예제 #10
0
from pylons import config
from formalchemy.forms import FieldSet
from formalchemy.tables import Grid

from cyberweb import model
from cyberweb.model import meta

users = []
for i in meta.Session.query(model.User).all():
    users.append((i.username,i.id))

Account = FieldSet(model.Account)
Account.configure(pk=False,
                      exclude=[Account.insert_date]
                     )

AccountAdd = FieldSet(model.Account)
AccountAdd.configure(pk=False,
                      exclude=[AccountAdd.insert_date]
                     )
## Initialize grids
AccountGrid = Grid(model.Account)
AccountGrid.configure(pk=False,
                      options=[AccountGrid.user.dropdown(options=users)],
                      exclude=[AccountGrid.authkey,AccountGrid.password,AccountGrid.insert_date]
                     )