You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by je...@apache.org on 2015/07/03 13:04:53 UTC
[2/3] allura git commit: [#7894] Move skip_mod_date into Allura
[#7894] Move skip_mod_date into Allura
Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/6e8e6f33
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/6e8e6f33
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/6e8e6f33
Branch: refs/heads/master
Commit: 6e8e6f33f5501290cbea052e99044a15a54beeeb
Parents: 23bcdc9
Author: Heith Seewald <hs...@slashdotmedia.com>
Authored: Mon Jun 29 14:36:55 2015 -0400
Committer: Heith Seewald <hs...@slashdotmedia.com>
Committed: Thu Jul 2 11:08:58 2015 -0400
----------------------------------------------------------------------
Allura/allura/lib/utils.py | 12 ++++++++++++
Allura/allura/tests/test_utils.py | 8 ++++++++
2 files changed, 20 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/allura/blob/6e8e6f33/Allura/allura/lib/utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/utils.py b/Allura/allura/lib/utils.py
index 143868e..f812e2e 100644
--- a/Allura/allura/lib/utils.py
+++ b/Allura/allura/lib/utils.py
@@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+from contextlib import contextmanager
import time
import string
@@ -21,6 +22,7 @@ import hashlib
import binascii
import logging.handlers
import codecs
+from ming.odm import session
import os.path
import datetime
import random
@@ -614,3 +616,13 @@ def clean_phone_number(number):
def phone_number_hash(number):
number = clean_phone_number(number)
return hashlib.sha1(number).hexdigest()
+
+
+@contextmanager
+def skip_mod_date(model_cls):
+ skip_mod_date = getattr(session(model_cls)._get(), 'skip_mod_date', False)
+ session(model_cls)._get().skip_mod_date = True
+ try:
+ yield
+ finally:
+ session(model_cls)._get().skip_mod_date = skip_mod_date
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/allura/blob/6e8e6f33/Allura/allura/tests/test_utils.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_utils.py b/Allura/allura/tests/test_utils.py
index 5043e3d..39d61b3 100644
--- a/Allura/allura/tests/test_utils.py
+++ b/Allura/allura/tests/test_utils.py
@@ -21,6 +21,8 @@ import json
import time
import unittest
import datetime as dt
+from ming.odm import session
+import model as M
from os import path
from webob import Request
@@ -323,3 +325,9 @@ def test_phone_number_hash():
hash = utils.phone_number_hash
assert_equal(hash('1234567890'), hash('+123 456:7890'))
assert_not_equal(hash('1234567890'), hash('1234567891'))
+
+
+def test_skip_mod_date():
+ with utils.skip_mod_date(M.Artifact):
+ assert getattr(session(M.Artifact)._get(), 'skip_mod_date', None) == True
+ assert getattr(session(M.Artifact)._get(), 'skip_mod_date', None) == False
\ No newline at end of file