示例#1
0
def getFields(context, interface=None, annotation=None):
    """Generator of all [zope.schema] fields that will be displayed in a 
    container listing.
    
    Redefines alchemist.ui.container.getFields, making use of the 
    @listing_columns property of the ModelDescriptor class.
    """
    if interface is None:
        domain_model = proxy.removeSecurityProxy(context.domain_model)
        interface = utils.get_derived_table_schema(domain_model)
    if annotation is None:
        annotation = utils.get_descriptor(interface)
    for field_name in annotation.listing_columns:
        yield interface[field_name]
示例#2
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 = utils.get_derived_table_schema(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')
示例#3
0
def setUpColumns(domain_model):
    """Use model descriptor on domain model extract columns for table listings
    """
    columns = []
    table_schema = utils.get_derived_table_schema(domain_model)
    if not table_schema:
        raise SyntaxError("Model must have domain interface %r" % (domain_model))
    descriptor_model = utils.get_descriptor(table_schema)
    
    field_column_names = \
        descriptor_model and descriptor_model.listing_columns \
        or schema.getFieldNamesInOrder(table_schema)

    # quick hack for now, dates are last in listings
    remainder = []
    
    for field_name in field_column_names:
        if not field_name in table_schema:
            # 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 (descriptor_model and 
                    field_name in descriptor_model.fields_by_name and 
                    descriptor_model.get(field_name).listing_column
                ):
                pass
            else:
                print "bad field, container", field_name, table_schema.__name__
                continue
        
        info = descriptor_model and descriptor_model.get(field_name) or None
        
        if info is not None and info.listing_column:
            columns.append(info.listing_column)
            continue
        
        field = table_schema[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
示例#4
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 formlib.form.Fields instance
    """
    domain_model = removeSecurityProxy(domain_model)
    #import time
    #t = time.time()
    table_schema = utils.get_derived_table_schema(domain_model)
    descriptor_model = utils.get_descriptor(table_schema)
    
    search_mode = mode == "search"
    
    if not descriptor_model:
        if search_mode:
            form_fields = formlib.form.Fields(*setUpSearchFields(table_schema))
        else:
            form_fields = formlib.form.Fields(table_schema)
        return form_fields
    
    fields = []
    columns = getattr(descriptor_model, "%s_columns" % mode)
    
    for field_info in columns:
        if not field_info.name in table_schema:
            #print "bad field", field_info.name, table_schema.__name__
            continue
        custom_widget = getattr(field_info, "%s_widget" % mode)
        if search_mode:
            fields.append(formlib.form.Field(
                    setUpSearchField(table_schema[field_info.name]),
                    custom_widget=custom_widget))
        else:
            fields.append(formlib.form.Field(
                    table_schema[field_info.name],
                    custom_widget=custom_widget))
    form_fields = formlib.form.Fields(*fields)
    #print "field setup cost", time.time()-t    
    return form_fields
示例#5
0
            result[property.key] = value
    
    for prop_name, prop_type in obj.__class__.extended_properties:
        try:
            result[prop_name] = getattr(obj, prop_name)
        except zope.security.interfaces.NoInteraction:
            log.error("Extended property %s requires an interaction.",
                prop_name)

    
    # any additional attributes - this allows us to capture any derived attributes
    if IAlchemistContent.providedBy(obj):
        seen_keys = ( [ prop.key for prop in mapper.iterate_properties ] + 
            include + exclude)
        try:
            domain_schema = utils.get_derived_table_schema(type(obj))
            known_names = [ k for k, d in 
                domain_schema.namesAndDescriptions(all=True) ]
            extra_properties = set(known_names).difference(set(seen_keys))
            for prop_name in extra_properties:
                try:
                    result[prop_name] = getattr(obj, prop_name)
                except zope.security.interfaces.NoInteraction:
                    log.error("Attribute %s requires an interaction.",
                        prop_name)

        except KeyError:
            log.warn("Could not find table schema for %s", obj)
    
    return result