Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: appengine/findit/model/versioned_config.py

Issue 1499583002: [Findit] Add a model to provide versioning and also a verioned config model. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Add versioned config model. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Versioned singleton entity with the global configuration."""
6
7 import logging
8
9 from google.appengine.api import users
10 from google.appengine.ext import ndb
11
12 from model.versioned_model import VersionedModel
13
14
15 class VersionedConfig(VersionedModel):
16 """Singleton entity with the global configuration of the service.
17
18 All changes are stored in the revision log.
19 """
20
21 # When this revision of configuration was created.
22 updated_ts = ndb.DateTimeProperty(indexed=False, auto_now_add=True)
23
24 # Who created this revision of configuration.
25 updated_by = ndb.StringProperty(indexed=False)
26
27 @classmethod
28 def Get(cls):
29 """Returns the current up-to-date version of the config entity."""
30 return cls.GetMostRecentVersion() or cls()
31
32 def Update(self, **kwargs):
33 """Applies |kwargs| dict to the entity and stores the entity if changed."""
34 if not users.is_current_user_admin():
35 raise Exception('Only admin could update config.')
36
37 dirty = False
38 for k, v in kwargs.iteritems():
39 assert k in self._properties, k
40 if getattr(self, k) != v:
41 setattr(self, k, v)
42 dirty = True
43
44 if dirty:
45 user_name = users.get_current_user().email().split('@')[0]
46 self.updated_by = user_name
47 self.Save()
48 logging.info('Config %s was updated by %s', self.__class__, user_name)
49
50 return dirty
OLDNEW
« no previous file with comments | « appengine/findit/model/test/versioned_model_test.py ('k') | appengine/findit/model/versioned_model.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698