• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.ReportValue类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中model_report.utils.ReportValue的典型用法代码示例。如果您正苦于以下问题:Python ReportValue类的具体用法?Python ReportValue怎么用?Python ReportValue使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了ReportValue类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_grouper_text

    def get_grouper_text(self, value, field, model_field):
        try:
            if not isinstance(model_field, (str, unicode)):
                obj = model_field.model(**{field: value})
                if hasattr(obj, 'get_%s_display' % field):
                    value = getattr(obj, 'get_%s_display' % field)()
        except:
            pass

        if field in self.override_field_formats:
            value = ReportValue(value)
            value.format = self.override_field_formats[field]

        return value
开发者ID:alexeds,项目名称:django-model-report,代码行数:14,代码来源:report.py


示例2: compute_row_totals

 def compute_row_totals(row_config,
                        row_values,
                        is_group_total=False,
                        is_report_total=False):
     total_row = self.get_empty_row_asdict(self.get_fields(),
                                           ReportValue(' '))
     for k, v in total_row.items():
         if k in row_config:
             fun = row_config[k]
             value = fun(row_values[k])
             if k in self.get_m2m_field_names():
                 value = ReportValue([
                     value,
                 ])
             value = ReportValue(value)
             value.is_value = False
             value.is_group_total = is_group_total
             value.is_report_total = is_report_total
             if k in self.override_field_values:
                 value.to_value = self.override_field_values[k]
             if k in self.override_field_formats:
                 value.format = self.override_field_formats[k]
             value.is_m2m_value = (k in self.get_m2m_field_names())
             total_row[k] = value
     row = self.reorder_dictrow(total_row)
     row = ReportRow(row)
     row.is_total = True
     return row
开发者ID:renyi,项目名称:django-model-report,代码行数:28,代码来源:report.py


示例3: compute_row_totals

 def compute_row_totals(self, row_config, row_values, is_group_total=False, is_report_total=False,
                        filter_related_fields={}):
     used_fields = [field for field in self.used_fields() if field not in filter_related_fields]
     total_row = self.get_empty_row_asdict(used_fields, ReportValue(' '))
     for field in used_fields:
         if field in row_config:
             fun = row_config[field]
             value = fun(row_values[field])
             if field in self.get_m2m_field_names():
                 value = ReportValue([value, ])
             value = ReportValue(value)
             value.is_value = False
             value.is_group_total = is_group_total
             value.is_report_total = is_report_total
             # TODO: method should do only one thing.
             # Remove ovveride_field_values from this function.
             if field in self.override_field_values:
                 value.to_value = self.override_field_values[field]
             if field in self.override_field_formats:
                 value.format = self.override_field_formats[field]
             value.is_m2m_value = (field in self.get_m2m_field_names())
             total_row[field] = value
     row = self.reorder_dictrow(total_row)
     row = ReportRow(row)
     row.is_total = True
     return row
开发者ID:spacediver,项目名称:django-model-report,代码行数:26,代码来源:report.py


示例4: compute_row_totals

 def compute_row_totals(row_config, row_values):
     total_row = self.get_empty_row_asdict(self.fields, ReportValue(" "))
     for k, v in total_row.items():
         if k in row_config:
             fun = row_config[k]
             value = fun(row_values[k])
             value = ReportValue(value)
             if k in self.override_field_values:
                 value.to_value = self.override_field_values[k]
             if k in self.override_field_formats:
                 value.format = self.override_field_formats[k]
             total_row[k] = value
     row = self.reorder_dictrow(total_row)
     row = ReportRow(row)
     row.is_total = True
     return row
开发者ID:JamesMura,项目名称:django-model-report,代码行数:16,代码来源:report.py


