You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2019/11/15 23:32:05 UTC

[allura] 03/07: misc

This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/8340
in repository https://gitbox.apache.org/repos/asf/allura.git

commit d3f789d99e9f9224b2337f539f6b005c660dd10f
Author: Dave Brondsema <da...@brondsema.net>
AuthorDate: Fri Nov 15 12:42:51 2019 -0500

    misc
---
 Allura/allura/lib/macro.py          |  2 +-
 Allura/allura/lib/stats.py          | 85 -------------------------------------
 Allura/allura/tests/test_globals.py | 11 +++++
 3 files changed, 12 insertions(+), 86 deletions(-)

diff --git a/Allura/allura/lib/macro.py b/Allura/allura/lib/macro.py
index b01eaad..4dc1f54 100644
--- a/Allura/allura/lib/macro.py
+++ b/Allura/allura/lib/macro.py
@@ -312,7 +312,7 @@ def project_screenshots():
     from allura.lib.widgets.project_list import ProjectScreenshots
     ps = ProjectScreenshots()
     g.resource_manager.register(ps)
-    response = ps.display(project=c.project)
+    response = ps.display(project=c.project, h=h)
     return response
 
 
diff --git a/Allura/allura/lib/stats.py b/Allura/allura/lib/stats.py
deleted file mode 100644
index d5244b1..0000000
--- a/Allura/allura/lib/stats.py
+++ /dev/null
@@ -1,85 +0,0 @@
-#       Licensed to the Apache Software Foundation (ASF) under one
-#       or more contributor license agreements.  See the NOTICE file
-#       distributed with this work for additional information
-#       regarding copyright ownership.  The ASF licenses this file
-#       to you under the Apache License, Version 2.0 (the
-#       "License"); you may not use this file except in compliance
-#       with the License.  You may obtain a copy of the License at
-#
-#         http://www.apache.org/licenses/LICENSE-2.0
-#
-#       Unless required by applicable law or agreed to in writing,
-#       software distributed under the License is distributed on an
-#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-#       KIND, either express or implied.  See the License for the
-#       specific language governing permissions and limitations
-#       under the License.
-
-from __future__ import with_statement
-from time import time
-from contextlib import contextmanager
-from tg import request
-
-
-class StatsRecord(object):
-
-    def __init__(self, request, active):
-        self.timers = dict(
-            mongo=0,
-            template=0,
-            total=0)
-        self.url = request.environ['PATH_INFO']
-        self.active = active
-        # Avoid double-timing things
-        self._now_timing = set()
-
-    def __repr__(self):
-        stats = ' '.join(
-            ('%s=%.0fms' % (k, v * 1000))
-            for k, v in sorted(self.timers.iteritems()))
-        return '%s: %s' % (self.url, stats)
-
-    def asdict(self):
-        return dict(
-            url=self.url,
-            timers=self.timers)
-
-    @contextmanager
-    def timing(self, name):
-        if self.active and name not in self._now_timing:
-            self._now_timing.add(name)
-            self.timers.setdefault(name, 0)
-            begin = time()
-            try:
-                yield
-            finally:
-                end = time()
-                self.timers[name] += end - begin
-                self._now_timing.remove(name)
-        else:
-            yield
-
-
-class timing(object):
-
-    '''Decorator to time a method call'''
-
-    def __init__(self, timer):
-        self.timer = timer
-
-    def __call__(self, func):
-        def inner(*l, **kw):
-            try:
-                stats = request.environ['sf.stats']
-            except TypeError:
-                return func(*l, **kw)
-            with stats.timing(self.timer):
-                return func(*l, **kw)
-        inner.__name__ = func.__name__
-        return inner
-
-    def decorate(self, obj, names):
-        names = names.split()
-        for name in names:
-            setattr(obj, name,
-                    self(getattr(obj, name)))
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 7176654..f7b2be4 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -667,6 +667,17 @@ def test_project_blog_posts_macro():
         assert_in('by <em>Test Admin</em>', r)
 
 
+def test_project_screenshots_macro():
+    with h.push_context('test', neighborhood='Projects'):
+        M.ProjectFile(project_id=c.project._id, category='screenshot', caption='caption', filename='test_file.jpg')
+        ThreadLocalORMSession.flush_all()
+
+        r = g.markdown_wiki.convert('[[project_screenshots]]')
+
+        assert_in('href="/p/test/screenshot/test_file.jpg"', r)
+        assert_in('src="/p/test/screenshot/test_file.jpg/thumb"', r)
+
+
 def get_project_names(r):
     """
     Extracts a list of project names from a wiki page HTML.