def display(self, models): datas = [] self.axis = copy.copy(self.old_axis) group_by = self.widget.screen.context.get('group_by', False) if group_by: if not self.key: del self.widget.screen.context['group_by'] self.key = True self.widget.screen.search_filter() ## TODO: Check why was this needed ? models = self.widget.screen.models self.widget.screen.context['group_by'] = group_by self.key = False self.axis[0] = group_by[0] self.axis_data[group_by[0]] = {} # This is to get the missing field. if the field is not available in the graph view # for use case :graph view loaded directly from a dashboard and user executes groupby if self.axis[0] not in models.mfields: missing_gb_field = rpc.session.rpc_exec_auth('/object', 'execute', self.model, 'fields_get', [self.axis[0]], {}) if missing_gb_field: models.add_fields(missing_gb_field, models) for m in models: res = {} for x in self.axis_data.keys(): if not self.axis_data[x]: self.axis_data[x] = self.fields[x] field_val = m[x].get_client(m) if self.fields[x]['type'] in ('many2one', 'char','time','text'): res[x] = field_val and str(field_val) or _('Undefined') elif self.fields[x]['type'] == 'selection': selection = dict(m[x].attrs['selection']) if field_val: val = str(field_val) res[x] = selection.get(val, val) else: res[x] = _('Undefined') elif self.fields[x]['type'] == 'date': if field_val: res[x] = datetime_util.server_to_local_timestamp(field_val, DT_FORMAT, user_locale_format.get_date_format(), tz_offset=False) else: res[x] = _('Undefined') elif self.fields[x]['type'] == 'datetime': if field_val: res[x] = datetime_util.server_to_local_timestamp(field_val, DHM_FORMAT, user_locale_format.get_datetime_format(True)) else: res[x] = _('Undefined') else: res[x] = field_val and float(field_val) or 0.0 datas.append(res) tinygraph.tinygraph(self._subplot, self.attrs.get('type', 'pie'), self.axis, self.axis_data, datas, axis_group_field=self.axis_group, orientation=self.attrs.get('orientation', 'vertical')) # the draw function may generate exception but it is not a problem as it will be redraw latter try: self._subplot.draw(None) #XXX it must have some better way to force the redraw but this one works self._canvas.queue_resize() except: pass
def display(self, models): datas = [] for m in models: res = {} for x in self.axis_data.keys(): if self.fields[x]['type'] in ('many2one', 'char','time','text'): res[x] = str(m[x].get_client(m)) elif self.fields[x]['type'] == 'selection': selection = dict(m[x].attrs['selection']) val = str(m[x].get_client(m)) res[x] = selection.get(val, val) elif self.fields[x]['type'] == 'date': if m[x].get_client(m): date = time.strptime(m[x].get_client(m), DT_FORMAT) res[x] = time.strftime(LDFMT, date) else: res[x]='' elif self.fields[x]['type'] == 'datetime': if m[x].get_client(m): date = time.strptime(m[x].get_client(m), DHM_FORMAT) if rpc.session.context.get('tz'): try: lzone = pytz.timezone(rpc.session.context['tz']) szone = pytz.timezone(rpc.session.timezone) dt = DT.datetime(date[0], date[1], date[2], date[3], date[4], date[5], date[6]) sdt = szone.localize(dt, is_dst=True) ldt = sdt.astimezone(lzone) date = ldt.timetuple() except pytz.UnknownTimeZoneError: # Timezones are sometimes invalid under Windows # and hard to figure out, so as a low-risk fix # in stable branch we will simply ignore the # exception and consider client in server TZ # (and sorry about the code duplication as well, # this is fixed properly in trunk) pass res[x] = time.strftime(LDFMT + ' %H:%M:%S', date) else: res[x] = '' else: res[x] = float(m[x].get_client(m)) datas.append(res) tinygraph.tinygraph(self._subplot, self.attrs.get('type', 'pie'), self.axis, self.axis_data, datas, axis_group_field=self.axis_group, orientation=self.attrs.get('orientation', 'vertical')) # the draw function may generate exception but it is not a problem as it will be redraw latter try: self._subplot.draw() #XXX it must have some better way to force the redraw but this one works self._canvas.queue_resize() except: pass
def display(self, models): datas = [] self.axis = copy.copy(self.old_axis) group_by = self.widget.screen.context.get("group_by", False) if group_by: if not self.key: del self.widget.screen.context["group_by"] self.key = True self.widget.screen.search_filter() models = self.widget.screen.models self.widget.screen.context["group_by"] = group_by self.axis[0] = group_by[0] self.axis_data[group_by[0]] = {} # This is to get the missing field. if the field is not available in the graph view # for use case :graph view loaded directly from a dashboard and user executes groupby if self.axis[0] not in models.mfields: missing_gb_field = rpc.session.rpc_exec_auth( "/object", "execute", self.model, "fields_get", [self.axis[0]], {} ) if missing_gb_field: models.add_fields(missing_gb_field, models) for m in models: res = {} for x in self.axis_data.keys(): if not self.axis_data[x]: self.axis_data[x] = self.fields[x] field_val = m[x].get_client(m) if self.fields[x]["type"] in ("many2one", "char", "time", "text"): res[x] = field_val and str(field_val) or "Undefined" elif self.fields[x]["type"] == "selection": selection = dict(m[x].attrs["selection"]) if field_val: val = str(field_val) res[x] = selection.get(val, val) else: res[x] = "Undefined" elif self.fields[x]["type"] == "date": if field_val: res[x] = datetime_util.server_to_local_timestamp( field_val, DT_FORMAT, user_locale_format.get_date_format(), tz_offset=False ) else: res[x] = "Undefined" elif self.fields[x]["type"] == "datetime": if field_val: res[x] = datetime_util.server_to_local_timestamp( field_val, DHM_FORMAT, user_locale_format.get_datetime_format(True) ) else: res[x] = "Undefined" else: res[x] = field_val and float(field_val) or 0.0 datas.append(res) tinygraph.tinygraph( self._subplot, self.attrs.get("type", "pie"), self.axis, self.axis_data, datas, axis_group_field=self.axis_group, orientation=self.attrs.get("orientation", "vertical"), ) # the draw function may generate exception but it is not a problem as it will be redraw latter try: self._subplot.draw(None) # XXX it must have some better way to force the redraw but this one works self._canvas.queue_resize() except: pass
def display(self, models): datas = [] for m in models: res = {} for x in self.axis_data.keys(): if self.fields[x]['type'] in ('many2one', 'char', 'time', 'text'): res[x] = str(m[x].get_client(m)) elif self.fields[x]['type'] == 'selection': selection = dict(m[x].attrs['selection']) val = str(m[x].get_client(m)) res[x] = selection.get(val, val) elif self.fields[x]['type'] == 'date': if m[x].get_client(m): date = time.strptime(m[x].get_client(m), DT_FORMAT) res[x] = time.strftime(LDFMT, date) else: res[x] = '' elif self.fields[x]['type'] == 'datetime': if m[x].get_client(m): date = time.strptime(m[x].get_client(m), DHM_FORMAT) if rpc.session.context.get('tz'): try: lzone = pytz.timezone( rpc.session.context['tz']) szone = pytz.timezone(rpc.session.timezone) dt = DT.datetime(date[0], date[1], date[2], date[3], date[4], date[5], date[6]) sdt = szone.localize(dt, is_dst=True) ldt = sdt.astimezone(lzone) date = ldt.timetuple() except pytz.UnknownTimeZoneError: # Timezones are sometimes invalid under Windows # and hard to figure out, so as a low-risk fix # in stable branch we will simply ignore the # exception and consider client in server TZ # (and sorry about the code duplication as well, # this is fixed properly in trunk) pass res[x] = time.strftime(LDFMT + ' %H:%M:%S', date) else: res[x] = '' else: res[x] = float(m[x].get_client(m)) datas.append(res) tinygraph.tinygraph(self._subplot, self.attrs.get('type', 'pie'), self.axis, self.axis_data, datas, axis_group_field=self.axis_group, orientation=self.attrs.get('orientation', 'vertical')) # the draw function may generate exception but it is not a problem as it will be redraw latter try: self._subplot.draw() #XXX it must have some better way to force the redraw but this one works self._canvas.queue_resize() except: pass
def display(self, models): datas = [] self.axis = copy.copy(self.old_axis) group_by = self.widget.screen.context.get('group_by', False) if group_by: if not self.key: del self.widget.screen.context['group_by'] self.key = True self.widget.screen.search_filter() models = self.widget.screen.models self.widget.screen.context['group_by'] = group_by self.axis[0] = group_by[0] self.axis_data[group_by[0]] = {} # This is to get the missing field. if the field is not available in the graph view # for use case :graph view loaded directly from a dashboard and user executes groupby if self.axis[0] not in models.mfields: missing_gb_field = rpc.session.rpc_exec_auth( '/object', 'execute', self.model, 'fields_get', [self.axis[0]], {}) if missing_gb_field: models.add_fields(missing_gb_field, models) for m in models: res = {} for x in self.axis_data.keys(): if not self.axis_data[x]: self.axis_data[x] = self.fields[x] field_val = m[x].get_client(m) if self.fields[x]['type'] in ('many2one', 'char', 'time', 'text'): res[x] = field_val and str(field_val) or 'Undefined' elif self.fields[x]['type'] == 'selection': selection = dict(m[x].attrs['selection']) if field_val: val = str(field_val) res[x] = selection.get(val, val) else: res[x] = 'Undefined' elif self.fields[x]['type'] == 'date': if field_val: res[x] = datetime_util.server_to_local_timestamp( field_val, DT_FORMAT, user_locale_format.get_date_format(), tz_offset=False) else: res[x] = 'Undefined' elif self.fields[x]['type'] == 'datetime': if field_val: res[x] = datetime_util.server_to_local_timestamp( field_val, DHM_FORMAT, user_locale_format.get_datetime_format(True)) else: res[x] = 'Undefined' else: res[x] = field_val and float(field_val) or 0.0 datas.append(res) tinygraph.tinygraph(self._subplot, self.attrs.get('type', 'pie'), self.axis, self.axis_data, datas, axis_group_field=self.axis_group, orientation=self.attrs.get('orientation', 'vertical')) # the draw function may generate exception but it is not a problem as it will be redraw latter try: self._subplot.draw(None) #XXX it must have some better way to force the redraw but this one works self._canvas.queue_resize() except: pass