示例5: compute_row_totals

 def compute_row_totals(row_config, row_values, is_group_total=False, is_report_total=False):
     total_row = self.get_empty_row_asdict(self.get_fields(), ReportValue(' '))
     for field_name in total_row.keys():
         if field_name in row_config:
             fun = row_config[field_name]
             cell_value = fun(row_values[field_name])
             if field_name in self.get_m2m_field_names():
                 cell_value = ReportValue([cell_value])
                 # cell_value = [cell_value]
             cell_value = ReportValue(cell_value)
             cell_value.is_value = False
             cell_value.is_group_total = is_group_total
             cell_value.is_report_total = is_report_total
             if field_name in self.override_field_values:
                 cell_value.to_value = self.override_field_values[field_name]
             if field_name in self.override_field_formats:
                 cell_value.format = self.override_field_formats[field_name]
             cell_value.is_m2m_value = field_name in self.get_m2m_field_names()
             total_row[field_name] = cell_value
     totals_row = ReportRow(self.reorder_dictrow(total_row))
     totals_row.is_total = True
     return totals_row
开发者ID:jerzyk,项目名称:django-model-report,代码行数:22,代码来源:report.py


示例6: get_rows


#.........这里部分代码省略.........
                    model_qs = self.model.objects.filter(pk__in=model_ids)
                else:
                    model_qs = model_field.rel.to.objects.filter(
                        pk__in=model_ids)
                div = {}
                method_name = dot_indexes[index].split('.')[1]
                for obj in model_qs:
                    method_value = getattr(obj, method_name)
                    if callable(method_value):
                        method_value = method_value()
                    div[obj.pk] = method_value
                dot_indexes_values[index] = div
                del model_qs

            if dot_indexes_values:
                new_resources = []
                for index_row, old_row in enumerate(resources):
                    new_row = []
                    for index, actual_value in enumerate(old_row):
                        if index in dot_indexes_values:
                            new_value = dot_indexes_values[index][actual_value]
                        else:
                            new_value = actual_value
                        new_row.append(new_value)
                    new_resources.append(new_row)
                resources = new_resources
            return resources

        def compute_row_totals(row_config,
                               row_values,
                               is_group_total=False,
                               is_report_total=False):
            total_row = self.get_empty_row_asdict(self.get_fields(),
                                                  ReportValue(' '))
            for k, v in total_row.items():
                if k in row_config:
                    fun = row_config[k]
                    value = fun(row_values[k])
                    if k in self.get_m2m_field_names():
                        value = ReportValue([
                            value,
                        ])
                    value = ReportValue(value)
                    value.is_value = False
                    value.is_group_total = is_group_total
                    value.is_report_total = is_report_total
                    if k in self.override_field_values:
                        value.to_value = self.override_field_values[k]
                    if k in self.override_field_formats:
                        value.format = self.override_field_formats[k]
                    value.is_m2m_value = (k in self.get_m2m_field_names())
                    total_row[k] = value
            row = self.reorder_dictrow(total_row)
            row = ReportRow(row)
            row.is_total = True
            return row

        def compute_row_header(row_config):
            header_row = self.get_empty_row_asdict(self.get_fields(),
                                                   ReportValue(''))
            for k, fun in row_config.items():
                if hasattr(fun, 'caption'):
                    value = force_unicode(fun.caption)
                else:
                    value = ' '
                header_row[k] = value
开发者ID:renyi,项目名称:django-model-report,代码行数:67,代码来源:report.py


