def _jsonValues( self, nodes, fields, context):
     """
     filter values from the nodes to respresent in json, currently
     that means some footwork around, probably better as another
     set of adapters.
     """
     values = []
     domain_model = proxy.removeSecurityProxy( context.domain_model )
     domain_interface = queryModelInterface( domain_model )
     domain_annotation = queryModelDescriptor( domain_interface )
     for n in nodes:
         d = {}
         # field to dictionaries
         for field in fields:
             f = field.__name__
             getter = field.query
             for anno_field in domain_annotation.fields:
                 if anno_field.name == f:
                     if getattr(anno_field.listing_column, 'getter', None):
                         getter=anno_field.listing_column.getter
                         d[ f ] = v = getter( n , field)
                     else:
                         d[ f ] = v = field.query( n )
             if isinstance( v, datetime.datetime ):
                 d[f] = v.strftime('%F %I:%M %p')
             elif isinstance( v, datetime.date ):
                 d[f] = v.strftime('%F')
             d['object_id'] =   stringKey(n)
         values.append( d )
     return values
 def _jsonValues(self, nodes, fields, context):
     """
     filter values from the nodes to respresent in json, currently
     that means some footwork around, probably better as another
     set of adapters.
     """
     values = []
     domain_model = proxy.removeSecurityProxy(context.domain_model)
     domain_interface = queryModelInterface(domain_model)
     domain_annotation = queryModelDescriptor(domain_interface)
     for n in nodes:
         d = {}
         # field to dictionaries
         for field in fields:
             f = field.__name__
             getter = field.query
             for anno_field in domain_annotation.fields:
                 if anno_field.name == f:
                     if getattr(anno_field.listing_column, 'getter', None):
                         getter = anno_field.listing_column.getter
                         d[f] = v = getter(n, field)
                     else:
                         d[f] = v = field.query(n)
             if isinstance(v, datetime.datetime):
                 d[f] = v.strftime('%F %I:%M %p')
             elif isinstance(v, datetime.date):
                 d[f] = v.strftime('%F')
             d['object_id'] = stringKey(n)
         values.append(d)
     return values
Exemple #3
0
 def __init__( self, **kw ):
     
     domain_schema = model.queryModelInterface( self.__class__ )
     known_names = [ k for k,d in domain_schema.namesAndDescriptions(1)]
     
     for k,v in kw.items():
         if k in known_names:
             setattr( self, k, v)
Exemple #4
0
    def __init__(self, **kw):

        domain_schema = model.queryModelInterface(self.__class__)
        known_names = [k for k, d in domain_schema.namesAndDescriptions(1)]

        for k, v in kw.items():
            if k in known_names:
                setattr(self, k, v)
 def _get_anno_getters_by_field_name(self, context):
     domain_model = proxy.removeSecurityProxy(context.domain_model)
     domain_interface = queryModelInterface(domain_model)
     domain_annotation = queryModelDescriptor(domain_interface)
     # dict of domain_annotation field getters by name, for fast lookup
     return dict([ 
         (da_field.name, getattr(da_field.listing_column, "getter", None)) 
         for da_field in domain_annotation.fields
     ])
Exemple #6
0
def getFields(context):
    domain_model = proxy.removeSecurityProxy(context.domain_model)
    domain_interface = queryModelInterface(domain_model)
    field_names = schema.getFieldNamesInOrder(domain_interface)
    for f in field_names:
        field = domain_interface[f]
        if isinstance(field, (schema.Choice, schema.Object, schema.List, schema.Tuple, schema.Bytes)):
            continue
        yield field
def getFields( context ):
    domain_model = proxy.removeSecurityProxy( context.domain_model )
    domain_interface = queryModelInterface( domain_model )
    field_names = schema.getFieldNamesInOrder( domain_interface )
    for f in field_names:
        field = domain_interface[ f ]
        if isinstance( field,  ( schema.Choice, schema.Object,
                                 schema.List, schema.Tuple, schema.Bytes ) ):
            continue
        yield field
