Chromium Code Reviews| Index: appengine/findit/model/base_model.py |
| diff --git a/appengine/findit/model/base_model.py b/appengine/findit/model/base_model.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3f4c013ce3ebd12d18dd299187422f7544e54070 |
| --- /dev/null |
| +++ b/appengine/findit/model/base_model.py |
| @@ -0,0 +1,27 @@ |
| +# Copyright (c) 2014 The Chromium Authors. All rights reserved. |
|
qyearsley
2015/01/07 06:59:46
Note, the "(c)" isn't necessary, and can be remove
stgao
2015/01/09 01:28:23
Good catch.
Done for files in this CL.
For other f
|
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +from google.appengine.ext import ndb |
| + |
| + |
| +class BaseModel(ndb.Model): # pragma: no cover |
| + """A base class to provide computed properties from the key. |
|
qyearsley
2015/01/07 06:59:46
This looks like a good idea. Possible alternative
stgao
2015/01/09 01:28:23
I like BaseBuildModel better.
Done.
|
| + |
| + The computed properties are master name, builder name, and build number. |
| + Subclasses should set its key as: |
| + ndb.Key('KindName', master_name, 'KindName', builder_name, |
| + 'KindName', build_number, 'Optional_KindName', optional_id, ...) |
| + """ |
| + |
| + @ndb.ComputedProperty |
| + def master_name(self): |
| + return self.key.pairs()[0][1] |
| + |
| + @ndb.ComputedProperty |
| + def builder_name(self): |
| + return self.key.pairs()[1][1] |
| + |
| + @ndb.ComputedProperty |
| + def build_number(self): |
| + return self.key.pairs()[2][1] |