示例7: get_rows

    def get_rows(self, groupby_data=None, filter_kwargs={}, filter_related_fields={}):
        report_rows = []

        for selected_field, field_value in filter_kwargs.items():
            if selected_field in self.override_field_filter_values:
                filter_kwargs[selected_field] = self.override_field_filter_values.get(selected_field)(self, field_value)

        qs = self.get_query_set(filter_kwargs)
        ffields = [f if 'self.' not in f else 'pk' for f in self.get_query_field_names() if f not in filter_related_fields]
        ffields_include_self = [f for f in self.get_query_field_names() if f not in filter_related_fields]
        extra_ffield = []
        backend = settings.DATABASES['default']['ENGINE'].split('.')[-1]
        for f in list(ffields):
            if '__' in f:
                for field, name in self.model_fields:
                    if name == f:
                        if is_date_field(field):
                            fname, flookup = f.rsplit('__', 1)
                            fname = fname.split('__')[-1]
                            if not flookup in ('year', 'month', 'day'):
                                break
                            if flookup == 'year':
                                if 'sqlite' in backend:
                                    extra_ffield.append([f, "strftime('%%Y', " + fname + ")"])
                                elif 'postgres' in backend:
                                    extra_ffield.append([f, "cast(extract(year from " + fname + ") as integer)"])
                                elif 'mysql' in backend:
                                    extra_ffield.append([f, "YEAR(" + fname + ")"])
                                else:
                                    raise NotImplemented  # mysql
                            if flookup == 'month':
                                if 'sqlite' in backend:
                                    extra_ffield.append([f, "strftime('%%m', " + fname + ")"])
                                elif 'postgres' in backend:
                                    extra_ffield.append([f, "cast(extract(month from " + fname + ") as integer)"])
                                elif 'mysql' in backend:
                                    extra_ffield.append([f, "MONTH(" + fname + ")"])
                                else:
                                    raise NotImplemented  # mysql
                            if flookup == 'day':
                                if 'sqlite' in backend:
                                    extra_ffield.append([f, "strftime('%%d', " + fname + ")"])
                                elif 'postgres' in backend:
                                    extra_ffield.append([f, "cast(extract(day from " + fname + ") as integer)"])
                                elif 'mysql' in backend:
                                    extra_ffield.append([f, "DAY(" + fname + ")"])
                                else:
                                    raise NotImplemented  # mysql
                        break
        obfields = list(self.list_order_by)
        if groupby_data and groupby_data['groupby']:
            if groupby_data['groupby'] in obfields:
                obfields.remove(groupby_data['groupby'])
            obfields.insert(0, groupby_data['groupby'])
        qs = self.filter_query(qs)
        qs = qs.order_by(*obfields)
        if extra_ffield:
            qs = qs.extra(select=dict(extra_ffield))
        qs = qs.values_list(*ffields)
        qs_list = list(qs)

        qs_list = self.get_with_dotvalues(qs_list)
        if self.model_m2m_fields:
            qs_list = self.group_m2m_field_values(qs_list)

        if groupby_data and groupby_data['groupby']:
            groupby_field = groupby_data['groupby']
            if groupby_field in self.override_group_value:
                transform_fn = self.override_group_value.get(groupby_field)
                groupby_fn = lambda x: transform_fn(x[ffields.index(groupby_field)])
            else:
                groupby_fn = lambda x: x[ffields.index(groupby_field)]
        else:
            groupby_fn = lambda x: None

        qs_list.sort(key=groupby_fn)
        g = groupby(qs_list, key=groupby_fn)

        row_report_totals = self.get_empty_row_asdict(self.report_totals, [])
        for grouper, resources in g:
            rows = list()
            row_group_totals = self.get_empty_row_asdict(self.group_totals, [])
            for resource in resources:
                row = ReportRow()
                if isinstance(resource, (tuple, list)):
                    for index, value in enumerate(resource):
                        if ffields_include_self[index] in self.group_totals:
                            row_group_totals[ffields_include_self[index]].append(value)
                        elif ffields[index] in self.group_totals:
                            row_group_totals[ffields[index]].append(value)
                        elif ffields[index] in self.report_totals:
                            row_report_totals[ffields[index]].append(value)
                        value = self._get_value_text(index, value)
                        value = ReportValue(value)
                        if ffields[index] in self.override_field_values:
                            value.to_value = self.override_field_values[ffields[index]]
                        if ffields[index] in self.override_field_formats:
                            value.format = self.override_field_formats[ffields[index]]
                        row.append(value)
                else:
#.........这里部分代码省略.........
开发者ID:monagis,项目名称:django-model-report,代码行数:101,代码来源:report.py