def getFields( context ):
    """ get all fields that will be displayed 
    in a containerlisting 
    """
    domain_model = proxy.removeSecurityProxy( context.domain_model )
    domain_interface = queryModelInterface( domain_model )
    domain_annotation = queryModelDescriptor( domain_interface )
    for column in  domain_annotation.listing_columns:
        field = domain_interface[column]
        yield field
Exemple #9
0
def getFields(context, interface=None, annotation=None):
    """Generator of all fields that will be displayed in a containerlisting 
    """
    if interface is None:
        model = proxy.removeSecurityProxy(context.domain_model)
        interface = queryModelInterface(model)
    if annotation is None:
        annotation = queryModelDescriptor(interface)
    for column in annotation.listing_columns:
        yield interface[column]
def getFields(context, interface=None, annotation=None):
    """Generator of all fields that will be displayed in a containerlisting 
    """
    if interface is None: 
        model = proxy.removeSecurityProxy(context.domain_model)
        interface = queryModelInterface(model)
    if annotation is None:
        annotation = queryModelDescriptor(interface)
    for column in annotation.listing_columns:
        yield interface[column]
 def __init__(self, context, request):
     super(ContainerBrowserView, self).__init__(context, request)
     self.domain_model = proxy.removeSecurityProxy(self.context).domain_model
     self.domain_interface = queryModelInterface(self.domain_model)
     self.domain_annotation = queryModelDescriptor(self.domain_interface)
     self.fields = tuple(getFields(
         self.context, self.domain_interface, self.domain_annotation))
     self.defaults_sort_on = getattr(self.domain_model, "sort_on", None)
     self.default_sort_dir = getattr(self.domain_model, "sort_dir", "desc")
     self.sort_dir = self.request.get("dir", self.default_sort_dir)
Exemple #12
0
def getFields(context):
    """ get all fields that will be displayed 
    in a containerlisting 
    """
    domain_model = proxy.removeSecurityProxy(context.domain_model)
    domain_interface = queryModelInterface(domain_model)
    domain_annotation = queryModelDescriptor(domain_interface)
    for column in domain_annotation.listing_columns:
        field = domain_interface[column]
        yield field
Exemple #13
0
 def __init__(self, context, request):
     super(ContainerBrowserView, self).__init__(context, request)
     self.domain_model = proxy.removeSecurityProxy(
         self.context).domain_model
     self.domain_interface = queryModelInterface(self.domain_model)
     self.domain_annotation = queryModelDescriptor(self.domain_interface)
     self.fields = tuple(
         getFields(self.context, self.domain_interface,
                   self.domain_annotation))
     self.defaults_sort_on = getattr(self.domain_model, "sort_on", None)
     self.default_sort_dir = getattr(self.domain_model, "sort_dir", "desc")
     self.sort_dir = self.request.get("dir", self.default_sort_dir)
def setUpColumns( domain_model ):
    """
    use model descriptor on domain model extract columns for table listings
    """
    columns = []
    domain_interface = model.queryModelInterface( domain_model )

    if not domain_interface:
        raise SyntaxError("Model must have domain interface %r"%(domain_model ) )

    domain_annotation = model.queryModelDescriptor( domain_interface )
    
    field_column_names = domain_annotation and domain_annotation.listing_columns \
                         or schema.getFieldNamesInOrder( domain_interface )

    # quick hack for now, dates are last in listings
    remainder = []
    
    for field_name in field_column_names:
        if not field_name in domain_interface:
            # we can specify additional columns for tables that are not present in the
            # the interface, iff they are fully spec'd as columns in the descriptor/annotation
            if domain_annotation \
                and field_name in domain_annotation \
                    and domain_annotation[ field_name ].listing_column:
                pass
            else:
                #print "bad field, container", field_name, domain_interface.__name__
                continue
            
        info = domain_annotation and domain_annotation.get( field_name ) or None
        
        if info is not None and info.listing_column:
            columns.append(
                info.listing_column
                )
            continue

        field = domain_interface[ field_name ]
        
        if isinstance( field, schema.Datetime ):
            remainder.append( 
                column.GetterColumn( title=field.title or field.__name__,
                                     getter=DateGetter( field.query ) )
                )
            continue
        columns.append(
            column.GetterColumn( title= ( field.title or field.__name__ ),
                                 getter = Getter( field.query ) )
            )
    columns.extend( remainder )
    return columns
