Merge branch 'master' into dillo
This commit is contained in:
@@ -79,7 +79,9 @@ class CommentTreeBuilder:
|
|||||||
self.nbr_of_Comments: int = 0
|
self.nbr_of_Comments: int = 0
|
||||||
|
|
||||||
def build(self) -> CommentTreeDO:
|
def build(self) -> CommentTreeDO:
|
||||||
enriched_comments = self.child_comments(self.node_id)
|
enriched_comments = self.child_comments(self.node_id,
|
||||||
|
sort={'properties.rating_positive': pymongo.DESCENDING,
|
||||||
|
'_created': pymongo.DESCENDING})
|
||||||
project_id = self.get_project_id()
|
project_id = self.get_project_id()
|
||||||
return CommentTreeDO(
|
return CommentTreeDO(
|
||||||
node_id=self.node_id,
|
node_id=self.node_id,
|
||||||
@@ -88,14 +90,15 @@ class CommentTreeBuilder:
|
|||||||
comments=enriched_comments
|
comments=enriched_comments
|
||||||
)
|
)
|
||||||
|
|
||||||
def child_comments(self, node_id: bson.ObjectId) -> typing.List[CommentDO]:
|
def child_comments(self, node_id: bson.ObjectId, sort: dict) -> typing.List[CommentDO]:
|
||||||
raw_comments = self.mongodb_comments(node_id)
|
raw_comments = self.mongodb_comments(node_id, sort)
|
||||||
return [self.enrich(comment) for comment in raw_comments]
|
return [self.enrich(comment) for comment in raw_comments]
|
||||||
|
|
||||||
def enrich(self, mongo_comment: dict) -> CommentDO:
|
def enrich(self, mongo_comment: dict) -> CommentDO:
|
||||||
self.nbr_of_Comments += 1
|
self.nbr_of_Comments += 1
|
||||||
comment = to_comment_data_object(mongo_comment)
|
comment = to_comment_data_object(mongo_comment)
|
||||||
comment.replies = self.child_comments(mongo_comment['_id'])
|
comment.replies = self.child_comments(mongo_comment['_id'],
|
||||||
|
sort={'_created': pymongo.ASCENDING})
|
||||||
return comment
|
return comment
|
||||||
|
|
||||||
def get_project_id(self):
|
def get_project_id(self):
|
||||||
@@ -104,7 +107,7 @@ class CommentTreeBuilder:
|
|||||||
return result['project']
|
return result['project']
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def mongodb_comments(cls, node_id: bson.ObjectId) -> typing.Iterator:
|
def mongodb_comments(cls, node_id: bson.ObjectId, sort: dict) -> typing.Iterator:
|
||||||
nodes_coll = current_app.db('nodes')
|
nodes_coll = current_app.db('nodes')
|
||||||
return nodes_coll.aggregate([
|
return nodes_coll.aggregate([
|
||||||
{'$match': {'node_type': 'comment',
|
{'$match': {'node_type': 'comment',
|
||||||
@@ -116,8 +119,7 @@ class CommentTreeBuilder:
|
|||||||
"foreignField": "_id",
|
"foreignField": "_id",
|
||||||
"as": "user"}},
|
"as": "user"}},
|
||||||
{'$unwind': {'path': "$user"}},
|
{'$unwind': {'path': "$user"}},
|
||||||
{'$sort': {'properties.rating_positive': pymongo.DESCENDING,
|
{'$sort': sort},
|
||||||
'_created': pymongo.DESCENDING}},
|
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
@@ -63,7 +63,7 @@ def remove_private_keys(document):
|
|||||||
return doc_copy
|
return doc_copy
|
||||||
|
|
||||||
|
|
||||||
def pretty_duration(seconds):
|
def pretty_duration(seconds: typing.Union[None, int, float]):
|
||||||
if seconds is None:
|
if seconds is None:
|
||||||
return ''
|
return ''
|
||||||
seconds = round(seconds)
|
seconds = round(seconds)
|
||||||
@@ -75,6 +75,27 @@ def pretty_duration(seconds):
|
|||||||
return f'{minutes:02}:{seconds:02}'
|
return f'{minutes:02}:{seconds:02}'
|
||||||
|
|
||||||
|
|
||||||
|
def pretty_duration_fractional(seconds: typing.Union[None, int, float]):
|
||||||
|
if seconds is None:
|
||||||
|
return ''
|
||||||
|
|
||||||
|
# Remove fraction of seconds from the seconds so that the rest is done as integers.
|
||||||
|
seconds, fracs = divmod(seconds, 1)
|
||||||
|
hours, seconds = divmod(int(seconds), 3600)
|
||||||
|
minutes, seconds = divmod(seconds, 60)
|
||||||
|
msec = int(round(fracs * 1000))
|
||||||
|
|
||||||
|
if msec == 0:
|
||||||
|
msec_str = ''
|
||||||
|
else:
|
||||||
|
msec_str = f'.{msec:03}'
|
||||||
|
|
||||||
|
if hours > 0:
|
||||||
|
return f'{hours:02}:{minutes:02}:{seconds:02}{msec_str}'
|
||||||
|
else:
|
||||||
|
return f'{minutes:02}:{seconds:02}{msec_str}'
|
||||||
|
|
||||||
|
|
||||||
class PillarJSONEncoder(json.JSONEncoder):
|
class PillarJSONEncoder(json.JSONEncoder):
|
||||||
"""JSON encoder with support for Pillar resources."""
|
"""JSON encoder with support for Pillar resources."""
|
||||||
|
|
||||||
|
@@ -35,6 +35,10 @@ def format_pretty_duration(s):
|
|||||||
return pretty_duration(s)
|
return pretty_duration(s)
|
||||||
|
|
||||||
|
|
||||||
|
def format_pretty_duration_fractional(s):
|
||||||
|
return pillar.api.utils.pretty_duration_fractional(s)
|
||||||
|
|
||||||
|
|
||||||
def format_undertitle(s):
|
def format_undertitle(s):
|
||||||
"""Underscore-replacing title filter.
|
"""Underscore-replacing title filter.
|
||||||
|
|
||||||
@@ -232,6 +236,7 @@ def setup_jinja_env(jinja_env, app_config: dict):
|
|||||||
jinja_env.filters['pretty_date'] = format_pretty_date
|
jinja_env.filters['pretty_date'] = format_pretty_date
|
||||||
jinja_env.filters['pretty_date_time'] = format_pretty_date_time
|
jinja_env.filters['pretty_date_time'] = format_pretty_date_time
|
||||||
jinja_env.filters['pretty_duration'] = format_pretty_duration
|
jinja_env.filters['pretty_duration'] = format_pretty_duration
|
||||||
|
jinja_env.filters['pretty_duration_fractional'] = format_pretty_duration_fractional
|
||||||
jinja_env.filters['undertitle'] = format_undertitle
|
jinja_env.filters['undertitle'] = format_undertitle
|
||||||
jinja_env.filters['hide_none'] = do_hide_none
|
jinja_env.filters['hide_none'] = do_hide_none
|
||||||
jinja_env.filters['pluralize'] = do_pluralize
|
jinja_env.filters['pluralize'] = do_pluralize
|
||||||
|
@@ -42,9 +42,9 @@ asn1crypto==0.24.0
|
|||||||
Babel==2.6.0
|
Babel==2.6.0
|
||||||
billiard==3.5.0.4
|
billiard==3.5.0.4
|
||||||
Cerberus==1.2
|
Cerberus==1.2
|
||||||
cffi==1.10.0
|
cffi==1.12.2
|
||||||
click==6.7
|
click==6.7
|
||||||
cryptography==2.0.3
|
cryptography==2.6.1
|
||||||
Events==0.3
|
Events==0.3
|
||||||
future==0.16.0
|
future==0.16.0
|
||||||
googleapis-common-protos==1.5.3
|
googleapis-common-protos==1.5.3
|
||||||
@@ -61,14 +61,14 @@ protobuf==3.6.0
|
|||||||
protorpc==0.12.0
|
protorpc==0.12.0
|
||||||
pyasn1==0.4.4
|
pyasn1==0.4.4
|
||||||
pyasn1-modules==0.2.2
|
pyasn1-modules==0.2.2
|
||||||
pycparser==2.17
|
pycparser==2.19
|
||||||
pymongo==3.7.0
|
pymongo==3.7.0
|
||||||
pyOpenSSL==16.2.0
|
pyOpenSSL==16.2.0
|
||||||
pytz==2018.5
|
pytz==2018.5
|
||||||
requests-oauthlib==1.0.0
|
requests-oauthlib==1.0.0
|
||||||
rsa==3.4.2
|
rsa==3.4.2
|
||||||
simplejson==3.16.0
|
simplejson==3.16.0
|
||||||
six==1.10.0
|
six==1.12.0
|
||||||
urllib3==1.22
|
urllib3==1.22
|
||||||
vine==1.1.4
|
vine==1.1.4
|
||||||
webencodings==0.5.1
|
webencodings==0.5.1
|
||||||
|
@@ -38,7 +38,7 @@ $comments-width-max: 710px
|
|||||||
display: inline-block
|
display: inline-block
|
||||||
float: left
|
float: left
|
||||||
font-weight: bold
|
font-weight: bold
|
||||||
margin-right: 8px
|
margin-right: 10px
|
||||||
white-space: nowrap
|
white-space: nowrap
|
||||||
|
|
||||||
&.op
|
&.op
|
||||||
|
@@ -394,14 +394,17 @@
|
|||||||
word-wrap: break-word
|
word-wrap: break-word
|
||||||
|
|
||||||
blockquote
|
blockquote
|
||||||
|
+clearfix
|
||||||
background-color: lighten($color-background-light, 5%)
|
background-color: lighten($color-background-light, 5%)
|
||||||
box-shadow: inset 5px 0 0 $color-background
|
box-shadow: inset 5px 0 0 $color-background
|
||||||
display: block
|
display: inline-block
|
||||||
|
width: 100%
|
||||||
font-size: 1em
|
font-size: 1em
|
||||||
margin:
|
margin:
|
||||||
|
bottom: 10px
|
||||||
left: 0
|
left: 0
|
||||||
right: 20px
|
right: 20px
|
||||||
bottom: 30px
|
top: 10px
|
||||||
padding: 5px 5px 5px 20px
|
padding: 5px 5px 5px 20px
|
||||||
text-shadow: 1px 1px 0 rgba(white, .2)
|
text-shadow: 1px 1px 0 rgba(white, .2)
|
||||||
|
|
||||||
@@ -446,11 +449,10 @@
|
|||||||
+list-bullets
|
+list-bullets
|
||||||
|
|
||||||
ul
|
ul
|
||||||
margin-bottom: 25px
|
+clearfix
|
||||||
|
margin-bottom: 15px
|
||||||
|
|
||||||
li
|
li
|
||||||
margin-bottom: 7px
|
|
||||||
|
|
||||||
img
|
img
|
||||||
display: block
|
display: block
|
||||||
padding:
|
padding:
|
||||||
@@ -462,8 +464,8 @@
|
|||||||
padding-left: 20px
|
padding-left: 20px
|
||||||
|
|
||||||
code, kbd, pre, samp
|
code, kbd, pre, samp
|
||||||
background-color: rgba($color-primary, .05)
|
background-color: darken(rgba($color-primary, .1), 30%)
|
||||||
color: darken($color-primary, 15%)
|
color: $color-primary
|
||||||
font-size: inherit
|
font-size: inherit
|
||||||
white-space: pre-line
|
white-space: pre-line
|
||||||
|
|
||||||
@@ -472,7 +474,7 @@
|
|||||||
|
|
||||||
kbd
|
kbd
|
||||||
border:
|
border:
|
||||||
color: rgba($color-primary, .33)
|
color: darken(rgba($color-primary, .33), 50%)
|
||||||
radius: 3px
|
radius: 3px
|
||||||
style: solid
|
style: solid
|
||||||
width: 2px
|
width: 2px
|
||||||
@@ -481,9 +483,13 @@
|
|||||||
font:
|
font:
|
||||||
size: .9em
|
size: .9em
|
||||||
weight: bold
|
weight: bold
|
||||||
margin: 2px
|
margin:
|
||||||
|
bottom: initial
|
||||||
|
left: 3px
|
||||||
|
right: 3px
|
||||||
|
top: initial
|
||||||
min-width: 15px
|
min-width: 15px
|
||||||
padding: 0 3px
|
padding: 0 5px
|
||||||
text:
|
text:
|
||||||
align: center
|
align: center
|
||||||
transform: uppercase
|
transform: uppercase
|
||||||
|
@@ -41,3 +41,12 @@ class MarkdownTest(unittest.TestCase):
|
|||||||
'<h1>Title</h1>\n<p>Before</p>\n'
|
'<h1>Title</h1>\n<p>Before</p>\n'
|
||||||
'<dl><dt>test</dt><dt>a</dt><dd>b</dd><dt>c</dt><dd>d</dd></dl>\n',
|
'<dl><dt>test</dt><dt>a</dt><dd>b</dd><dt>c</dt><dd>d</dd></dl>\n',
|
||||||
jinja.do_markdowned({'eek': '# Title\n\nBefore\n{test a="b" c="d"}'}, 'eek'))
|
jinja.do_markdowned({'eek': '# Title\n\nBefore\n{test a="b" c="d"}'}, 'eek'))
|
||||||
|
|
||||||
|
def test_pretty_duration_fractional(self):
|
||||||
|
from pillar.web import jinja
|
||||||
|
|
||||||
|
self.assertEqual('03:04.568', jinja.format_pretty_duration_fractional(184.5678911111))
|
||||||
|
self.assertEqual('02:03:04.568', jinja.format_pretty_duration_fractional(7384.5678911111))
|
||||||
|
|
||||||
|
self.assertEqual('03:04', jinja.format_pretty_duration_fractional(184.00049))
|
||||||
|
self.assertEqual('02:03:04', jinja.format_pretty_duration_fractional(7384.00049))
|
||||||
|
Reference in New Issue
Block a user