示例8: get_rows

    def get_rows(self, request, groupby_data=None, filter_kwargs={}, filter_related_fields={}):

        report_rows = []

        def get_field_value(obj, field):
            if isinstance(obj, (dict)):
                return obj[field]
            left_field = field.split("__")[0]
            try:
                right_field = "__".join(field.split("__")[1:])
            except:
                right_field = ""
            if right_field:
                return get_field_value(getattr(obj, left_field), right_field)
            if hasattr(obj, "get_%s_display" % left_field):
                attr = getattr(obj, "get_%s_display" % field)
            else:
                attr = getattr(obj, field)
            if callable(attr):
                attr = attr()
            return attr

        qs = self.get_query_set(filter_kwargs)
        ffields = [
            f if "self." not in f else "pk" for f in self.get_query_field_names() if f not in filter_related_fields
        ]
        obfields = list(self.list_order_by)
        if groupby_data and groupby_data["groupby"]:
            if groupby_data["groupby"] in obfields:
                obfields.remove(groupby_data["groupby"])
            obfields.insert(0, groupby_data["groupby"])
        qs = qs.order_by(*obfields)
        qs = qs.values_list(*ffields)
        qs_list = list(qs)

        def get_with_dotvalues(resources):
            # {1: 'field.method'}
            dot_indexes = dict([(index, dot_field) for index, dot_field in enumerate(self.fields) if "." in dot_field])
            dot_indexes_values = {}

            dot_model_fields = [
                (index, model_field[0]) for index, model_field in enumerate(self.model_fields) if index in dot_indexes
            ]
            # [ 1, model_field] ]
            for index, model_field in dot_model_fields:
                model_ids = set([row[index] for row in resources])
                if isinstance(model_field, (unicode, str)) and "self." in model_field:
                    model_qs = self.model.objects.filter(pk__in=model_ids)
                else:
                    model_qs = model_field.rel.to.objects.filter(pk__in=model_ids)
                div = {}
                method_name = dot_indexes[index].split(".")[1]
                for obj in model_qs:
                    method_value = getattr(obj, method_name)
                    if callable(method_value):
                        method_value = method_value()
                    div[obj.pk] = method_value
                dot_indexes_values[index] = div
                del model_qs

            if dot_indexes_values:
                new_resources = []
                for index_row, old_row in enumerate(resources):
                    new_row = []
                    for index, actual_value in enumerate(old_row):
                        if index in dot_indexes_values:
                            new_value = dot_indexes_values[index][actual_value]
                        else:
                            new_value = actual_value
                        new_row.append(new_value)
                    new_resources.append(new_row)
                resources = new_resources
            return resources

        def compute_row_totals(row_config, row_values):
            total_row = self.get_empty_row_asdict(self.fields, ReportValue(" "))
            for k, v in total_row.items():
                if k in row_config:
                    fun = row_config[k]
                    value = fun(row_values[k])
                    value = ReportValue(value)
                    if k in self.override_field_values:
                        value.to_value = self.override_field_values[k]
                    if k in self.override_field_formats:
                        value.format = self.override_field_formats[k]
                    total_row[k] = value
            row = self.reorder_dictrow(total_row)
            row = ReportRow(row)
            row.is_total = True
            return row

        def compute_row_header(row_config):
            header_row = self.get_empty_row_asdict(self.fields, ReportValue(""))
            for k, fun in row_config.items():
                if hasattr(fun, "caption"):
                    value = fun.caption
                else:
                    value = " "
                header_row[k] = value
            row = self.reorder_dictrow(header_row)
#.........这里部分代码省略.........
开发者ID:JamesMura,项目名称:django-model-report,代码行数:101,代码来源:report.py


