Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
mentors.debian.net
debexpo
Commits
1a65b526
Commit
1a65b526
authored
Aug 11, 2012
by
Baptiste Mouterde
Committed by
ikoalaz
Aug 11, 2012
Browse files
comment: add support of no js submission, add check for parent in the same page, fix redirect
parent
0447d984
Changes
1
Hide whitespace changes
Inline
Side-by-side
debexpo/controllers/comments.py
View file @
1a65b526
...
...
@@ -50,20 +50,42 @@ class CommentsController(BaseController):
setattr
(
comment
,
'vote'
,
True
)
return
comment
@
validate
(
schema
=
CommentForm
)
def
index
(
self
):
log
.
debug
(
'called by a standard query, creating comment'
)
# TODO : test this
"""
this wil handle the no-js comment posting, test on each var
"""
schema
=
CommentForm
()
msg
=
MsgServiceController
()
if
self
.
_create_comment
(
**
kwargs
):
msg
.
call_msg
(
'sucess'
,
'comment added'
,
kwars
[
'content'
])
redirect
(
origin
)
args
=
{
'type'
:
request
.
params
[
'type'
][
0
]}
if
request
.
params
[
'parent'
]
!=
""
:
args
[
'parent'
]
=
int
(
request
.
params
[
'parent'
])
else
:
args
[
'parent'
]
=
''
print
request
.
params
for
i
in
request
.
params
:
label
=
i
value
=
request
.
params
[
label
]
if
label
!=
'type'
or
label
!=
'parent'
:
args
[
label
]
=
value
try
:
self
.
form_result
=
schema
.
to_python
(
args
)
except
formencode
.
validators
.
Invalid
,
error
:
msg
=
MsgServiceController
()
return
msg
.
call_msg
(
'failure'
,
'Invalid: %s'
%
error
)
if
self
.
_create_comment
(
revision
=
self
.
form_result
[
'revision'
],
text
=
self
.
form_result
[
'content'
],
start
=
self
.
form_result
[
'start'
],
stop
=
self
.
form_result
[
'stop'
],
style
=
self
.
form_result
[
'type'
],
file
=
self
.
form_result
[
'file'
],
parent_id
=
self
.
form_result
[
'parent'
]):
return
msg
.
call_msg
(
'sucess'
,
'comment added'
,
self
.
form_result
[
'content'
])
else
:
msg
.
call_msg
(
'failure'
,
'you must be logged'
)
redirect
(
url
(
login
))
return
msg
.
call_msg
(
'failure'
,
'you must be logged'
)
redirect
(
url
(
'
login
'
))
@
jsonify
def
ajax_call
(
self
):
...
...
@@ -79,12 +101,12 @@ class CommentsController(BaseController):
return
'Invalid: %s'
%
error
if
self
.
_create_comment
(
revision
=
self
.
form_result
[
'revision'
],
text
=
request
.
params
[
'content'
],
start
=
request
.
params
[
'start'
],
stop
=
request
.
params
[
'stop'
],
style
=
request
.
params
[
'type'
],
file
=
request
.
params
[
'file'
],
parent_id
=
request
.
params
[
'parent'
]):
text
=
self
.
form_result
[
'content'
],
start
=
self
.
form_result
[
'start'
],
stop
=
self
.
form_result
[
'stop'
],
style
=
self
.
form_result
[
'type'
],
file
=
self
.
form_result
[
'file'
],
parent_id
=
self
.
form_result
[
'parent'
]):
return
msg
.
call_msg
(
'success'
,
'message added'
)
else
:
return
msg
.
call_msg
(
'failure'
,
'you must be logged'
)
...
...
@@ -112,11 +134,16 @@ class CommentsController(BaseController):
log
.
debug
(
'adding data to database'
)
dic
=
{}
for
id
,
value
in
kwargs
.
iteritems
():
if
value
!=
''
:
if
value
!=
''
and
value
!=
None
:
dic
[
id
]
=
value
dic
[
'user'
]
=
author
print
dic
if
'parent_id'
in
dic
:
parent
=
meta
.
session
.
query
(
PackageComment
).
get
(
dic
[
'parent_id'
])
if
(
'filename'
in
dic
and
'file'
in
parent
)
and
not
(
parent
.
file
==
dic
[
'filename'
]
and
parent
.
package_version_id
==
commit_id
):
#this mean that the parent isn't in the same page, it will screw up everything
return
False
dic
[
'index'
]
=
parent
.
index
+
1
else
:
dic
[
'index'
]
=
0
...
...
@@ -150,7 +177,8 @@ class CommentsController(BaseController):
dic
=
{
'package_version_id'
:
request
.
params
[
'package_version_id'
],
'file'
:
file_name
}
c
.
comments
=
self
.
get_comments
(
**
dic
)
return
str
(
render
(
'comments/comments.mako'
,
extra_vars
=
{
'id'
:
request
.
params
[
'id'
],
'package_version_id'
:
request
.
params
[
'package_version_id'
]}))
extra_vars
=
{
'id'
:
request
.
params
[
'id'
],
'package_version_id'
:
request
.
params
[
'package_version_id'
],
'filename'
:
file_name
}))
@
staticmethod
def
get_comments
(
**
kwargs
):
...
...
@@ -207,13 +235,13 @@ class CommentsController(BaseController):
#no session found
log
.
debug
(
"no session found, redirect to login"
)
msg
.
call_msg
(
'failure'
,
'you are not login'
)
redirect
(
url
(
login
))
redirect
(
url
(
'
login
'
))
user
=
meta
.
session
.
query
(
User
).
get
(
session
[
'user_id'
])
if
user
is
None
:
#no user found
log
.
debug
(
"no user found, redirect to login"
)
msg
.
call_msg
(
'failure'
,
'this user doesn
\'
t appear to exist'
)
redirect
(
url
(
login
))
redirect
(
url
(
'
login
'
))
else
:
comment
=
meta
.
session
.
query
(
PackageComment
).
get
(
comment_id
)
if
comment
is
None
:
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment