showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 1 | from django.db import models as dbmodels, connection |
| 2 | from django.utils import datastructures |
| 3 | from autotest_lib.frontend.afe import model_logic, readonly_connection |
| 4 | |
showard | 8b0ea22 | 2009-12-23 19:23:03 +0000 | [diff] [blame] | 5 | _quote_name = connection.ops.quote_name |
| 6 | |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 7 | class TempManager(model_logic.ExtendedManager): |
| 8 | _GROUP_COUNT_NAME = 'group_count' |
| 9 | |
| 10 | def _get_key_unless_is_function(self, field): |
| 11 | if '(' in field: |
| 12 | return field |
showard | 7c199df | 2008-10-03 10:17:15 +0000 | [diff] [blame] | 13 | return self.get_key_on_this_table(field) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 14 | |
| 15 | |
showard | f248952 | 2008-10-23 23:08:00 +0000 | [diff] [blame] | 16 | def _get_field_names(self, fields, extra_select_fields={}): |
| 17 | field_names = [] |
| 18 | for field in fields: |
| 19 | if field in extra_select_fields: |
showard | d2b0c88 | 2009-10-19 18:34:11 +0000 | [diff] [blame] | 20 | field_names.append(extra_select_fields[field][0]) |
showard | f248952 | 2008-10-23 23:08:00 +0000 | [diff] [blame] | 21 | else: |
| 22 | field_names.append(self._get_key_unless_is_function(field)) |
| 23 | return field_names |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 24 | |
| 25 | |
showard | 8bfb5cb | 2009-10-07 20:49:15 +0000 | [diff] [blame] | 26 | def _get_group_query_sql(self, query, group_by): |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 27 | sql, params = query.query.as_sql() |
showard | d50ffb4 | 2008-09-04 02:47:45 +0000 | [diff] [blame] | 28 | |
| 29 | # insert GROUP BY clause into query |
showard | 8bfb5cb | 2009-10-07 20:49:15 +0000 | [diff] [blame] | 30 | group_fields = self._get_field_names(group_by, query.query.extra_select) |
showard | 7c199df | 2008-10-03 10:17:15 +0000 | [diff] [blame] | 31 | group_by_clause = ' GROUP BY ' + ', '.join(group_fields) |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 32 | group_by_position = sql.rfind('ORDER BY') |
showard | d50ffb4 | 2008-09-04 02:47:45 +0000 | [diff] [blame] | 33 | if group_by_position == -1: |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 34 | group_by_position = len(sql) |
| 35 | sql = (sql[:group_by_position] + |
| 36 | group_by_clause + ' ' + |
| 37 | sql[group_by_position:]) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 38 | |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 39 | return sql, params |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 40 | |
| 41 | |
showard | 06b82fc | 2009-06-30 01:59:42 +0000 | [diff] [blame] | 42 | def _get_column_names(self, cursor): |
showard | 8bfb5cb | 2009-10-07 20:49:15 +0000 | [diff] [blame] | 43 | """ |
showard | 06b82fc | 2009-06-30 01:59:42 +0000 | [diff] [blame] | 44 | Gets the column names from the cursor description. This method exists |
showard | 8bfb5cb | 2009-10-07 20:49:15 +0000 | [diff] [blame] | 45 | so that it can be mocked in the unit test for sqlite3 compatibility. |
showard | 06b82fc | 2009-06-30 01:59:42 +0000 | [diff] [blame] | 46 | """ |
| 47 | return [column_info[0] for column_info in cursor.description] |
| 48 | |
| 49 | |
showard | 8bfb5cb | 2009-10-07 20:49:15 +0000 | [diff] [blame] | 50 | def execute_group_query(self, query, group_by): |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 51 | """ |
showard | 8a6eb0c | 2008-10-01 11:38:59 +0000 | [diff] [blame] | 52 | Performs the given query grouped by the fields in group_by with the |
showard | 8bfb5cb | 2009-10-07 20:49:15 +0000 | [diff] [blame] | 53 | given query's extra select fields added. Returns a list of dicts, where |
| 54 | each dict corresponds to single row and contains a key for each grouped |
| 55 | field as well as all of the extra select fields. |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 56 | """ |
showard | 8bfb5cb | 2009-10-07 20:49:15 +0000 | [diff] [blame] | 57 | sql, params = self._get_group_query_sql(query, group_by) |
showard | 56e9377 | 2008-10-06 10:06:22 +0000 | [diff] [blame] | 58 | cursor = readonly_connection.connection().cursor() |
showard | 8a6eb0c | 2008-10-01 11:38:59 +0000 | [diff] [blame] | 59 | cursor.execute(sql, params) |
showard | 06b82fc | 2009-06-30 01:59:42 +0000 | [diff] [blame] | 60 | field_names = self._get_column_names(cursor) |
showard | 8a6eb0c | 2008-10-01 11:38:59 +0000 | [diff] [blame] | 61 | row_dicts = [dict(zip(field_names, row)) for row in cursor.fetchall()] |
| 62 | return row_dicts |
| 63 | |
| 64 | |
| 65 | def get_count_sql(self, query): |
| 66 | """ |
| 67 | Get the SQL to properly select a per-group count of unique matches for |
showard | 7c199df | 2008-10-03 10:17:15 +0000 | [diff] [blame] | 68 | a grouped query. Returns a tuple (field alias, field SQL) |
showard | 8a6eb0c | 2008-10-01 11:38:59 +0000 | [diff] [blame] | 69 | """ |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 70 | if query.query.distinct: |
showard | 7c199df | 2008-10-03 10:17:15 +0000 | [diff] [blame] | 71 | pk_field = self.get_key_on_this_table() |
showard | 8a6eb0c | 2008-10-01 11:38:59 +0000 | [diff] [blame] | 72 | count_sql = 'COUNT(DISTINCT %s)' % pk_field |
| 73 | else: |
| 74 | count_sql = 'COUNT(1)' |
showard | 7c199df | 2008-10-03 10:17:15 +0000 | [diff] [blame] | 75 | return self._GROUP_COUNT_NAME, count_sql |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 76 | |
| 77 | |
| 78 | def _get_num_groups_sql(self, query, group_by): |
showard | d2b0c88 | 2009-10-19 18:34:11 +0000 | [diff] [blame] | 79 | group_fields = self._get_field_names(group_by, query.query.extra_select) |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 80 | query = query.order_by() # this can mess up the query and isn't needed |
| 81 | |
| 82 | sql, params = query.query.as_sql() |
| 83 | from_ = sql[sql.find(' FROM'):] |
showard | d2b0c88 | 2009-10-19 18:34:11 +0000 | [diff] [blame] | 84 | return ('SELECT DISTINCT %s %s' % (','.join(group_fields), |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 85 | from_), |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 86 | params) |
| 87 | |
| 88 | |
showard | d2b0c88 | 2009-10-19 18:34:11 +0000 | [diff] [blame] | 89 | def _cursor_rowcount(self, cursor): |
| 90 | """To be stubbed by tests""" |
| 91 | return cursor.rowcount |
| 92 | |
| 93 | |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 94 | def get_num_groups(self, query, group_by): |
| 95 | """ |
| 96 | Returns the number of distinct groups for the given query grouped by the |
| 97 | fields in group_by. |
| 98 | """ |
| 99 | sql, params = self._get_num_groups_sql(query, group_by) |
showard | 56e9377 | 2008-10-06 10:06:22 +0000 | [diff] [blame] | 100 | cursor = readonly_connection.connection().cursor() |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 101 | cursor.execute(sql, params) |
showard | d2b0c88 | 2009-10-19 18:34:11 +0000 | [diff] [blame] | 102 | return self._cursor_rowcount(cursor) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 103 | |
| 104 | |
| 105 | class Machine(dbmodels.Model): |
showard | f8b1904 | 2009-05-12 17:22:49 +0000 | [diff] [blame] | 106 | machine_idx = dbmodels.AutoField(primary_key=True) |
showard | 356d237 | 2009-11-10 01:29:53 +0000 | [diff] [blame] | 107 | hostname = dbmodels.CharField(unique=True, max_length=255) |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 108 | machine_group = dbmodels.CharField(blank=True, max_length=240) |
| 109 | owner = dbmodels.CharField(blank=True, max_length=240) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 110 | |
| 111 | class Meta: |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 112 | db_table = 'tko_machines' |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 113 | |
| 114 | |
| 115 | class Kernel(dbmodels.Model): |
showard | f8b1904 | 2009-05-12 17:22:49 +0000 | [diff] [blame] | 116 | kernel_idx = dbmodels.AutoField(primary_key=True) |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 117 | kernel_hash = dbmodels.CharField(max_length=105, editable=False) |
| 118 | base = dbmodels.CharField(max_length=90) |
| 119 | printable = dbmodels.CharField(max_length=300) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 120 | |
| 121 | class Meta: |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 122 | db_table = 'tko_kernels' |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 123 | |
| 124 | |
| 125 | class Patch(dbmodels.Model): |
| 126 | kernel = dbmodels.ForeignKey(Kernel, db_column='kernel_idx') |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 127 | name = dbmodels.CharField(blank=True, max_length=240) |
| 128 | url = dbmodels.CharField(blank=True, max_length=900) |
| 129 | the_hash = dbmodels.CharField(blank=True, max_length=105, db_column='hash') |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 130 | |
| 131 | class Meta: |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 132 | db_table = 'tko_patches' |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 133 | |
| 134 | |
| 135 | class Status(dbmodels.Model): |
showard | f8b1904 | 2009-05-12 17:22:49 +0000 | [diff] [blame] | 136 | status_idx = dbmodels.AutoField(primary_key=True) |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 137 | word = dbmodels.CharField(max_length=30) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 138 | |
| 139 | class Meta: |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 140 | db_table = 'tko_status' |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 141 | |
| 142 | |
| 143 | class Job(dbmodels.Model): |
showard | f8b1904 | 2009-05-12 17:22:49 +0000 | [diff] [blame] | 144 | job_idx = dbmodels.AutoField(primary_key=True) |
showard | 356d237 | 2009-11-10 01:29:53 +0000 | [diff] [blame] | 145 | tag = dbmodels.CharField(unique=True, max_length=100) |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 146 | label = dbmodels.CharField(max_length=300) |
| 147 | username = dbmodels.CharField(max_length=240) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 148 | machine = dbmodels.ForeignKey(Machine, db_column='machine_idx') |
| 149 | queued_time = dbmodels.DateTimeField(null=True, blank=True) |
| 150 | started_time = dbmodels.DateTimeField(null=True, blank=True) |
| 151 | finished_time = dbmodels.DateTimeField(null=True, blank=True) |
showard | c1c1caf | 2009-09-08 16:26:50 +0000 | [diff] [blame] | 152 | afe_job_id = dbmodels.IntegerField(null=True, default=None) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 153 | |
| 154 | class Meta: |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 155 | db_table = 'tko_jobs' |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 156 | |
| 157 | |
showard | f8b1904 | 2009-05-12 17:22:49 +0000 | [diff] [blame] | 158 | class Test(dbmodels.Model, model_logic.ModelExtensions, |
| 159 | model_logic.ModelWithAttributes): |
| 160 | test_idx = dbmodels.AutoField(primary_key=True) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 161 | job = dbmodels.ForeignKey(Job, db_column='job_idx') |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 162 | test = dbmodels.CharField(max_length=90) |
| 163 | subdir = dbmodels.CharField(blank=True, max_length=180) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 164 | kernel = dbmodels.ForeignKey(Kernel, db_column='kernel_idx') |
| 165 | status = dbmodels.ForeignKey(Status, db_column='status') |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 166 | reason = dbmodels.CharField(blank=True, max_length=3072) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 167 | machine = dbmodels.ForeignKey(Machine, db_column='machine_idx') |
| 168 | finished_time = dbmodels.DateTimeField(null=True, blank=True) |
| 169 | started_time = dbmodels.DateTimeField(null=True, blank=True) |
| 170 | |
showard | f8b1904 | 2009-05-12 17:22:49 +0000 | [diff] [blame] | 171 | objects = model_logic.ExtendedManager() |
| 172 | |
| 173 | def _get_attribute_model_and_args(self, attribute): |
| 174 | return TestAttribute, dict(test=self, attribute=attribute, |
| 175 | user_created=True) |
| 176 | |
| 177 | |
| 178 | def set_attribute(self, attribute, value): |
| 179 | # ensure non-user-created attributes remain immutable |
| 180 | try: |
| 181 | TestAttribute.objects.get(test=self, attribute=attribute, |
| 182 | user_created=False) |
| 183 | raise ValueError('Attribute %s already exists for test %s and is ' |
| 184 | 'immutable' % (attribute, self.test_idx)) |
| 185 | except TestAttribute.DoesNotExist: |
| 186 | super(Test, self).set_attribute(attribute, value) |
| 187 | |
| 188 | |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 189 | class Meta: |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 190 | db_table = 'tko_tests' |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 191 | |
| 192 | |
showard | e732ee7 | 2008-09-23 19:15:43 +0000 | [diff] [blame] | 193 | class TestAttribute(dbmodels.Model, model_logic.ModelExtensions): |
showard | f8b1904 | 2009-05-12 17:22:49 +0000 | [diff] [blame] | 194 | test = dbmodels.ForeignKey(Test, db_column='test_idx') |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 195 | attribute = dbmodels.CharField(max_length=90) |
| 196 | value = dbmodels.CharField(blank=True, max_length=300) |
showard | f8b1904 | 2009-05-12 17:22:49 +0000 | [diff] [blame] | 197 | user_created = dbmodels.BooleanField(default=False) |
| 198 | |
| 199 | objects = model_logic.ExtendedManager() |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 200 | |
| 201 | class Meta: |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 202 | db_table = 'tko_test_attributes' |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 203 | |
| 204 | |
jadmanski | 430dca9 | 2008-12-16 20:56:53 +0000 | [diff] [blame] | 205 | class IterationAttribute(dbmodels.Model, model_logic.ModelExtensions): |
showard | f8b1904 | 2009-05-12 17:22:49 +0000 | [diff] [blame] | 206 | # this isn't really a primary key, but it's necessary to appease Django |
| 207 | # and is harmless as long as we're careful |
showard | e732ee7 | 2008-09-23 19:15:43 +0000 | [diff] [blame] | 208 | test = dbmodels.ForeignKey(Test, db_column='test_idx', primary_key=True) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 209 | iteration = dbmodels.IntegerField() |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 210 | attribute = dbmodels.CharField(max_length=90) |
| 211 | value = dbmodels.CharField(blank=True, max_length=300) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 212 | |
showard | f8b1904 | 2009-05-12 17:22:49 +0000 | [diff] [blame] | 213 | objects = model_logic.ExtendedManager() |
| 214 | |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 215 | class Meta: |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 216 | db_table = 'tko_iteration_attributes' |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 217 | |
| 218 | |
jadmanski | 430dca9 | 2008-12-16 20:56:53 +0000 | [diff] [blame] | 219 | class IterationResult(dbmodels.Model, model_logic.ModelExtensions): |
showard | f8b1904 | 2009-05-12 17:22:49 +0000 | [diff] [blame] | 220 | # see comment on IterationAttribute regarding primary_key=True |
jadmanski | 430dca9 | 2008-12-16 20:56:53 +0000 | [diff] [blame] | 221 | test = dbmodels.ForeignKey(Test, db_column='test_idx', primary_key=True) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 222 | iteration = dbmodels.IntegerField() |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 223 | attribute = dbmodels.CharField(max_length=90) |
| 224 | value = dbmodels.DecimalField(null=True, max_digits=12, decimal_places=31, |
| 225 | blank=True) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 226 | |
showard | f8b1904 | 2009-05-12 17:22:49 +0000 | [diff] [blame] | 227 | objects = model_logic.ExtendedManager() |
| 228 | |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 229 | class Meta: |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 230 | db_table = 'tko_iteration_result' |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 231 | |
| 232 | |
| 233 | class TestLabel(dbmodels.Model, model_logic.ModelExtensions): |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 234 | name = dbmodels.CharField(max_length=80, unique=True) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 235 | description = dbmodels.TextField(blank=True) |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 236 | tests = dbmodels.ManyToManyField(Test, blank=True, |
| 237 | db_table='tko_test_labels_tests') |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 238 | |
| 239 | name_field = 'name' |
showard | f8b1904 | 2009-05-12 17:22:49 +0000 | [diff] [blame] | 240 | objects = model_logic.ExtendedManager() |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 241 | |
| 242 | class Meta: |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 243 | db_table = 'tko_test_labels' |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 244 | |
| 245 | |
| 246 | class SavedQuery(dbmodels.Model, model_logic.ModelExtensions): |
| 247 | # TODO: change this to foreign key once DBs are merged |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 248 | owner = dbmodels.CharField(max_length=80) |
| 249 | name = dbmodels.CharField(max_length=100) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 250 | url_token = dbmodels.TextField() |
| 251 | |
| 252 | class Meta: |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 253 | db_table = 'tko_saved_queries' |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 254 | |
| 255 | |
showard | ce12f55 | 2008-09-19 00:48:59 +0000 | [diff] [blame] | 256 | class EmbeddedGraphingQuery(dbmodels.Model, model_logic.ModelExtensions): |
| 257 | url_token = dbmodels.TextField(null=False, blank=False) |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 258 | graph_type = dbmodels.CharField(max_length=16, null=False, blank=False) |
showard | ce12f55 | 2008-09-19 00:48:59 +0000 | [diff] [blame] | 259 | params = dbmodels.TextField(null=False, blank=False) |
| 260 | last_updated = dbmodels.DateTimeField(null=False, blank=False, |
| 261 | editable=False) |
| 262 | # refresh_time shows the time at which a thread is updating the cached |
| 263 | # image, or NULL if no one is updating the image. This is used so that only |
| 264 | # one thread is updating the cached image at a time (see |
| 265 | # graphing_utils.handle_plot_request) |
| 266 | refresh_time = dbmodels.DateTimeField(editable=False) |
| 267 | cached_png = dbmodels.TextField(editable=False) |
| 268 | |
| 269 | class Meta: |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 270 | db_table = 'tko_embedded_graphing_queries' |
showard | ce12f55 | 2008-09-19 00:48:59 +0000 | [diff] [blame] | 271 | |
| 272 | |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 273 | # views |
| 274 | |
| 275 | class TestViewManager(TempManager): |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 276 | def get_query_set(self): |
| 277 | query = super(TestViewManager, self).get_query_set() |
showard | 5bf7c50 | 2008-08-20 01:22:22 +0000 | [diff] [blame] | 278 | |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 279 | # add extra fields to selects, using the SQL itself as the "alias" |
| 280 | extra_select = dict((sql, sql) |
| 281 | for sql in self.model.extra_fields.iterkeys()) |
| 282 | return query.extra(select=extra_select) |
| 283 | |
| 284 | |
showard | f248952 | 2008-10-23 23:08:00 +0000 | [diff] [blame] | 285 | def _get_include_exclude_suffix(self, exclude): |
| 286 | if exclude: |
showard | 2aa318e | 2009-08-20 23:43:10 +0000 | [diff] [blame] | 287 | return '_exclude' |
| 288 | return '_include' |
| 289 | |
| 290 | |
| 291 | def _add_attribute_join(self, query_set, join_condition, |
| 292 | suffix=None, exclude=False): |
| 293 | if suffix is None: |
| 294 | suffix = self._get_include_exclude_suffix(exclude) |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 295 | return self.add_join(query_set, 'tko_test_attributes', |
| 296 | join_key='test_idx', |
showard | 2aa318e | 2009-08-20 23:43:10 +0000 | [diff] [blame] | 297 | join_condition=join_condition, |
| 298 | suffix=suffix, exclude=exclude) |
| 299 | |
| 300 | |
| 301 | def _add_label_pivot_table_join(self, query_set, suffix, join_condition='', |
| 302 | exclude=False, force_left_join=False): |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 303 | return self.add_join(query_set, 'tko_test_labels_tests', |
| 304 | join_key='test_id', |
showard | 2aa318e | 2009-08-20 23:43:10 +0000 | [diff] [blame] | 305 | join_condition=join_condition, |
| 306 | suffix=suffix, exclude=exclude, |
| 307 | force_left_join=force_left_join) |
showard | f248952 | 2008-10-23 23:08:00 +0000 | [diff] [blame] | 308 | |
| 309 | |
showard | 64aeecd | 2008-09-19 21:32:58 +0000 | [diff] [blame] | 310 | def _add_label_joins(self, query_set, suffix=''): |
showard | 2aa318e | 2009-08-20 23:43:10 +0000 | [diff] [blame] | 311 | query_set = self._add_label_pivot_table_join( |
| 312 | query_set, suffix=suffix, force_left_join=True) |
showard | d50ffb4 | 2008-09-04 02:47:45 +0000 | [diff] [blame] | 313 | |
showard | 2aa318e | 2009-08-20 23:43:10 +0000 | [diff] [blame] | 314 | # since we're not joining from the original table, we can't use |
| 315 | # self.add_join() again |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 316 | second_join_alias = 'tko_test_labels' + suffix |
showard | d50ffb4 | 2008-09-04 02:47:45 +0000 | [diff] [blame] | 317 | second_join_condition = ('%s.id = %s.testlabel_id' % |
showard | 64aeecd | 2008-09-19 21:32:58 +0000 | [diff] [blame] | 318 | (second_join_alias, |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 319 | 'tko_test_labels_tests' + suffix)) |
showard | 64aeecd | 2008-09-19 21:32:58 +0000 | [diff] [blame] | 320 | filter_object = self._CustomSqlQ() |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 321 | filter_object.add_join('tko_test_labels', |
showard | d50ffb4 | 2008-09-04 02:47:45 +0000 | [diff] [blame] | 322 | second_join_condition, |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 323 | query_set.query.LOUTER, |
showard | d50ffb4 | 2008-09-04 02:47:45 +0000 | [diff] [blame] | 324 | alias=second_join_alias) |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 325 | return self._add_customSqlQ(query_set, filter_object) |
showard | d50ffb4 | 2008-09-04 02:47:45 +0000 | [diff] [blame] | 326 | |
showard | 64aeecd | 2008-09-19 21:32:58 +0000 | [diff] [blame] | 327 | |
showard | d50ffb4 | 2008-09-04 02:47:45 +0000 | [diff] [blame] | 328 | def _get_label_ids_from_names(self, label_names): |
showard | 2aa318e | 2009-08-20 23:43:10 +0000 | [diff] [blame] | 329 | label_ids = list( # listifying avoids a double query below |
showard | 8b0ea22 | 2009-12-23 19:23:03 +0000 | [diff] [blame] | 330 | TestLabel.objects.filter(name__in=label_names) |
| 331 | .values_list('name', 'id')) |
showard | 2aa318e | 2009-08-20 23:43:10 +0000 | [diff] [blame] | 332 | if len(label_ids) < len(set(label_names)): |
lmr | 12b4558 | 2010-01-11 21:22:02 +0000 | [diff] [blame^] | 333 | raise ValueError('Not all labels found: %s' % |
| 334 | ', '.join(label_names)) |
showard | 8b0ea22 | 2009-12-23 19:23:03 +0000 | [diff] [blame] | 335 | return dict(name_and_id for name_and_id in label_ids) |
showard | 2aa318e | 2009-08-20 23:43:10 +0000 | [diff] [blame] | 336 | |
| 337 | |
| 338 | def _include_or_exclude_labels(self, query_set, label_names, exclude=False): |
showard | 8b0ea22 | 2009-12-23 19:23:03 +0000 | [diff] [blame] | 339 | label_ids = self._get_label_ids_from_names(label_names).itervalues() |
showard | 2aa318e | 2009-08-20 23:43:10 +0000 | [diff] [blame] | 340 | suffix = self._get_include_exclude_suffix(exclude) |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 341 | condition = ('tko_test_labels_tests%s.testlabel_id IN (%s)' % |
showard | 8b0ea22 | 2009-12-23 19:23:03 +0000 | [diff] [blame] | 342 | (suffix, |
| 343 | ','.join(str(label_id) for label_id in label_ids))) |
showard | 2aa318e | 2009-08-20 23:43:10 +0000 | [diff] [blame] | 344 | return self._add_label_pivot_table_join(query_set, |
| 345 | join_condition=condition, |
| 346 | suffix=suffix, |
| 347 | exclude=exclude) |
showard | 0281350 | 2008-08-20 20:52:56 +0000 | [diff] [blame] | 348 | |
| 349 | |
showard | 8b0ea22 | 2009-12-23 19:23:03 +0000 | [diff] [blame] | 350 | def _add_custom_select(self, query_set, select_name, select_sql): |
| 351 | return query_set.extra(select={select_name: select_sql}) |
| 352 | |
| 353 | |
| 354 | def _add_select_value(self, query_set, alias): |
| 355 | return self._add_custom_select(query_set, alias, |
| 356 | _quote_name(alias) + '.value') |
| 357 | |
| 358 | |
| 359 | def _add_select_ifnull(self, query_set, alias, non_null_value): |
| 360 | select_sql = "IF(%s.id IS NOT NULL, '%s', NULL)" % (_quote_name(alias), |
| 361 | non_null_value) |
| 362 | return self._add_custom_select(query_set, alias, select_sql) |
| 363 | |
| 364 | |
| 365 | def _join_label_column(self, query_set, label_name, label_id): |
| 366 | table_name = TestLabel.tests.field.m2m_db_table() |
| 367 | alias = 'label_' + label_name |
| 368 | condition = "%s.testlabel_id = %s" % (_quote_name(alias), label_id) |
| 369 | query_set = self.add_join(query_set, table_name, |
| 370 | join_key='test_id', join_condition=condition, |
| 371 | alias=alias, force_left_join=True) |
| 372 | |
| 373 | query_set = self._add_select_ifnull(query_set, alias, label_name) |
| 374 | return query_set |
| 375 | |
| 376 | |
| 377 | def _join_label_columns(self, query_set, label_names): |
| 378 | label_id_map = self._get_label_ids_from_names(label_names) |
| 379 | for label_name in label_names: |
| 380 | query_set = self._join_label_column(query_set, label_name, |
| 381 | label_id_map[label_name]) |
| 382 | return query_set |
| 383 | |
| 384 | |
| 385 | def _join_attribute(self, test_view_query_set, attribute, |
| 386 | alias=None, extra_join_condition=None): |
| 387 | """ |
| 388 | Join the given TestView QuerySet to TestAttribute. The resulting query |
| 389 | has an additional column for the given attribute named |
| 390 | "attribute_<attribute name>". |
| 391 | """ |
| 392 | table_name = TestAttribute._meta.db_table |
| 393 | if not alias: |
| 394 | alias = 'attribute_' + attribute |
| 395 | condition = "%s.attribute = '%s'" % (_quote_name(alias), |
| 396 | self.escape_user_sql(attribute)) |
| 397 | if extra_join_condition: |
| 398 | condition += ' AND (%s)' % extra_join_condition |
| 399 | query_set = self.add_join(test_view_query_set, table_name, |
| 400 | join_key='test_idx', join_condition=condition, |
| 401 | alias=alias, force_left_join=True) |
| 402 | |
| 403 | query_set = self._add_select_value(query_set, alias) |
| 404 | return query_set |
| 405 | |
| 406 | |
| 407 | def _join_machine_label_columns(self, query_set, machine_label_names): |
| 408 | for label_name in machine_label_names: |
| 409 | alias = 'machine_label_' + label_name |
| 410 | condition = "FIND_IN_SET('%s', %s)" % ( |
| 411 | label_name, _quote_name(alias) + '.value') |
| 412 | query_set = self._join_attribute(query_set, 'host-labels', |
| 413 | alias=alias, |
| 414 | extra_join_condition=condition) |
| 415 | query_set = self._add_select_ifnull(query_set, alias, label_name) |
| 416 | return query_set |
| 417 | |
| 418 | |
| 419 | def _join_one_iteration_key(self, query_set, result_key, first_alias=None): |
| 420 | table_name = IterationResult._meta.db_table |
| 421 | alias = 'iteration_' + result_key |
| 422 | condition_parts = ["%s.attribute = '%s'" % |
| 423 | (_quote_name(alias), |
| 424 | self.escape_user_sql(result_key))] |
| 425 | if first_alias: |
| 426 | # after the first join, we need to match up iteration indices, |
| 427 | # otherwise each join will expand the query by the number of |
| 428 | # iterations and we'll have extraneous rows |
| 429 | condition_parts.append('%s.iteration = %s.iteration' % |
| 430 | (_quote_name(alias), |
| 431 | _quote_name(first_alias))) |
| 432 | |
| 433 | condition = ' and '.join(condition_parts) |
| 434 | # add a join to IterationResult |
| 435 | query_set = self.add_join(query_set, table_name, join_key='test_idx', |
| 436 | join_condition=condition, alias=alias) |
| 437 | # select the iteration value and index for this join |
| 438 | query_set = self._add_select_value(query_set, alias) |
| 439 | if not first_alias: |
| 440 | # for first join, add iteration index select too |
| 441 | query_set = self._add_custom_select( |
| 442 | query_set, 'iteration_index', |
| 443 | _quote_name(alias) + '.iteration') |
| 444 | |
| 445 | return query_set, alias |
| 446 | |
| 447 | |
| 448 | def _join_iterations(self, test_view_query_set, result_keys): |
| 449 | """Join the given TestView QuerySet to IterationResult for one result. |
| 450 | |
| 451 | The resulting query looks like a TestView query but has one row per |
| 452 | iteration. Each row includes all the attributes of TestView, an |
| 453 | attribute for each key in result_keys and an iteration_index attribute. |
| 454 | |
| 455 | We accomplish this by joining the TestView query to IterationResult |
| 456 | once per result key. Each join is restricted on the result key (and on |
| 457 | the test index, like all one-to-many joins). For the first join, this |
| 458 | is the only restriction, so each TestView row expands to a row per |
| 459 | iteration (per iteration that includes the key, of course). For each |
| 460 | subsequent join, we also restrict the iteration index to match that of |
| 461 | the initial join. This makes each subsequent join produce exactly one |
| 462 | result row for each input row. (This assumes each iteration contains |
| 463 | the same set of keys. Results are undefined if that's not true.) |
| 464 | """ |
| 465 | if not result_keys: |
| 466 | return test_view_query_set |
| 467 | |
| 468 | query_set, first_alias = self._join_one_iteration_key( |
| 469 | test_view_query_set, result_keys[0]) |
| 470 | for result_key in result_keys[1:]: |
| 471 | query_set, _ = self._join_one_iteration_key(query_set, result_key, |
| 472 | first_alias=first_alias) |
| 473 | return query_set |
| 474 | |
| 475 | |
| 476 | def get_query_set_with_joins(self, filter_data): |
| 477 | """ |
| 478 | Add joins for querying over test-related items. |
| 479 | |
| 480 | These parameters are supported going forward: |
| 481 | * test_attribute_fields: list of attribute names. Each attribute will |
| 482 | be available as a column attribute_<name>.value. |
| 483 | * test_label_fields: list of label names. Each label will be available |
| 484 | as a column label_<name>.id, non-null iff the label is present. |
| 485 | * iteration_fields: list of iteration result names. Each |
| 486 | result will be available as a column iteration_<name>.value. |
| 487 | Note that this changes the semantics to return iterations |
| 488 | instead of tests -- if a test has multiple iterations, a row |
| 489 | will be returned for each one. The iteration index is also |
| 490 | available as iteration_<name>.iteration. |
| 491 | * machine_label_fields: list of machine label names. Each will be |
| 492 | available as a column machine_label_<name>.id, non-null iff the |
| 493 | label is present on the machine used in the test. |
| 494 | |
| 495 | These parameters are deprecated: |
| 496 | * include_labels |
| 497 | * exclude_labels |
| 498 | * include_attributes_where |
| 499 | * exclude_attributes_where |
| 500 | |
| 501 | Additionally, this method adds joins if the following strings are |
| 502 | present in extra_where (this is also deprecated): |
| 503 | * test_labels |
| 504 | * test_attributes_host_labels |
| 505 | """ |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 506 | query_set = self.get_query_set() |
showard | 8b0ea22 | 2009-12-23 19:23:03 +0000 | [diff] [blame] | 507 | |
| 508 | test_attributes = filter_data.pop('test_attribute_fields', []) |
| 509 | for attribute in test_attributes: |
| 510 | query_set = self._join_attribute(query_set, attribute) |
| 511 | |
| 512 | test_labels = filter_data.pop('test_label_fields', []) |
| 513 | query_set = self._join_label_columns(query_set, test_labels) |
| 514 | |
| 515 | machine_labels = filter_data.pop('machine_label_fields', []) |
| 516 | query_set = self._join_machine_label_columns(query_set, machine_labels) |
| 517 | |
| 518 | iteration_keys = filter_data.pop('iteration_fields', []) |
| 519 | query_set = self._join_iterations(query_set, iteration_keys) |
| 520 | |
| 521 | # everything that follows is deprecated behavior |
| 522 | |
showard | d50ffb4 | 2008-09-04 02:47:45 +0000 | [diff] [blame] | 523 | joined = False |
showard | 2aa318e | 2009-08-20 23:43:10 +0000 | [diff] [blame] | 524 | |
showard | f248952 | 2008-10-23 23:08:00 +0000 | [diff] [blame] | 525 | extra_where = filter_data.get('extra_where', '') |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 526 | if 'tko_test_labels' in extra_where: |
showard | 0281350 | 2008-08-20 20:52:56 +0000 | [diff] [blame] | 527 | query_set = self._add_label_joins(query_set) |
showard | d50ffb4 | 2008-09-04 02:47:45 +0000 | [diff] [blame] | 528 | joined = True |
| 529 | |
showard | 8b0ea22 | 2009-12-23 19:23:03 +0000 | [diff] [blame] | 530 | include_labels = filter_data.pop('include_labels', []) |
| 531 | exclude_labels = filter_data.pop('exclude_labels', []) |
showard | 2aa318e | 2009-08-20 23:43:10 +0000 | [diff] [blame] | 532 | if include_labels: |
| 533 | query_set = self._include_or_exclude_labels(query_set, |
| 534 | include_labels) |
showard | fc8c6ae | 2008-11-11 19:06:01 +0000 | [diff] [blame] | 535 | joined = True |
showard | 2aa318e | 2009-08-20 23:43:10 +0000 | [diff] [blame] | 536 | if exclude_labels: |
| 537 | query_set = self._include_or_exclude_labels(query_set, |
| 538 | exclude_labels, |
| 539 | exclude=True) |
showard | 64aeecd | 2008-09-19 21:32:58 +0000 | [diff] [blame] | 540 | joined = True |
| 541 | |
| 542 | include_attributes_where = filter_data.pop('include_attributes_where', |
| 543 | '') |
| 544 | exclude_attributes_where = filter_data.pop('exclude_attributes_where', |
| 545 | '') |
| 546 | if include_attributes_where: |
| 547 | query_set = self._add_attribute_join( |
showard | 2aa318e | 2009-08-20 23:43:10 +0000 | [diff] [blame] | 548 | query_set, |
| 549 | join_condition=self.escape_user_sql(include_attributes_where)) |
showard | 64aeecd | 2008-09-19 21:32:58 +0000 | [diff] [blame] | 550 | joined = True |
| 551 | if exclude_attributes_where: |
| 552 | query_set = self._add_attribute_join( |
showard | 2aa318e | 2009-08-20 23:43:10 +0000 | [diff] [blame] | 553 | query_set, |
| 554 | join_condition=self.escape_user_sql(exclude_attributes_where), |
showard | 64aeecd | 2008-09-19 21:32:58 +0000 | [diff] [blame] | 555 | exclude=True) |
| 556 | joined = True |
showard | d50ffb4 | 2008-09-04 02:47:45 +0000 | [diff] [blame] | 557 | |
| 558 | if not joined: |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 559 | filter_data['no_distinct'] = True |
showard | d50ffb4 | 2008-09-04 02:47:45 +0000 | [diff] [blame] | 560 | |
showard | 8b0ea22 | 2009-12-23 19:23:03 +0000 | [diff] [blame] | 561 | if 'tko_test_attributes_host_labels' in extra_where: |
showard | f248952 | 2008-10-23 23:08:00 +0000 | [diff] [blame] | 562 | query_set = self._add_attribute_join( |
| 563 | query_set, suffix='_host_labels', |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 564 | join_condition='tko_test_attributes_host_labels.attribute = ' |
showard | f248952 | 2008-10-23 23:08:00 +0000 | [diff] [blame] | 565 | '"host-labels"') |
| 566 | |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 567 | return query_set |
| 568 | |
| 569 | |
showard | 8bfb5cb | 2009-10-07 20:49:15 +0000 | [diff] [blame] | 570 | def query_test_ids(self, filter_data, apply_presentation=True): |
| 571 | query = self.model.query_objects(filter_data, |
| 572 | apply_presentation=apply_presentation) |
| 573 | dicts = query.values('test_idx') |
showard | 0281350 | 2008-08-20 20:52:56 +0000 | [diff] [blame] | 574 | return [item['test_idx'] for item in dicts] |
| 575 | |
| 576 | |
showard | 0281350 | 2008-08-20 20:52:56 +0000 | [diff] [blame] | 577 | def query_test_label_ids(self, filter_data): |
showard | d50ffb4 | 2008-09-04 02:47:45 +0000 | [diff] [blame] | 578 | query_set = self.model.query_objects(filter_data) |
| 579 | query_set = self._add_label_joins(query_set, suffix='_list') |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 580 | rows = self._custom_select_query(query_set, ['tko_test_labels_list.id']) |
showard | d50ffb4 | 2008-09-04 02:47:45 +0000 | [diff] [blame] | 581 | return [row[0] for row in rows if row[0] is not None] |
showard | 0281350 | 2008-08-20 20:52:56 +0000 | [diff] [blame] | 582 | |
| 583 | |
showard | eaccf8f | 2009-04-16 03:11:33 +0000 | [diff] [blame] | 584 | def escape_user_sql(self, sql): |
| 585 | sql = super(TestViewManager, self).escape_user_sql(sql) |
| 586 | return sql.replace('test_idx', self.get_key_on_this_table('test_idx')) |
| 587 | |
| 588 | |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 589 | class TestView(dbmodels.Model, model_logic.ModelExtensions): |
| 590 | extra_fields = { |
showard | f4c702e | 2009-07-08 21:14:27 +0000 | [diff] [blame] | 591 | 'DATE(job_queued_time)': 'job queued day', |
| 592 | 'DATE(test_finished_time)': 'test finished day', |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | group_fields = [ |
showard | f4c702e | 2009-07-08 21:14:27 +0000 | [diff] [blame] | 596 | 'test_name', |
| 597 | 'status', |
| 598 | 'kernel', |
| 599 | 'hostname', |
| 600 | 'job_tag', |
| 601 | 'job_name', |
| 602 | 'platform', |
| 603 | 'reason', |
| 604 | 'job_owner', |
| 605 | 'job_queued_time', |
| 606 | 'DATE(job_queued_time)', |
| 607 | 'test_started_time', |
| 608 | 'test_finished_time', |
| 609 | 'DATE(test_finished_time)', |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 610 | ] |
| 611 | |
| 612 | test_idx = dbmodels.IntegerField('test index', primary_key=True) |
| 613 | job_idx = dbmodels.IntegerField('job index', null=True, blank=True) |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 614 | test_name = dbmodels.CharField(blank=True, max_length=90) |
| 615 | subdir = dbmodels.CharField('subdirectory', blank=True, max_length=180) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 616 | kernel_idx = dbmodels.IntegerField('kernel index') |
| 617 | status_idx = dbmodels.IntegerField('status index') |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 618 | reason = dbmodels.CharField(blank=True, max_length=3072) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 619 | machine_idx = dbmodels.IntegerField('host index') |
| 620 | test_started_time = dbmodels.DateTimeField(null=True, blank=True) |
| 621 | test_finished_time = dbmodels.DateTimeField(null=True, blank=True) |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 622 | job_tag = dbmodels.CharField(blank=True, max_length=300) |
| 623 | job_name = dbmodels.CharField(blank=True, max_length=300) |
| 624 | job_owner = dbmodels.CharField('owner', blank=True, max_length=240) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 625 | job_queued_time = dbmodels.DateTimeField(null=True, blank=True) |
| 626 | job_started_time = dbmodels.DateTimeField(null=True, blank=True) |
| 627 | job_finished_time = dbmodels.DateTimeField(null=True, blank=True) |
showard | c1c1caf | 2009-09-08 16:26:50 +0000 | [diff] [blame] | 628 | afe_job_id = dbmodels.IntegerField(null=True) |
showard | a5288b4 | 2009-07-28 20:06:08 +0000 | [diff] [blame] | 629 | hostname = dbmodels.CharField(blank=True, max_length=300) |
| 630 | platform = dbmodels.CharField(blank=True, max_length=240) |
| 631 | machine_owner = dbmodels.CharField(blank=True, max_length=240) |
| 632 | kernel_hash = dbmodels.CharField(blank=True, max_length=105) |
| 633 | kernel_base = dbmodels.CharField(blank=True, max_length=90) |
| 634 | kernel = dbmodels.CharField(blank=True, max_length=300) |
| 635 | status = dbmodels.CharField(blank=True, max_length=30) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 636 | |
| 637 | objects = TestViewManager() |
| 638 | |
| 639 | def save(self): |
| 640 | raise NotImplementedError('TestView is read-only') |
| 641 | |
| 642 | |
| 643 | def delete(self): |
| 644 | raise NotImplementedError('TestView is read-only') |
| 645 | |
| 646 | |
| 647 | @classmethod |
showard | 8bfb5cb | 2009-10-07 20:49:15 +0000 | [diff] [blame] | 648 | def query_objects(cls, filter_data, initial_query=None, |
| 649 | apply_presentation=True): |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 650 | if initial_query is None: |
showard | 64aeecd | 2008-09-19 21:32:58 +0000 | [diff] [blame] | 651 | initial_query = cls.objects.get_query_set_with_joins(filter_data) |
showard | 8bfb5cb | 2009-10-07 20:49:15 +0000 | [diff] [blame] | 652 | return super(TestView, cls).query_objects( |
| 653 | filter_data, initial_query=initial_query, |
| 654 | apply_presentation=apply_presentation) |
showard | 3544486 | 2008-08-07 22:35:30 +0000 | [diff] [blame] | 655 | |
| 656 | |
| 657 | class Meta: |
showard | eab66ce | 2009-12-23 00:03:56 +0000 | [diff] [blame] | 658 | db_table = 'tko_test_view_2' |