Exemple #15
0
    def __init__(self, **kw):
        try:
            domain_schema = model.queryModelInterface(self.__class__)
            known_names = [k for k, d in domain_schema.namesAndDescriptions(1)]
        except:
            known_names = None

        for k, v in kw.items():
            if known_names is None or k in known_names:
                setattr(self, k, v)
            else:
                log.warn("Invalid attribute on %s %s" %
                         (self.__class__.__name__, k))
Exemple #16
0
    def __init__(self, **kw):
        try:
            domain_schema = model.queryModelInterface(self.__class__)
            known_names = [k for k, d in domain_schema.namesAndDescriptions(1)]
        except:
            known_names = None

        for k, v in kw.items():
            if known_names is None or k in known_names:
                setattr(self, k, v)
            else:
                log.warn(
                    "Invalid attribute on %s %s" % (
                        self.__class__.__name__, k))
Exemple #17
0
 def defineIndexes(self, indexer):
     """
     define field indexes on the catalog at app server startup (note, xapian 
     doesn't allow for changing field definitions without reindexing) ... 
     see sync index script.
     """
     content_schema = model.queryModelInterface(self.domain_model)
     if interfaces.ENABLE_LOGGING: log.debug('generating indexing schema %r'%content_schema)
     for field in schema.getFields(content_schema).values():
         if field.__name__ in self.action_fields:
             continue
         if not isinstance(field, (schema.Text, schema.ASCII)):
             continue
         if interfaces.ENABLE_LOGGING: log.info(" indexing field %s"%field.__name__)
         indexer.add_field_action(
             field.__name__, xappy.FieldActions.INDEX_FREETEXT, language='en')
Exemple #18
0
 def defineIndexes(self, indexer):
     """
     define field indexes on the catalog at app server startup (note, xapian 
     doesn't allow for changing field definitions without reindexing) ... 
     see sync index script.
     """
     content_schema = model.queryModelInterface(self.domain_model)
     if interfaces.ENABLE_LOGGING: log.debug('generating indexing schema %r'%content_schema)
     for field in schema.getFields(content_schema).values():
         if field.__name__ in self.action_fields:
             continue
         if not isinstance(field, (schema.Text, schema.ASCII)):
             continue
         if interfaces.ENABLE_LOGGING: log.info(" indexing field %s"%field.__name__)
         indexer.add_field_action(
             field.__name__, xappy.FieldActions.INDEX_FREETEXT, language='en')
def setUpFields( domain_model, mode ):
    """
    setup form fields for add/edit/view/search modes, with custom widgets
    enabled from model descriptor. this expects the domain model and mode
    passed in and will return a form.Fields instance
    """
    
    domain_model = removeSecurityProxy( domain_model )
    t = time.time()

    domain_interface = model.queryModelInterface( domain_model )
    domain_annotation = model.queryModelDescriptor( domain_interface )

    search_mode = mode == 'search'

    if not domain_annotation:
        if search_mode:
            form_fields = form.Fields( *setUpSearchFields( domain_interface ) )
        else:
            form_fields = form.Fields( domain_interface )
        return form_fields

    fields = []
    columns = getattr( domain_annotation, '%s_columns'%mode )
    

    
    for field_info in columns:
        if not field_info.name in domain_interface:
            #print "bad field", field_info.name, domain_interface.__name__
            continue
        custom_widget = getattr( field_info, "%s_widget"%mode )
        if search_mode:
            fields.append(
                form.Field( setUpSearchField( domain_interface[ field_info.name ] ),
                            custom_widget = custom_widget )
                )
        else:
            fields.append(
                form.Field( domain_interface[ field_info.name ],
                            custom_widget = custom_widget )
                )
    form_fields = form.Fields( *fields )
    #print "field setup cost", time.time()-t    
    return form_fields