示例9: get_rows

    def get_rows(self, request, groupby_data=None, filter_kwargs={}, filter_related_fields={}):
        report_rows = []

        def get_field_value(obj, field):
            if isinstance(obj, (dict)):
                return obj[field]
            left_field = field.split("__")[0]
            try:
                right_field = "__".join(field.split("__")[1:])
            except:
                right_field = ''
            if right_field:
                return get_field_value(getattr(obj, left_field), right_field)
            if hasattr(obj, 'get_%s_display' % left_field):
                attr = getattr(obj, 'get_%s_display' % field)
            else:
                attr = getattr(obj, field)
            if callable(attr):
                attr = attr()
            return attr
        qs = self.get_query_set(filter_kwargs)
        ffields = [f if 'self.' not in f else 'pk' for f in self.get_query_field_names() if f not in filter_related_fields]
        obfields = list(self.list_order_by)
        if groupby_data and groupby_data['groupby']:
            if groupby_data['groupby'] in obfields:
                obfields.remove(groupby_data['groupby'])
            obfields.insert(0, groupby_data['groupby'])
        qs = self.filter_query(qs)
        qs = qs.order_by(*obfields)
        qs = qs.values_list(*ffields)
        qs_list = list(qs)

        def get_with_dotvalues(resources):
            # {1: 'field.method'}
            dot_indexes = dict([(index, dot_field) for index, dot_field in enumerate(self.get_fields()) if '.' in dot_field])
            dot_indexes_values = {}

            dot_model_fields = [(index, model_field[0]) for index, model_field in enumerate(self.model_fields) if index in dot_indexes]
            # [ 1, model_field] ]
            for index, model_field in dot_model_fields:
                model_ids = set([row[index] for row in resources])
                if isinstance(model_field, (unicode, str)) and 'self.' in model_field:
                    model_qs = self.model.objects.filter(pk__in=model_ids)
                else:
                    model_qs = model_field.rel.to.objects.filter(pk__in=model_ids)
                div = {}
                method_name = dot_indexes[index].split('.')[1]
                for obj in model_qs:
                    method_value = getattr(obj, method_name)
                    if callable(method_value):
                        method_value = method_value()
                    div[obj.pk] = method_value
                dot_indexes_values[index] = div
                del model_qs

            if dot_indexes_values:
                new_resources = []
                for index_row, old_row in enumerate(resources):
                    new_row = []
                    for index, actual_value in enumerate(old_row):
                        if index in dot_indexes_values:
                            new_value = dot_indexes_values[index][actual_value]
                        else:
                            new_value = actual_value
                        new_row.append(new_value)
                    new_resources.append(new_row)
                resources = new_resources
            return resources

        def compute_row_totals(row_config, row_values, is_group_total=False, is_report_total=False):
            total_row = self.get_empty_row_asdict(self.get_fields(), ReportValue(' '))
            for k, v in total_row.items():
                if k in row_config:
                    fun = row_config[k]
                    value = fun(row_values[k])
                    if k in self.get_m2m_field_names():
                        value = ReportValue([value, ])
                    value = ReportValue(value)
                    value.is_value = False
                    value.is_group_total = is_group_total
                    value.is_report_total = is_report_total
                    if k in self.override_field_values:
                        value.to_value = self.override_field_values[k]
                    if k in self.override_field_formats:
                        value.format = self.override_field_formats[k]
                    value.is_m2m_value = (k in self.get_m2m_field_names())
                    total_row[k] = value
            row = self.reorder_dictrow(total_row)
            row = ReportRow(row)
            row.is_total = True
            return row

        def compute_row_header(row_config):
            header_row = self.get_empty_row_asdict(self.get_fields(), ReportValue(''))
            for k, fun in row_config.items():
                if hasattr(fun, 'caption'):
                    value = force_unicode(fun.caption)
                else:
                    value = ' '
                header_row[k] = value
#.........这里部分代码省略.........
开发者ID:SacNaturalFoods,项目名称:django-model-report,代码行数:101,代码来源:report.py



注:本文中的model_report.utils.ReportValue类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python fields.get_excerpt函数代码示例发布时间:2022-05-27
下一篇:
Python utils.ReportRow类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap