allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tvansteenbu...@apache.org
Subject [2/2] git commit: [#6207] ticket:466 Expand markdown caching to all articat types
Date Thu, 07 Nov 2013 17:40:21 GMT
[#6207] ticket:466 Expand markdown caching to all articat types


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/56db185f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/56db185f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/56db185f

Branch: refs/heads/master
Commit: 56db185f777a8d1e78a15fbb47803594177fd8f9
Parents: 062d1d8
Author: Andrej Aleksandrov <pinelounge@gmail.com>
Authored: Wed Nov 6 10:35:58 2013 +0200
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Thu Nov 7 17:15:46 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/project.py                          | 2 +-
 Allura/allura/lib/app_globals.py                              | 3 +++
 Allura/allura/lib/macro.py                                    | 6 +++---
 Allura/allura/model/artifact.py                               | 3 ++-
 Allura/allura/model/discuss.py                                | 1 +
 Allura/allura/model/neighborhood.py                           | 2 ++
 Allura/allura/model/oauth.py                                  | 7 +++++--
 Allura/allura/model/project.py                                | 4 +++-
 Allura/allura/templates/widgets/discussion_header.html        | 2 +-
 Allura/allura/tests/test_globals.py                           | 3 +++
 ForgeBlog/forgeblog/model/blog.py                             | 4 +++-
 ForgeChat/forgechat/model/chat.py                             | 4 ++++
 ForgeChat/forgechat/templates/chat/day.html                   | 2 +-
 .../templates/discussion_widgets/forum_header.html            | 2 +-
 .../templates/discussionforums/admin_forums.html              | 2 +-
 .../forgediscussion/templates/discussionforums/index.html     | 2 +-
 ForgeTracker/forgetracker/model/ticket.py                     | 1 +
 ForgeTracker/forgetracker/templates/tracker/ticket.html       | 2 +-
 ForgeWiki/forgewiki/model/wiki.py                             | 6 +++++-
 19 files changed, 42 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index 0dbb3c3..ebaeaa3 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -164,7 +164,7 @@ class NeighborhoodController(object):
         ]
         return dict(neighborhood=self.neighborhood,
                     title="Welcome to " + self.neighborhood.name,
-                    text=g.markdown.convert(self.neighborhood.homepage),
+                    text=g.markdown.cached_convert(self.neighborhood, 'homepage'),
                     projects=projects,
                     sort=sort,
                     limit=limit, page=page, count=count)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/Allura/allura/lib/app_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 2ea8163..431f210 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -88,6 +88,9 @@ class ForgeMarkdown(markdown.Markdown):
 
         """
         source_text = getattr(artifact, field_name)
+        # Check if contents macro and never cache
+        if "[[" in source_text:
+            return self.convert(source_text)
         cache_field_name = field_name + '_cache'
         cache = getattr(artifact, cache_field_name, None)
         if not cache:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/Allura/allura/lib/macro.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/macro.py b/Allura/allura/lib/macro.py
index 97d5206..d4c974e 100644
--- a/Allura/allura/lib/macro.py
+++ b/Allura/allura/lib/macro.py
@@ -95,7 +95,7 @@ def neighborhood_feeds(tool_name, max_number=5, sort='pubdate'):
                 title=item.title,
                 author=item.author_name,
                 ago=h.ago(item.pubdate),
-                description=g.markdown.convert(item.description)))
+                description=g.markdown.cached_convert(item, 'description')))
         for item in feed)
     feeds = NeighborhoodFeeds(feeds=output)
     g.resource_manager.register(feeds)
@@ -115,7 +115,7 @@ def neighborhood_blog_posts(max_number=5, sort='timestamp', summary=False):
                 title=post.title,
                 author=post.author().display_name,
                 ago=h.ago(post.timestamp),
-                description=summary and '&nbsp;' or g.markdown.convert(post.text)))
+                description=summary and '&nbsp;' or g.markdown.cached_convert(post, 'text')))
         for post in posts if post.app and
                              security.has_access(post, 'read', project=post.app.project)()
and
                              security.has_access(post.app.project, 'read', project=post.app.project)())
@@ -143,7 +143,7 @@ def project_blog_posts(max_number=5, sort='timestamp', summary=False,
mount_poin
                 title=post.title,
                 author=post.author().display_name,
                 ago=h.ago(post.timestamp),
-                description=summary and '&nbsp;' or g.markdown.convert(post.text)))
+                description=summary and '&nbsp;' or g.markdown.cached_convert(post, 'text')))
         for post in posts if security.has_access(post, 'read', project=post.app.project)()
and
                              security.has_access(post.app.project, 'read', project=post.app.project)())
     posts = BlogPosts(posts=output)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 5b288d5..40ccb5e 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -37,7 +37,7 @@ from .session import main_doc_session, main_orm_session
 from .session import project_doc_session, project_orm_session
 from .session import artifact_orm_session
 from .index import ArtifactReference
-from .types import ACL, ACE
+from .types import ACL, ACE, MarkdownCache
 from .project import AppConfig
 from .notification import MailFooter
 
@@ -743,6 +743,7 @@ class Feed(MappedClass):
     link=FieldProperty(str)
     pubdate = FieldProperty(datetime, if_missing=datetime.utcnow)
     description = FieldProperty(str)
+    description_cache = FieldProperty(MarkdownCache)
     unique_id = FieldProperty(str, if_missing=lambda:h.nonce(40))
     author_name = FieldProperty(str, if_missing=lambda:c.user.get_pref('display_name') if
hasattr(c, 'user') else None)
     author_link = FieldProperty(str, if_missing=lambda:c.user.url() if hasattr(c, 'user')
else None)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/Allura/allura/model/discuss.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/discuss.py b/Allura/allura/model/discuss.py
index a021c12..df55ac9 100644
--- a/Allura/allura/model/discuss.py
+++ b/Allura/allura/model/discuss.py
@@ -51,6 +51,7 @@ class Discussion(Artifact, ActivityObject):
     shortname = FieldProperty(str)
     name = FieldProperty(str)
     description = FieldProperty(str, if_missing='')
+    description_cache = FieldProperty(MarkdownCache)
     num_topics = FieldProperty(int, if_missing=0)
     num_posts = FieldProperty(int, if_missing=0)
     subscriptions = FieldProperty({str: bool})

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/Allura/allura/model/neighborhood.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/neighborhood.py b/Allura/allura/model/neighborhood.py
index 5c4a928..7fd98e3 100644
--- a/Allura/allura/model/neighborhood.py
+++ b/Allura/allura/model/neighborhood.py
@@ -32,6 +32,7 @@ from allura.lib import plugin
 
 from .session import main_orm_session
 from .filesystem import File
+from .types import MarkdownCache
 
 log = logging.getLogger(__name__)
 
@@ -67,6 +68,7 @@ class Neighborhood(MappedClass):
     shortname_prefix = FieldProperty(str, if_missing='')
     css = FieldProperty(str, if_missing='')
     homepage = FieldProperty(str, if_missing='')
+    homepage_cache = FieldProperty(MarkdownCache)
     redirect = FieldProperty(str, if_missing='')
     projects = RelationProperty('Project')
     allow_browse = FieldProperty(bool, if_missing=True)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/Allura/allura/model/oauth.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/oauth.py b/Allura/allura/model/oauth.py
index 5f9344c..531fceb 100644
--- a/Allura/allura/model/oauth.py
+++ b/Allura/allura/model/oauth.py
@@ -27,6 +27,7 @@ from ming.orm.declarative import MappedClass
 from allura.lib import helpers as h
 from .session import main_doc_session, main_orm_session
 from .session import project_doc_session, project_orm_session
+from .types import MarkdownCache
 
 log = logging.getLogger(__name__)
 
@@ -59,12 +60,14 @@ class OAuthConsumerToken(OAuthToken):
     user_id = ForeignIdProperty('User', if_missing=lambda:c.user._id)
     name = FieldProperty(str)
     description = FieldProperty(str)
-    
+    description_cache = FieldProperty(MarkdownCache)
+
+
     user = RelationProperty('User')
 
     @property
     def description_html(self):
-        return g.markdown.convert(self.description)
+        return g.markdown.cached_convert(self, 'description')
 
     @property
     def consumer(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index e1cae14..d8584ef 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -42,6 +42,7 @@ from allura.lib import exceptions
 from allura.lib import security
 from allura.lib import validators as v
 from allura.lib.security import has_access
+from allura.model.types import MarkdownCache
 
 from .session import main_orm_session
 from .session import project_orm_session, project_doc_session
@@ -175,6 +176,7 @@ class Project(MappedClass, ActivityNode, ActivityObject):
     short_description=FieldProperty(str, if_missing='')
     summary=FieldProperty(str, if_missing='')
     description=FieldProperty(str, if_missing='')
+    description_cache = FieldProperty(MarkdownCache)
     homepage_title=FieldProperty(str, if_missing='')
     external_homepage=FieldProperty(str, if_missing='')
     support_page=FieldProperty(str, if_missing='')
@@ -321,7 +323,7 @@ class Project(MappedClass, ActivityNode, ActivityObject):
 
     @property
     def description_html(self):
-        return g.markdown.convert(self.description)
+        return g.markdown.cached_convert(self, 'description')
 
     @property
     def parent_project(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/Allura/allura/templates/widgets/discussion_header.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/widgets/discussion_header.html b/Allura/allura/templates/widgets/discussion_header.html
index 801a21a..b464bfa 100644
--- a/Allura/allura/templates/widgets/discussion_header.html
+++ b/Allura/allura/templates/widgets/discussion_header.html
@@ -16,4 +16,4 @@
        specific language governing permissions and limitations
        under the License.
 -#}
-<div>{{g.markdown.convert(value.description)|safe}}</div>
\ No newline at end of file
+<div>{{g.markdown.cached_convert(value, 'description')|safe}}</div>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/Allura/allura/tests/test_globals.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_globals.py b/Allura/allura/tests/test_globals.py
index 94f3ced..32cdffd 100644
--- a/Allura/allura/tests/test_globals.py
+++ b/Allura/allura/tests/test_globals.py
@@ -598,6 +598,9 @@ class TestCachedMarkdown(unittest.TestCase):
             html = self.md.cached_convert(self.post, 'text')
             self.assertEqual(html, self.expected_html)
             self.assertFalse(convert_func.called)
+            self.post.text = u"text [[macro]] pass"
+            html = self.md.cached_convert(self.post, 'text')
+            self.assertTrue(convert_func.called)
 
     @patch.dict('allura.lib.app_globals.config', {})
     def test_no_threshold_defined(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/ForgeBlog/forgeblog/model/blog.py
----------------------------------------------------------------------
diff --git a/ForgeBlog/forgeblog/model/blog.py b/ForgeBlog/forgeblog/model/blog.py
index b6984d8..2d8f0fd 100644
--- a/ForgeBlog/forgeblog/model/blog.py
+++ b/ForgeBlog/forgeblog/model/blog.py
@@ -29,6 +29,7 @@ from ming.orm.declarative import MappedClass
 
 from allura import model as M
 from allura.model.timeline import ActivityObject
+from allura.model.types import MarkdownCache
 from allura.lib import helpers as h
 from allura.lib import utils
 
@@ -105,6 +106,7 @@ class BlogPost(M.VersionedArtifact, ActivityObject):
 
     title = FieldProperty(str, if_missing='Untitled')
     text = FieldProperty(str, if_missing='')
+    text_cache = FieldProperty(MarkdownCache)
     timestamp = FieldProperty(datetime, if_missing=datetime.utcnow)
     slug = FieldProperty(str)
     state = FieldProperty(schema.OneOf('draft', 'published'), if_missing='draft')
@@ -132,7 +134,7 @@ class BlogPost(M.VersionedArtifact, ActivityObject):
 
     @property
     def html_text(self):
-        return g.markdown.convert(self.text)
+        return g.markdown.cached_convert(self, 'text')
 
     @property
     def html_text_preview(self):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/ForgeChat/forgechat/model/chat.py
----------------------------------------------------------------------
diff --git a/ForgeChat/forgechat/model/chat.py b/ForgeChat/forgechat/model/chat.py
index 981dd38..d2baeda 100644
--- a/ForgeChat/forgechat/model/chat.py
+++ b/ForgeChat/forgechat/model/chat.py
@@ -22,6 +22,8 @@ from ming.orm import FieldProperty, Mapper
 from ming.orm.declarative import MappedClass
 
 from allura import model as M
+from allura.model.types import MarkdownCache
+
 
 class ChatChannel(MappedClass):
 
@@ -46,6 +48,8 @@ class ChatMessage(M.Artifact):
     sender = FieldProperty(str, if_missing='')
     channel = FieldProperty(str, if_missing='')
     text = FieldProperty(str, if_missing='')
+    text_cache = FieldProperty(MarkdownCache)
+
 
     def index_id(self):
         id = 'Chat-%s:%s:%s.%s' % (

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/ForgeChat/forgechat/templates/chat/day.html
----------------------------------------------------------------------
diff --git a/ForgeChat/forgechat/templates/chat/day.html b/ForgeChat/forgechat/templates/chat/day.html
index 913eb7d..26ddcac 100644
--- a/ForgeChat/forgechat/templates/chat/day.html
+++ b/ForgeChat/forgechat/templates/chat/day.html
@@ -44,7 +44,7 @@
             {{msg.sender_short}}
           </div>
         </div>
-        <div style='margin-left:13em'>{{g.markdown.convert(msg.text) | safe}}</div>
+        <div style='margin-left:13em'>{{g.markdown.cached_convert(msg, 'text') | safe}}</div>
       </div>
       <div style='clear:both'></div>
     </li>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/ForgeDiscussion/forgediscussion/templates/discussion_widgets/forum_header.html
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/templates/discussion_widgets/forum_header.html
b/ForgeDiscussion/forgediscussion/templates/discussion_widgets/forum_header.html
index 77507d6..18b6e48 100644
--- a/ForgeDiscussion/forgediscussion/templates/discussion_widgets/forum_header.html
+++ b/ForgeDiscussion/forgediscussion/templates/discussion_widgets/forum_header.html
@@ -18,7 +18,7 @@
 -#}
 {% import 'allura:templates/jinja_master/lib.html' as lib with context %}
 
-{{g.markdown.convert(value.description)|safe}}
+{{g.markdown.cached_convert(value, 'description')|safe}}
 
 {% if value.announcements %}
   <h3>Announcements</h3>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/ForgeDiscussion/forgediscussion/templates/discussionforums/admin_forums.html
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/templates/discussionforums/admin_forums.html
b/ForgeDiscussion/forgediscussion/templates/discussionforums/admin_forums.html
index 44d8905..2284a5d 100644
--- a/ForgeDiscussion/forgediscussion/templates/discussionforums/admin_forums.html
+++ b/ForgeDiscussion/forgediscussion/templates/discussionforums/admin_forums.html
@@ -81,7 +81,7 @@
             </span>
           </div>
           <div class="editable viewing">
-            <div class="viewer">{{g.markdown.convert(forum.description)|safe}}</div>
+            <div class="viewer">{{g.markdown.cached_convert(forum, 'description')|safe}}</div>
             <span class="editor multiline">
               {{lib.text_area('forum-%s.description' % loop.index0, 'Description', h.really_unicode(forum.description))}}
             </span>

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/ForgeDiscussion/forgediscussion/templates/discussionforums/index.html
----------------------------------------------------------------------
diff --git a/ForgeDiscussion/forgediscussion/templates/discussionforums/index.html b/ForgeDiscussion/forgediscussion/templates/discussionforums/index.html
index ca65594..9103386 100644
--- a/ForgeDiscussion/forgediscussion/templates/discussionforums/index.html
+++ b/ForgeDiscussion/forgediscussion/templates/discussionforums/index.html
@@ -53,7 +53,7 @@
       <tr>
         <td>
           <strong><a href="{{forum.url()}}">{{forum.name}}</a></strong><br>
-          {{g.markdown.convert(forum.description)}}
+          {{g.markdown.cached_convert(forum, 'description')}}
           {% if forum.deleted %}
             <div class="notice">This forum has been deleted and is not visible to non-admin
users</div>
           {% endif %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index 50ec351..2dfa186 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -584,6 +584,7 @@ class Ticket(VersionedArtifact, ActivityObject, VotableArtifact):
     ticket_num = FieldProperty(int, required=True, allow_none=False)
     summary = FieldProperty(str)
     description = FieldProperty(str, if_missing='')
+    description_cache = FieldProperty(MarkdownCache)
     reported_by_id = ForeignIdProperty(User, if_missing=lambda:c.user._id)
     assigned_to_id = ForeignIdProperty(User, if_missing=None)
     milestone = FieldProperty(str, if_missing='')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/ForgeTracker/forgetracker/templates/tracker/ticket.html
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/templates/tracker/ticket.html b/ForgeTracker/forgetracker/templates/tracker/ticket.html
index 95e40a6..1709778 100644
--- a/ForgeTracker/forgetracker/templates/tracker/ticket.html
+++ b/ForgeTracker/forgetracker/templates/tracker/ticket.html
@@ -142,7 +142,7 @@
   {{ c.vote_form.display(artifact=ticket) }}
 {% endif %}
 <div id="ticket_content">
-  {{g.markdown.convert(ticket.description)|safe}}
+  {{g.markdown.cached_convert(ticket, 'description')|safe}}
   {% if ticket.attachments %}
     <strong class="grid-18">{{ticket.attachments|length}} Attachments</strong>
     <div class="clear">

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/56db185f/ForgeWiki/forgewiki/model/wiki.py
----------------------------------------------------------------------
diff --git a/ForgeWiki/forgewiki/model/wiki.py b/ForgeWiki/forgewiki/model/wiki.py
index 7bb78f7..a6565d6 100644
--- a/ForgeWiki/forgewiki/model/wiki.py
+++ b/ForgeWiki/forgewiki/model/wiki.py
@@ -37,6 +37,8 @@ from allura.model import (
         Shortlink,
 )
 from allura.model.timeline import ActivityObject
+from allura.model.types import MarkdownCache
+
 from allura.lib import helpers as h
 from allura.lib import utils
 
@@ -96,8 +98,10 @@ class Page(VersionedArtifact, ActivityObject):
         history_class = PageHistory
         unique_indexes = [('app_config_id', 'title')]
 
+
     title=FieldProperty(str)
     text=FieldProperty(schema.String, if_missing='')
+    text_cache = FieldProperty(MarkdownCache)
     viewable_by=FieldProperty([str])
     type_s = 'Wiki'
 
@@ -206,7 +210,7 @@ class Page(VersionedArtifact, ActivityObject):
     @property
     def html_text(self):
         """A markdown processed version of the page text"""
-        return g.markdown_wiki.convert(self.text)
+        return g.markdown_wiki.cached_convert(self, 'text')
 
     def authors(self):
         """All the users that have edited this page"""


Mime
View raw message