Exemple #20
0
 def __call__(self):
     context = proxy.removeSecurityProxy(self.context)
     self.domain_model = context.domain_model
     self.domain_interface = queryModelInterface(self.domain_model)
     self.domain_annotation = queryModelDescriptor(self.domain_interface)
     session = Session()
     self.set_size = 0
     self.fields = list(getFields(self.context))
     start, limit = self.getOffsets()
     batch = self.getBatch(start, limit)
     data = dict(length=self.set_size,
                 start=start,
                 recordsReturned=len(batch),
                 sort=self.request.get('sort'),
                 dir=self.request.get('dir', "asc"),
                 nodes=batch)
     session.close()
     return simplejson.dumps(data)
 def __call__( self ):
     context = proxy.removeSecurityProxy( self.context )
     self.domain_model = context.domain_model
     self.domain_interface = queryModelInterface( self.domain_model )
     self.domain_annotation = queryModelDescriptor( self.domain_interface )
     session = Session()
     self.set_size = 0
     self.fields = list( getFields( self.context )  )
     start, limit = self.getOffsets( )
     batch = self.getBatch( start, limit)
     data = dict( length=self.set_size,
                  start=start,
                  recordsReturned=len(batch),
                  sort = self.request.get('sort'),
                  dir  = self.request.get('dir', "asc"),
                  nodes=batch )
     session.close()
     return simplejson.dumps( data )
Exemple #22
0
def setUpColumns(domain_model):
    """
    use model descriptor on domain model extract columns for table listings
    """
    columns = []
    domain_interface = model.queryModelInterface(domain_model)

    if not domain_interface:
        raise SyntaxError("Model must have domain interface %r" % (domain_model))

    domain_annotation = model.queryModelDescriptor(domain_interface)

    field_column_names = (
        domain_annotation and domain_annotation.listing_columns or schema.getFieldNamesInOrder(domain_interface)
    )

    # quick hack for now, dates are last in listings
    remainder = []

    for field_name in field_column_names:
        if not field_name in domain_interface:
            # we can specify additional columns for tables that are not present in the
            # the interface, iff they are fully spec'd as columns in the descriptor/annotation
            if domain_annotation and field_name in domain_annotation and domain_annotation[field_name].listing_column:
                pass
            else:
                # print "bad field, container", field_name, domain_interface.__name__
                continue

        info = domain_annotation and domain_annotation.get(field_name) or None

        if info is not None and info.listing_column:
            columns.append(info.listing_column)
            continue

        field = domain_interface[field_name]

        if isinstance(field, schema.Datetime):
            remainder.append(column.GetterColumn(title=field.title or field.__name__, getter=DateGetter(field.query)))
            continue
        columns.append(column.GetterColumn(title=(field.title or field.__name__), getter=Getter(field.query)))
    columns.extend(remainder)
    return columns
Exemple #23
0
def setUpFields(domain_model, mode):
    """
    setup form fields for add/edit/view/search modes, with custom widgets
    enabled from model descriptor. this expects the domain model and mode
    passed in and will return a form.Fields instance
    """

    domain_model = removeSecurityProxy(domain_model)
    t = time.time()

    domain_interface = model.queryModelInterface(domain_model)
    domain_annotation = model.queryModelDescriptor(domain_interface)

    search_mode = mode == "search"

    if not domain_annotation:
        if search_mode:
            form_fields = form.Fields(*setUpSearchFields(domain_interface))
        else:
            form_fields = form.Fields(domain_interface)
        return form_fields

    fields = []
    columns = getattr(domain_annotation, "%s_columns" % mode)

    for field_info in columns:
        if not field_info.name in domain_interface:
            # print "bad field", field_info.name, domain_interface.__name__
            continue
        custom_widget = getattr(field_info, "%s_widget" % mode)
        if search_mode:
            fields.append(form.Field(setUpSearchField(domain_interface[field_info.name]), custom_widget=custom_widget))
        else:
            fields.append(form.Field(domain_interface[field_info.name], custom_widget=custom_widget))
    form_fields = form.Fields(*fields)
    # print "field setup cost", time.time()-t
    return form_fields
Exemple #24
0
def provideRecorder( klass, change_table ):
    domain_interface = queryModelInterface( klass )
    recorder = type( "%sChangeRecorder"%(klass.__name__),
                     (ChangeRecorder,),
                     {'change_table':change_table} )
    component.provideAdapter( recorder, (domain_interface,), (interfaces.IRecorder,))