Example #1
0
    def set_value( me, context, fieldname, value, do_get_check =True, next_adr =None, **kargs):
        #if fieldname not in me.field_map: return
        if me._DBG_set_value: print '\n set %s ?= %r' % (fieldname, value)
        model = me.model
        if do_get_check:
            try:
                oldvalue = get_attrib( model, fieldname)
            except AttributeError:
                e = me.ERR_not_in_model % fieldname
                print e
                return
#        if next_adr: print 'focusto', next_adr
        me.focus = next_adr or fieldname        #before set - if exception, focus goes to error field
        set_attrib( model, fieldname, value)
        if me._DBG_set_value: print ' --> %s == %r' % (fieldname, get_attrib( model, fieldname))
Example #2
0
def set_container_data( container, data_obj, description, context, **kargs):
    for name, fld in description.iteritems():
        if issubclass( fld.typ, Spravka):
            subrep = isinstance( fld.setup, dict) and fld.typ( **fld.setup) or fld.typ()
            if callable( fld.setup):
                fld.setup( container, subrep)
            o = data_obj
            if fld.model:
                o = get_attrib( data_obj, fld.model)
            subrep.refresh( context, container, o, **kargs)
            setattr( container, name, subrep)
        elif fld.model:
            try: value = get_attrib( data_obj, fld.model)
            except AttributeError:
                value = None
                print container.__class__.__name__, '''
warning: query obj has no attr "%s"''' % fld.model
            setattr( container, name, value)
Example #3
0
    def dereference( me, namespace):
        src_obj = namespace[ me.src_key]
        if isinstance( src_obj, LinkBase):
            src_obj = src_obj.dereference( namespace)

        if me.attr_name:
            res = get_attrib( src_obj, me.attr_name)
            if isinstance( res, LinkBase):
                return res.dereference( namespace)
            return res
        return src_obj
Example #4
0
 def get_default( me, attr_name, view =None, default =None):
     # FIXME тука що търся във view след като неговите defaults са му сетнати
     # още след наследяванията
     # layout_defaults явно не е за атрибути на view-то а само за страничните неща margins etc.
     last_name = attr_name.split('.')[-1]
     spr_defaults = getattr( me.spr, 'layout_defaults', {})
     res = spr_defaults.get( last_name)
     if res is None and view:
         res = get_attrib( view, attr_name)
     if res is None:
         res = default
     return res
Example #5
0
 def get_value( me, fieldname, err =None, do_err =True):
     model = me.model
     #print ' get %s in %s' % (fieldname, model)
     try:
         value = get_attrib( model, fieldname)
     except AttributeError:
         e = me.ERR_not_in_model % fieldname
         if do_err:
             print e
         if err is not None:
             err.append( e)
         value = me._DEFAULT_get_value
     else:
         if value is notSetYet: value = me._DEFAULT_get_value
     return value
Example #6
0
 def __getitem__( me, k):
     try:
         return me.o.__dict__[k]
     except KeyError:
         #this to return None ONLY on last .attr; else it's a null
         # inbetween -> error to catch and ignore the whole thing
         kk = k.split('.')
         if len(kk)>1:
             try:
                 g = get_attrib( me.o, '.'.join( kk[:-1]))
             except AttributeError:
                 raise AttrWrapError, k
             if g is None:
                 raise AttrWrapError, k
         else:
             g = me.o
         return getattr( g, kk[-1], None)
Example #7
0
 def eval( me, name):
     context = me.context
     def attr_getter( self, name):
         attr = getattr( self, name)
         return calc_by_context( attr, context)
     return get_attrib( me, name, getattr=attr_getter)
Example #8
0
 def name( me):
     home = str( get_attrib( me, 'home.num', 'none'))
     return str( getattr( me, 'street','none')) +'#'+ home
Example #9
0
 def column( me, name):
     return [ get_attrib( r, name) for r in me.rows ]
Example #10
0
def panel4Struct( panel, model, typ,
        name_leaf='',
        fullname ='',    #model's pfx/name in view
        readonly =False,
        is_root  =True,
        make_panel =make_panel4Struct,
        fields2ignore = None,
        extract_one_fld_panel = False,
        translator=None,
        attr_order=None,
        **kargs_ignore
    ):

    pfx = fullname and fullname+'.' or ''
    mtyp = typ
    attr_order = attr_order or list( mtyp._order_Statics(items=False))
    for name in attr_order:
        if fields2ignore and name in fields2ignore:
            continue
        typ = mtyp.StaticType[name]
        try:
            typ = typ.StaticType_alt
            fullname = pfx + typ.name
        except AttributeError:
            fullname = pfx + name

        if getattr( typ, 'meta', None): continue
        if getattr( typ, 'UI_hide', None): continue
        my_readonly = readonly
        optional = getattr( typ, 'optional', None)
        if optional:
            opt_name = optional.name
            on = get_attrib( model, opt_name, None)    #True - on by default
            item_name = not on and HIDE_OPTIONAL_OFF and name or '' #item's name at least
            opt_fullname = pfx+opt_name
            panel_opt = Panel( '[_ %(opt_fullname)s] %(item_name)s' % locals(),
                                { opt_fullname: dict( label='', width=30) },
                            )
            panel += panel_opt
            my_readonly = my_readonly or not on
            if not on and HIDE_OPTIONAL_OFF:      #without this, optional is visible but readonly
                continue
        m = None
        if getattr( typ, 'non_atomary', None): m = getattr( model, name, None)
        p = _panel4any( model= m,
                        typ  = typ,
                        fullname=   fullname,
                        readonly=   my_readonly,
                        name_leaf=  name,
                        make_panel= make_panel,
                        fields2ignore= fields2ignore,
                        translator= translator,
                )

        if translator:
            if isinstance( p, tuple):
                d = p[1]
                d = d[ list(d.keys())[0] ]
                l =  d.get('label')
                if l: d['label'] = translator(l)
            elif isinstance( p, Panel):
                p.header['title'] =  translator(p.header['title'])
        if not optional:
            panel += p
        else:
            if typ.non_atomary:
                panel_opt *= p
            else: #plain atomary
                txt,field_map = p
                panel_opt.field_map.update( field_map)
                panel_opt.parse( txt, start_new_row=False)
Example #11
0
 def test_( me):
     for attr_name, expected_val in me.params.expected.iteritems():
         v = get_attrib( me.test_data, attr_name)
         me.assertEqual( v, expected_val, me.name+' '+attr_name)