Пример #1
0
    def add_field_for(self, fields, df):
        sf = get_atomizer(df, df.name)

        if not sf in self.all_fields:
            self.all_fields.append(sf)

        #~ sf = self.df2sf.get(df,None)
        #~ if sf is None:
            #~ sf = self.create_atomizer(df,df.name)
            #~ self.all_fields.append(sf)
            #~ self.df2sf[df] = sf
        fields.append(sf)
Пример #2
0
    def add_field_for(self, fields, df):
        sf = get_atomizer(self.actor, df, df.name)
        if sf is None:  # dummy fields
            return
        if not sf in self.all_fields:
            self.all_fields.append(sf)

        #~ sf = self.df2sf.get(df,None)
        #~ if sf is None:
        #~ sf = self.create_atomizer(df,df.name)
        #~ self.all_fields.append(sf)
        #~ self.df2sf[df] = sf
        fields.append(sf)
Пример #3
0
    def add_field_for(self, fields, df):
        sf = get_atomizer(self.actor, df, df.name)
        if sf is None:  # dummy fields
            return
        # if not self.rh.actor.editable and isinstance(sf, ForeignKeyStoreField):
        #     sf = StoreField(df, df.name)
        #     raise Exception(20160907)
        if sf not in self.all_fields:
            self.all_fields.append(sf)

        # sf = self.df2sf.get(df,None)
        # if sf is None:
        # sf = self.create_atomizer(df,df.name)
        # self.all_fields.append(sf)
        # self.df2sf[df] = sf
        fields.append(sf)
Пример #4
0
    def add_field_for(self, fields, df):
        sf = get_atomizer(self.actor, df, df.name)
        if sf is None:  # dummy fields
            return
        # if not self.rh.actor.editable and isinstance(sf, ForeignKeyStoreField):
        #     sf = StoreField(df, df.name)
        #     raise Exception(20160907)
        if sf not in self.all_fields:
            self.all_fields.append(sf)

        # sf = self.df2sf.get(df,None)
        # if sf is None:
            # sf = self.create_atomizer(df,df.name)
            # self.all_fields.append(sf)
            # self.df2sf[df] = sf
        fields.append(sf)
Пример #5
0
    def get_field_info(ar,column_names=None):
        """
        Return a tuple (fields, headers, widths) which expresses which columns, headers 
        and widths the user wants for this TableRequest. If `self` has web request info, 
        checks for GET parameters cn, cw and ch (coming from the grid widget). Otherwise 
        Also apply the tables's :meth:`override_column_headers 
        <lino.core.actors.Actor.override_column_headers>` method.
        """
        u = ar.get_user()
        if u is not None:
            jsgen.set_for_user_profile(u.profile)
        
        if ar.request is None:
            columns = None
        else:
            columns = [str(x) for x in ar.request.REQUEST.getlist(constants.URL_PARAM_COLUMNS)]
        if columns:
            #~ widths = [int(x) for x in ar.request.REQUEST.getlist(constants.URL_PARAM_WIDTHS)]
            all_widths = ar.request.REQUEST.getlist(constants.URL_PARAM_WIDTHS)
            hiddens = [(x == 'true') for x in ar.request.REQUEST.getlist(constants.URL_PARAM_HIDDENS)]
            fields = []
            widths = []
            #~ headers = []
            #~ ah = ar.actor.get_handle(self.extjs_ui)
            #~ ah = ar.actor.get_handle(settings.SITE.ui)
            ah = ar.actor.get_handle()
            for i,cn in enumerate(columns):
                col = None
                for e in ah.list_layout.main.columns:
                    if e.name == cn:
                        col = e
                        break
                if col is None:
                    #~ names = [e.name for e in ar.ah.list_layout._main.walk()]
                    #~ raise Exception("No column named %r in %s" % (cn,ah.list_layout.main.columns))
                    raise Exception("No column named %r in %s" % (cn,ar.ah.list_layout.main.columns))
                if not hiddens[i]:
                    fields.append(col)
                    #~ fields.append(col.field._lino_atomizer)
                    #~ headers.append(unicode(col.label or col.name))
                    widths.append(int(all_widths[i]))
        else:
            if column_names:
                from lino.core import layouts
                #~ assert ar.actor is not None
                ll = layouts.ListLayout(column_names,datasource=ar.actor)
                #~ lh = ll.get_layout_handle(self.extjs_ui)
                lh = ll.get_layout_handle(settings.SITE.ui)
                columns = lh.main.columns
                columns = [e for e in columns if not e.hidden]
            else:
                #~ ah = ar.actor.get_handle(self.extjs_ui)
                ah = ar.actor.get_request_handle(ar)
                columns = ah.list_layout.main.columns
                
            #~ if ar.actor.__name__ == 'ActiveCourses':
                #~ logger.info("20131010 %s", [e.hidden for e in columns])
                
            # render them so that babelfields in hidden_languages get hidden:
            for e in columns: 
                e.value = e.ext_options()
                #~ e.value.update(e.ext_options())
                #~ e.js_value() 
            columns = [e for e in columns if not e.value.get('hidden',False)] # 
            
            columns = [e for e in columns if not e.hidden]
            
            widths = ["%d" % (col.width or col.preferred_width) for col in columns]
            #~ 20130415 widths = ["%d%%" % (col.width or col.preferred_width) for col in columns]
            #~ fields = [col.field._lino_atomizer for col in columns]
            fields = columns
            
        headers = [column_header(col) for col in fields]

        oh = ar.actor.override_column_headers(ar)
        if oh:
            for i,e in enumerate(columns):
                header = oh.get(e.name,None)
                if header is not None:
                    headers[i] = header
            #~ print 20120507, oh, headers
            
        return fields, headers, widths
