Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
comment
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cubicweb
cubes
comment
Commits
68cdbd97a6d3
Commit
68cdbd97a6d3
authored
14 years ago
by
Sylvain Thénault
Browse files
Options
Downloads
Patches
Plain Diff
update to 3.9 api by using an ITree adapter
parent
c6e6d5adc287
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
entities.py
+10
-13
10 additions, 13 deletions
entities.py
hooks.py
+2
-2
2 additions, 2 deletions
hooks.py
test/unittest_comment.py
+7
-5
7 additions, 5 deletions
test/unittest_comment.py
uiprops.py
+1
-1
1 addition, 1 deletion
uiprops.py
views.py
+33
-17
33 additions, 17 deletions
views.py
with
53 additions
and
38 deletions
entities.py
+
10
−
13
View file @
68cdbd97
...
...
@@ -9,7 +9,5 @@
from
logilab.common.textutils
import
normalize_text
from
cubicweb.view
import
EntityView
from
cubicweb.interfaces
import
ITree
from
cubicweb.mixins
import
TreeMixIn
from
cubicweb.selectors
import
implements
from
cubicweb.entities
import
AnyEntity
,
fetch_config
...
...
@@ -14,8 +12,9 @@
from
cubicweb.selectors
import
implements
from
cubicweb.entities
import
AnyEntity
,
fetch_config
from
cubicweb.entities.adapters
import
ITreeAdapter
def
subcomments_count
(
commentable
):
return
sum
([
len
(
commentable
.
reverse_comments
)]
+
[
subcomments_count
(
c
)
for
c
in
commentable
.
reverse_comments
])
...
...
@@ -16,9 +15,9 @@
def
subcomments_count
(
commentable
):
return
sum
([
len
(
commentable
.
reverse_comments
)]
+
[
subcomments_count
(
c
)
for
c
in
commentable
.
reverse_comments
])
class
Comment
(
TreeMixIn
,
AnyEntity
):
class
Comment
(
AnyEntity
):
"""
customized class for Comment entities
"""
__regid__
=
'
Comment
'
...
...
@@ -23,7 +22,5 @@
"""
customized class for Comment entities
"""
__regid__
=
'
Comment
'
tree_attribute
=
'
comments
'
__implements__
=
AnyEntity
.
__implements__
+
(
ITree
,)
fetch_attrs
,
fetch_order
=
fetch_config
((
'
creation_date
'
,),
'
creation_date
'
,
order
=
'
ASC
'
)
...
...
@@ -33,9 +30,6 @@
def
dc_description
(
self
,
format
=
'
text/plain
'
):
return
self
.
printable_value
(
'
content
'
,
format
=
format
)
def
after_deletion_path
(
self
):
"""
return (path, parameters) which should be used as redirect
information when this entity is being deleted
"""
return
self
.
root
().
rest_path
(),
{}
subcomments_count
=
subcomments_count
...
...
@@ -41,5 +35,7 @@
subcomments_count
=
subcomments_count
class
CommentITreeAdapter
(
ITreeAdapter
):
__select__
=
implements
(
'
Comment
'
)
tree_relation
=
'
comments
'
# some views potentially needed on web *and* server side (for notification)
...
...
@@ -78,7 +74,8 @@
def
cell_call
(
self
,
row
,
col
):
e
=
self
.
cw_rset
.
get_entity
(
row
,
col
)
strings
=
[]
cpath
=
e
.
path
()[
1
:]
itree
=
e
.
cw_adapt_to
(
'
ITree
'
)
cpath
=
itree
.
path
()[
1
:]
indentlevel
=
len
(
cpath
)
-
1
for
i
,
ceid
in
enumerate
(
cpath
):
comment
=
self
.
_cw
.
execute
(
'
Any C,T,D WHERE C creation_date D, C content T, C eid %(x)s
'
,
...
...
@@ -87,7 +84,7 @@
withauthor
=
i
!=
indentlevel
).
strip
()
+
'
\n
'
)
strings
.
append
(
u
'
\n
%s: %s
'
%
(
self
.
_cw
.
_
(
'
i18n_by_author_field
'
),
e
.
dc_creator
()
or
_
(
'
unknown author
'
)))
strings
.
append
(
u
'
url: %s
'
%
e
.
root
().
absolute_url
())
strings
.
append
(
u
'
url: %s
'
%
itre
e
.
root
().
absolute_url
())
self
.
w
(
u
'
\n
'
.
join
(
strings
))
...
...
This diff is collapsed.
Click to expand it.
hooks.py
+
2
−
2
View file @
68cdbd97
"""
Comment notification hooks
:organization: Logilab
:copyright: 2003-200
9
LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:copyright: 2003-20
1
0 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
__docformat__
=
"
restructuredtext en
"
...
...
@@ -18,7 +18,7 @@
msgid_timestamp
=
False
def
subject
(
self
):
root
=
self
.
cw_rset
.
get_entity
(
self
.
cw_row
,
self
.
cw_col
).
root
()
root
=
self
.
cw_rset
.
get_entity
(
self
.
cw_row
,
self
.
cw_col
).
cw_adapt_to
(
'
ITree
'
).
root
()
return
'
%s %s %s
'
%
(
self
.
_cw
.
_
(
'
new comment for
'
),
root
.
dc_type
(),
root
.
dc_title
())
...
...
This diff is collapsed.
Click to expand it.
test/unittest_comment.py
+
7
−
5
View file @
68cdbd97
...
...
@@ -83,4 +83,5 @@
def
test_path
(
self
):
req
=
self
.
request
()
c1
=
req
.
create_entity
(
'
Comment
'
,
content
=
u
"
oijzr
"
,
comments
=
self
.
b
)
itreec1
=
c1
.
cw_adapt_to
(
'
ITree
'
)
c11
=
req
.
create_entity
(
'
Comment
'
,
content
=
u
"
duh?
"
,
comments
=
c1
)
...
...
@@ -86,8 +87,9 @@
c11
=
req
.
create_entity
(
'
Comment
'
,
content
=
u
"
duh?
"
,
comments
=
c1
)
self
.
assertEquals
(
c1
.
path
(),
[
self
.
b
.
eid
,
c1
.
eid
])
self
.
assertEquals
(
c1
.
root
().
eid
,
self
.
b
.
eid
)
self
.
assertEquals
(
c11
.
path
(),
[
self
.
b
.
eid
,
c1
.
eid
,
c11
.
eid
])
self
.
assertEquals
(
c11
.
root
().
eid
,
self
.
b
.
eid
)
itreec11
=
c11
.
cw_adapt_to
(
'
ITree
'
)
self
.
assertEquals
(
itreec1
.
path
(),
[
self
.
b
.
eid
,
c1
.
eid
])
self
.
assertEquals
(
itreec1
.
root
().
eid
,
self
.
b
.
eid
)
self
.
assertEquals
(
itreec11
.
path
(),
[
self
.
b
.
eid
,
c1
.
eid
,
c11
.
eid
])
self
.
assertEquals
(
itreec11
.
root
().
eid
,
self
.
b
.
eid
)
def
test_comments_ascending_order
(
self
):
req
=
self
.
request
()
...
...
@@ -97,7 +99,7 @@
c2
=
req
.
create_entity
(
'
Comment
'
,
content
=
u
"
two
"
,
comments
=
self
.
b
)
self
.
assertEquals
([
c
.
eid
for
c
in
self
.
b
.
reverse_comments
],
[
c1
.
eid
,
c2
.
eid
])
self
.
assertEquals
([
c
.
eid
for
c
in
c1
.
children
()],
self
.
assertEquals
([
c
.
eid
for
c
in
c1
.
cw_adapt_to
(
'
ITree
'
).
children
()],
[
c11
.
eid
,
c12
.
eid
])
def
test_subcomments_count
(
self
):
...
...
This diff is collapsed.
Click to expand it.
data/external_resources
→
uiprops.py
+
1
−
1
View file @
68cdbd97
COMMENT_ICON =
DATADIR/
icon_comment.gif
COMMENT_ICON
=
data
(
'
icon_comment.gif
'
)
This diff is collapsed.
Click to expand it.
views.py
+
33
−
17
View file @
68cdbd97
...
...
@@ -4,6 +4,8 @@
:copyright: 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
"""
from
__future__
import
with_statement
__docformat__
=
"
restructuredtext en
"
_
=
unicode
...
...
@@ -23,7 +25,7 @@
from
cubicweb.mixins
import
TreeViewMixIn
from
cubicweb.web
import
stdmsgs
,
uicfg
,
component
,
form
,
formwidgets
as
fw
from
cubicweb.web.action
import
LinkToEntityAction
,
Action
from
cubicweb.web.views
import
primary
,
baseviews
,
xmlrss
,
basecontrollers
from
cubicweb.web.views
import
primary
,
baseviews
,
xmlrss
,
basecontrollers
,
treeview
_afs
=
uicfg
.
autoform_section
_afs
.
tag_subject_of
((
'
*
'
,
'
comments
'
,
'
*
'
),
formtype
=
'
main
'
,
section
=
'
hidden
'
)
...
...
@@ -80,7 +82,7 @@
def
cell_call
(
self
,
row
,
col
,
**
kwargs
):
entity
=
self
.
cw_rset
.
get_entity
(
row
,
col
)
root
=
entity
.
root
()
root
=
entity
.
cw_adapt_to
(
'
ITree
'
).
root
()
self
.
w
(
u
'
<a href=
"
%s
"
>%s %s</a>
'
%
(
xml_escape
(
root
.
absolute_url
()),
xml_escape
(
root
.
dc_type
()),
...
...
@@ -131,12 +133,11 @@
replyaction
=
actions
.
select_or_none
(
'
reply_comment
'
,
self
.
_cw
,
rset
=
self
.
cw_rset
,
row
=
row
)
if
replyaction
is
not
None
:
url
=
self
.
_cw
.
build_ajax_replace_url
(
'
comment%sHolder
'
%
entity
.
eid
,
rql_for_eid
(
entity
.
eid
),
'
addcommentform
'
)
url
=
self
.
_cw
.
ajax_replace_url
(
'
comment%sHolder
'
%
entity
.
eid
,
eid
=
entity
.
eid
,
vid
=
'
addcommentform
'
)
self
.
w
(
u
'
| <span class=
"
replyto
"
><a href=
"
%s
"
>%s</a></span>
'
%
(
xml_escape
(
url
),
self
.
_cw
.
_
(
replyaction
.
title
)))
editaction
=
actions
.
select_or_none
(
'
edit_comment
'
,
self
.
_cw
,
rset
=
self
.
cw_rset
,
row
=
row
)
if
editaction
is
not
None
:
# split(':', 1)[1] to remove javascript:
...
...
@@ -137,12 +138,12 @@
self
.
w
(
u
'
| <span class=
"
replyto
"
><a href=
"
%s
"
>%s</a></span>
'
%
(
xml_escape
(
url
),
self
.
_cw
.
_
(
replyaction
.
title
)))
editaction
=
actions
.
select_or_none
(
'
edit_comment
'
,
self
.
_cw
,
rset
=
self
.
cw_rset
,
row
=
row
)
if
editaction
is
not
None
:
# split(':', 1)[1] to remove javascript:
formjs
=
self
.
_cw
.
build_
ajax_replace_url
(
cdivid
,
rql_for_
eid
(
entity
.
eid
)
,
'
editcommentform
'
,
'
append
'
).
split
(
'
:
'
,
1
)[
1
]
formjs
=
self
.
_cw
.
ajax_replace_url
(
cdivid
,
'
append
'
,
eid
=
entity
.
eid
,
vid
=
'
editcommentform
'
).
split
(
'
:
'
,
1
)[
1
]
url
=
"
javascript: jQuery(
'
#%s div
'
).hide(); %s
"
%
(
cdivid
,
formjs
)
self
.
w
(
u
'
| <span class=
"
replyto
"
><a href=
"
%s
"
>%s</a></span>
'
%
(
xml_escape
(
url
),
self
.
_cw
.
_
(
editaction
.
title
)))
...
...
@@ -150,9 +151,10 @@
deleteaction
=
actions
.
select_or_none
(
'
delete_comment
'
,
self
.
_cw
,
rset
=
self
.
cw_rset
,
row
=
row
)
if
deleteaction
is
not
None
:
url
=
self
.
_cw
.
build_ajax_replace_url
(
'
comment%s
'
%
entity
.
eid
,
rql_for_eid
(
entity
.
eid
),
'
deleteconf
'
,
__redirectpath
=
entity
.
root
().
rest_path
())
root
=
entity
.
cw_adapt_to
(
'
ITree
'
).
root
()
url
=
self
.
_cw
.
ajax_replace_url
(
'
comment%s
'
%
entity
.
eid
,
eid
=
entity
.
eid
,
vid
=
'
deleteconf
'
,
__redirectpath
=
root
.
rest_path
())
self
.
w
(
u
'
| <span class=
"
replyto
"
><a href=
"
%s
"
>%s</a></span>
'
%
(
xml_escape
(
url
),
self
.
_cw
.
_
(
deleteaction
.
title
)))
...
...
@@ -164,7 +166,7 @@
self
.
w
(
u
'
</div>
\n
'
)
# close comment's content div
class
CommentThreadView
(
T
ree
V
iew
MixIn
,
baseviews
.
List
View
):
class
CommentThreadView
(
t
ree
v
iew
.
BaseTree
View
):
"""
a recursive tree view
"""
__select__
=
implements
(
'
Comment
'
)
title
=
_
(
'
thread view
'
)
...
...
@@ -182,5 +184,6 @@
self
.
w
(
u
'
<guid isPermaLink=
"
true
"
>%s</guid>
\n
'
%
xml_escape
(
entity
.
absolute_url
()))
self
.
render_title_link
(
entity
)
root
=
entity
.
cw_adapt_to
(
'
ITree
'
).
root
()
description
=
entity
.
dc_description
(
format
=
'
text/html
'
)
+
\
self
.
_cw
.
_
(
u
'
about
'
)
+
\
...
...
@@ -185,7 +188,7 @@
description
=
entity
.
dc_description
(
format
=
'
text/html
'
)
+
\
self
.
_cw
.
_
(
u
'
about
'
)
+
\
u
'
<a href=%s>%s</a>
'
%
(
entity
.
root
()
.
absolute_url
(),
entity
.
root
()
.
dc_title
())
u
'
<a href=%s>%s</a>
'
%
(
root
.
absolute_url
(),
root
.
dc_title
())
self
.
_marker
(
'
description
'
,
description
)
self
.
_marker
(
'
dc:date
'
,
entity
.
dc_date
(
self
.
date_format
))
self
.
render_entity_creator
(
entity
)
...
...
@@ -315,7 +318,7 @@
params
[
'
etype
'
]
=
entity
.
__regid__
url
=
req
.
ajax_replace_url
(
'
comment%sHolder
'
%
eid
,
vid
=
'
addcommentform
'
,
**
params
)
self
.
w
(
u
'
(<a href=
"
%s
"
>%s</a>)
'
%
(
url
,
req
.
_
(
addcomment
.
title
)))
self
.
w
(
u
'
(<a href=
"
%s
"
>%s</a>)
'
%
(
xml_escape
(
url
)
,
req
.
_
(
addcomment
.
title
)))
class
UserLatestCommentsSection
(
component
.
EntityVComponent
):
...
...
@@ -342,6 +345,18 @@
})
self
.
w
(
u
'
</div>
'
)
# adapters #####################################################################
from
cubicweb.web.views.editcontroller
import
IEditControlAdapter
class
CommentIEditControlAdapter
(
IEditControlAdapter
):
__select__
=
implements
(
'
Comment
'
)
def
after_deletion_path
(
self
):
"""
return (path, parameters) which should be used as redirect
information when this entity is being deleted
"""
return
self
.
entity
.
cw_adapt_to
(
'
ITree
'
).
root
().
rest_path
(),
{}
# actions ######################################################################
...
...
@@ -360,5 +375,6 @@
def
url
(
self
):
comment
=
self
.
cw_rset
.
get_entity
(
self
.
cw_row
or
0
,
self
.
cw_col
or
0
)
linkto
=
'
%s:%s:subject
'
%
(
self
.
rtype
,
comment
.
eid
)
root
=
comment
.
cw_adapt_to
(
'
ITree
'
).
root
()
return
self
.
_cw
.
build_url
(
vid
=
'
creation
'
,
etype
=
self
.
target_etype
,
__linkto
=
linkto
,
...
...
@@ -363,6 +379,6 @@
return
self
.
_cw
.
build_url
(
vid
=
'
creation
'
,
etype
=
self
.
target_etype
,
__linkto
=
linkto
,
__redirectpath
=
comment
.
root
()
.
rest_path
(),
__redirectpath
=
root
.
rest_path
(),
__redirectvid
=
self
.
_cw
.
form
.
get
(
'
vid
'
,
''
))
...
...
@@ -396,7 +412,7 @@
class
DeleteCommentAction
(
Action
):
__regid__
=
'
delete_comment
'
__select__
=
implements
(
'
Comment
'
)
&
authenticated_user
()
&
\
score_entity
(
lambda
x
:
not
x
.
reverse_comments
and
x
.
has_perm
(
'
delete
'
))
score_entity
(
lambda
x
:
not
x
.
reverse_comments
and
x
.
cw_
has_perm
(
'
delete
'
))
title
=
_
(
'
delete comment
'
)
category
=
'
hidden
'
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment