def __self_data(self): columns = [] values = [] for ra in self._report.attrs.order_by('id'): columns.append(ra.name) values.append((ra.value, ra.id if ra.data else None)) return Header(columns, {}).struct, values
def __get_values(self): queryset = self.get_queryset() columns = ['report'] columns.extend(self.view['columns']) # Get attributes columns and values attributes = {} attrs_qs = ReportAttr.objects.filter(report_id__in=list( cache_obj.report_id for cache_obj in queryset)).order_by('id') for attr in attrs_qs.only('name', 'value', 'report_id'): if attr.name not in attributes: attributes[attr.name] = {} columns.append(attr.name) attributes[attr.name][attr.report_id] = attr.value cnt = 0 values = [] for cache_obj in queryset: cnt += 1 values_str = [] for col in columns: val = '-' href = None html = None if col in attributes: val = attributes[col].get(cache_obj.report_id, '-') elif col == 'report': val = cnt if self.model == SafeMarkAssociationChanges: href = reverse('reports:safe', args=[cache_obj.report_id]) elif self.model == UnsafeMarkAssociationChanges: href = reverse('reports:unsafe', args=[cache_obj.report.trace_id]) else: href = reverse('reports:unknown', args=[cache_obj.report_id]) elif col == 'sum_verdict': html = self.__get_sum_verdict(cache_obj) elif col == 'change_kind': html = self.__get_kind_html(cache_obj) elif col == 'decision': val = cache_obj.decision.name href = reverse('jobs:decision', args=[cache_obj.decision.id]) elif col == 'tags': html = self.__get_tags_or_problems(cache_obj.tags_old, cache_obj.tags_new) elif col == 'problems': html = self.__get_tags_or_problems(cache_obj.problems_old, cache_obj.problems_new) values_str.append({ 'value': str(val), 'href': href, 'html': html }) values.append(values_str) return Header(columns, MARK_TITLES).struct, values
def __init__(self, user, marks_type, view, page=1): self.user = user self.type = marks_type self.view = view self._page_num = page self.page = None columns, self.values = self.__marks_data() self.header = Header(columns, MARK_TITLES).struct
def __unsafes_data(self): unsafes_ids = list(report.pk for report in self.page) cnt = (self.page.number - 1) * self.paginator.per_page + 1 columns = ['number'] columns.extend(self.view['columns']) attributes = {} for r_id, a_name, a_value in ReportAttr.objects.filter(report_id__in=unsafes_ids).order_by('id')\ .values_list('report_id', 'name', 'value'): if a_name not in attributes: columns.append(a_name) attributes[a_name] = {} attributes[a_name][r_id] = a_value verdicts_dict = dict(UNSAFE_VERDICTS) with_confirmed = 'hidden' not in self.view or 'confirmed_marks' not in self.view['hidden'] values_data = [] for report in self.page: values_row = [] for col in columns: val = '-' href = None color = None if col in attributes: val = attributes[col].get(report.pk, '-') elif col == 'number': val = cnt href = reverse('reports:unsafe', args=[report.trace_id]) elif col == 'marks_number': if with_confirmed: val = '{0} ({1})'.format(report.cache.marks_confirmed, report.cache.marks_total) else: val = str(report.cache.marks_total) elif col == 'report_verdict': val = verdicts_dict[report.cache.verdict] color = UNSAFE_COLOR[report.cache.verdict] elif col == 'tags': if len(report.cache.tags): tags_values = [] for tag in sorted(report.cache.tags): if report.cache.tags[tag] > 1: tags_values.append('{0} ({1})'.format(tag, report.cache.tags[tag])) else: tags_values.append(tag) val = ', '.join(tags_values) elif col == 'verifiers:cpu': val = HumanizedValue(report.cpu_time, user=self.user).timedelta elif col == 'verifiers:wall': val = HumanizedValue(report.wall_time, user=self.user).timedelta elif col == 'verifiers:memory': val = HumanizedValue(report.memory, user=self.user).memory values_row.append({'value': val, 'color': color, 'href': href}) values_data.append(values_row) cnt += 1 return Header(columns, REP_MARK_TITLES).struct, values_data
def __init__(self, user, report, view, page=1): self.user = user self.report = report self.view = view self.columns = [] columns, values = self.__component_data() self.paginator = None self.table_data = {'header': Header(columns, REP_MARK_TITLES).struct, 'values': self.__get_page(page, values)}
def __init__(self, user, report, view, data): self.title = _('Safes') self.user = user self.view = view self._kwargs = self.__get_kwargs(report, data) self.parents = get_parents(report) self.verdicts = SAFE_VERDICTS self.page = None columns, values = self.__safes_data() self.table_data = {'header': Header(columns, REP_MARK_TITLES).struct, 'values': values}
def marks_data(self): cnt = (self.page.number - 1) * self.paginator.per_page + 1 columns = ['checkbox', 'number'] if self.is_manager else ['number'] columns.extend(self.view['columns']) # We collecting attributes from separate request to ensure the order of attributes columns is right attr_columns, attributes = self.__get_attrs() columns.extend(attr_columns) values_data = [] for mark_version in self.page: mark_id = mark_version.mark_id values_row = [] for col in columns: val = '-' href = None color = None if col == 'checkbox': values_row.append({'checkbox': mark_id}) continue elif col in attributes: val = attributes[col].get(mark_id, '-') elif col == 'number': val = cnt href = reverse('marks:{}'.format(self.mark_type), args=[mark_id]) elif col == 'num_of_links': val = mark_version.num_of_links elif col == 'tags': if mark_version.mark.cache_tags: val = ','.join(mark_version.mark.cache_tags) elif col == 'author' and mark_version.author: val = mark_version.author.get_full_name() href = reverse('users:show-profile', args=[mark_version.author_id]) elif col == 'change_date': val = mark_version.change_date if self.user.data_format == 'hum': val = HumanizedValue.get_templated_text( '{% load humanize %}{{ date|naturaltime }}', date=val) elif col == 'source': val = mark_version.mark.get_source_display() elif col == 'identifier': val = str(mark_version.mark.identifier) else: val, href, color = self.get_value(col, mark_version) values_row.append({'value': val, 'color': color, 'href': href}) values_data.append(values_row) cnt += 1 return Header(columns, MARK_TITLES).struct, values_data
def __get_data(self): cnt = (self.page.number - 1) * self.paginator.per_page columns = ['report'] + self.view['columns'] values = [] for mark_report in self.page: report = mark_report.report cnt += 1 values_str = [] for col in columns: val = '-' color = None href = None if col == 'report': val = cnt if report.decision_id in self.can_view_decisions: if self.type == 'unsafe': href = reverse('reports:unsafe', args=[str(report.trace_id)]) else: href = reverse('reports:%s' % self.type, args=[report.id]) elif col == 'decision': val = report.decision.name if report.decision_id in self.can_view_decisions: href = reverse('jobs:decision', args=[report.decision_id]) elif col == 'ass_type': val = mark_report.get_type_display() elif col == 'associated': val = mark_report.associated elif col == 'ass_author': if mark_report.author: val = mark_report.author.get_full_name() href = reverse('users:show-profile', args=[mark_report.author_id]) elif col == 'likes' and mark_report.id in self.likes_data: val = '{} / {}'.format( self.likes_data[mark_report.id]['likes'], self.likes_data[mark_report.id]['dislikes']) else: val, href, color = self.get_value(col, mark_report) values_str.append({ 'value': val, 'href': href, 'color': color, 'column': col }) values.append(values_str) return Header(columns, MARK_TITLES).struct, values
def __init__(self, user, report, view, data): self.title = _('Unknowns') self.user = user self.view = view self._kwargs = self.__get_kwargs(report, data) self.parents = get_parents(report) self.page = None self.selected_columns = self.__selected() self.available_columns = self.__available() columns, values = self.__unknowns_data() if isinstance(values, str): self.table_data = values else: self.table_data = {'header': Header(columns, REP_MARK_TITLES).struct, 'values': values}
def __init__(self, obj, view): self.view = view self._data = json.loads(obj.table_data) self._problems_names = {} self.href = self._data['href'] if self.view['type'] == VIEW_TYPES[16][0]: self.verdicts = SAFE_VERDICTS elif self.view['type'] == VIEW_TYPES[17][0]: self.verdicts = UNSAFE_VERDICTS self.selected_columns = self.__selected() self.available_columns = self.__available() self.columns = self.__get_columns() self.header = Header(self.columns, MARK_TITLES).struct self.values = self.__get_values()
def __init__(self, user, mark, view, page=1): self.user = user self.mark = mark self.view = view if isinstance(self.mark, MarkUnsafe): self.type = 'unsafe' elif isinstance(self.mark, MarkSafe): self.type = 'safe' elif isinstance(self.mark, MarkUnknown): self.type = 'unknown' else: return self.selected_columns = self.__selected() self.available_columns = self.__available() self.columns = self.__get_columns() self.header = Header(self.columns, MARK_TITLES).struct self.values = self.__get_page(page, self.__get_values())
def __component_data(self): report_ids = list(report.id for report in self.page) columns = ['component'] reports_data = dict((report.id, { 'component': {'value': report.component, 'href': reverse('reports:component', args=[report.id])} }) for report in self.page) for r_id, name, value in ReportAttr.objects.filter(report_id__in=report_ids).order_by('id') \ .values_list('report_id', 'name', 'value'): if name not in columns: columns.append(name) reports_data[r_id][name] = {'value': value} values_data = list( list( reports_data[report.id].get(col, '-') for col in columns ) for report in self.page ) return Header(columns, REP_MARK_TITLES).struct, values_data
def __init__(self, user, report, view): self.user = user self.report = report self.view = view self.can_mark = MarkAccess(user, report=report).can_create() self.statuses = MARK_STATUS self.ass_types = ASSOCIATION_TYPE if isinstance(report, ReportUnsafe): self.type = 'unsafe' self.verdicts = MARK_UNSAFE elif isinstance(report, ReportSafe): self.type = 'safe' self.verdicts = MARK_SAFE elif isinstance(report, ReportUnknown): self.type = 'unknown' else: return self.selected_columns = self.__selected() self.available_columns = self.__available() self.columns = self.__get_columns() self.header = Header(self.columns, MARK_TITLES).struct self.values = self.__get_values()
def __init__(self, report): self.report = report columns, values = self.__self_data() self.table_data = {'header': Header(columns, REP_MARK_TITLES).struct, 'values': values}
def __get_values(self): value_data = [] source_dict = dict(MARK_SOURCE) ass_type_dict = dict(self.ass_types) cnt = 1 for mark_data in self.queryset: row_data = [] for col in self.columns: val = '-' href = None color = None if col == 'mark_num': val = cnt href = reverse('marks:{}'.format(self.report_type), args=[mark_data['id']]) elif col == 'verdict': val = self.marks_model( verdict=mark_data['verdict']).get_verdict_display() if self.report_type == 'unsafe': color = UNSAFE_COLOR[mark_data['verdict']] else: color = SAFE_COLOR[mark_data['verdict']] elif col == 'problem': val = mark_data['problem'] problem_link = mark_data['link'] if problem_link is not None: if not problem_link.startswith('http'): problem_link = 'http://' + problem_link href = problem_link elif col == 'similarity': if mark_data['error'] is not None: val = mark_data['error'] color = result_color(0) else: val = "{:.0%}".format(mark_data['similarity']) color = result_color(mark_data['similarity']) elif col == 'status': if mark_data['status']: val = MarkUnsafe( status=mark_data['status']).get_status_display() color = STATUS_COLOR[mark_data['status']] elif col == 'source': val = source_dict[mark_data['source']] elif col == 'tags': if mark_data['cache_tags']: val = '; '.join(sorted(mark_data['cache_tags'])) elif col == 'ass_type': val = { 'id': mark_data['id'], 'origin': mark_data['ass_type'], 'display': ass_type_dict[mark_data['ass_type']] } if mark_data['ass_type'] != ASSOCIATION_TYPE[1][0]: val['confirm_url'] = reverse( 'marks:api-confirm-{}'.format(self.report_type), args=[mark_data['ass_id']]) if mark_data['ass_type'] != ASSOCIATION_TYPE[2][0]: val['unconfirm_url'] = reverse( 'marks:api-confirm-{}'.format(self.report_type), args=[mark_data['ass_id']]) color = ASSOCIATION_TYPE_COLOR[mark_data['ass_type']] elif col == 'ass_author': if mark_data['ass_author'] and mark_data[ 'ass_author'] in self.authors: val = self.authors[ mark_data['ass_author']].get_full_name() href = reverse('users:show-profile', args=[mark_data['ass_author']]) elif col == 'description': if len(mark_data['description']): val = mark_data['description'] elif col == 'likes': val = { 'id': mark_data['ass_id'], 'likes_num': len(self.likes_data['likes'].get( mark_data['ass_id'], [])), 'dislikes_num': len(self.likes_data['dislikes'].get( mark_data['ass_id'], [])), 'like_url': reverse('marks:api-like-{}'.format(self.report_type), args=[mark_data['ass_id']]) } elif col == 'buttons': val = { 'edit': reverse('marks:{}-edit-inl'.format(self.report_type), args=[mark_data['id']]), 'delete': reverse('marks:api-{}-detail'.format(self.report_type), args=[mark_data['id']]), } elif col == 'change_date': val = mark_data['cahnge_date'] elif col == 'associated': val = mark_data['associated'] elif col == 'author': if mark_data['author'] and mark_data[ 'author'] in self.authors: val = self.authors[mark_data['author']].get_full_name() href = reverse('users:show-profile', args=[mark_data['author']]) row_data.append({ 'value': val, 'color': color, 'column': col, 'href': href }) cnt += 1 value_data.append(row_data) return value_data, Header(self.columns, MARK_TITLES).struct