Пример #6
0
    def get_field_info(ar, column_names=None):
        u = ar.get_user()
        if u is not None:
            jsgen.set_for_user_profile(u.profile)

        if ar.request is None:
            columns = None
        else:
            columns = [
                str(x) for x in ar.request.REQUEST.getlist(
                    constants.URL_PARAM_COLUMNS)]
        if columns:
            all_widths = ar.request.REQUEST.getlist(
                constants.URL_PARAM_WIDTHS)
            hiddens = [
                (x == 'true') for x in ar.request.REQUEST.getlist(
                    constants.URL_PARAM_HIDDENS)]
            fields = []
            widths = []
            ah = ar.actor.get_handle()
            for i, cn in enumerate(columns):
                col = None
                for e in ah.list_layout.main.columns:
                    if e.name == cn:
                        col = e
                        break
                if col is None:
                    raise Exception("No column named %r in %s" %
                                    (cn, ar.ah.list_layout.main.columns))
                if not hiddens[i]:
                    fields.append(col)
                    widths.append(int(all_widths[i]))
        else:
            if column_names:
                from lino.core import layouts
                ll = layouts.ListLayout(column_names, datasource=ar.actor)
                lh = ll.get_layout_handle(settings.SITE.ui)
                columns = lh.main.columns
                columns = [e for e in columns if not e.hidden]
            else:
                ah = ar.actor.get_request_handle(ar)
                columns = ah.list_layout.main.columns

            # render them so that babelfields in hidden_languages get hidden:
            for e in columns:
                e.value = e.ext_options()
            #
            columns = [e for e in columns if not e.value.get('hidden', False)]

            columns = [e for e in columns if not e.hidden]

            widths = ["%d" % (col.width or col.preferred_width)
                      for col in columns]
            #~ 20130415 widths = ["%d%%" % (col.width or col.preferred_width) for col in columns]
            #~ fields = [col.field._lino_atomizer for col in columns]
            fields = columns

        headers = [column_header(col) for col in fields]

        oh = ar.actor.override_column_headers(ar)
        if oh:
            for i, e in enumerate(columns):
                header = oh.get(e.name, None)
                if header is not None:
                    headers[i] = header
            #~ print 20120507, oh, headers

        return fields, headers, widths