Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
c2425200
Commit
c2425200
authored
May 21, 2014
by
lduarte1991
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Annotation Tools: Add helper functions and fixed pep8/pylint errors
Small plugin fixes
parent
ecb05e6b
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
148 additions
and
25 deletions
+148
-25
common/lib/xmodule/xmodule/annotator_mixin.py
+46
-0
common/lib/xmodule/xmodule/annotator_token.py
+2
-2
common/lib/xmodule/xmodule/tests/test_annotator_mixin.py
+53
-0
common/lib/xmodule/xmodule/tests/test_annotator_token.py
+0
-0
common/lib/xmodule/xmodule/tests/test_videoannotation.py
+0
-0
common/lib/xmodule/xmodule/textannotation_module.py
+2
-6
common/lib/xmodule/xmodule/videoannotation_module.py
+3
-15
common/static/css/vendor/ova/richText-annotator.css
+13
-1
common/static/js/vendor/ova/flagging-annotator.js
+0
-0
common/static/js/vendor/ova/reply-annotator.js
+1
-0
common/static/js/vendor/ova/tags-annotator.js
+28
-1
No files found.
common/lib/xmodule/xmodule/annotator_mixin.py
0 → 100644
View file @
c2425200
"""
Annotations Tool Mixin
This file contains global variables and functions used in the various Annotation Tools.
"""
from
pkg_resources
import
resource_string
from
lxml
import
etree
from
urlparse
import
urlparse
from
os.path
import
splitext
,
basename
from
HTMLParser
import
HTMLParser
def
get_instructions
(
xmltree
):
""" Removes <instructions> from the xmltree and returns them as a string, otherwise None. """
instructions
=
xmltree
.
find
(
'instructions'
)
if
instructions
is
not
None
:
instructions
.
tag
=
'div'
xmltree
.
remove
(
instructions
)
return
etree
.
tostring
(
instructions
,
encoding
=
'unicode'
)
return
None
def
get_extension
(
srcurl
):
''' get the extension of a given url '''
if
'youtu'
in
srcurl
:
return
'video/youtube'
else
:
disassembled
=
urlparse
(
srcurl
)
file_ext
=
splitext
(
basename
(
disassembled
.
path
))[
1
]
return
'video/'
+
file_ext
.
replace
(
'.'
,
''
)
class
MLStripper
(
HTMLParser
):
"helper function for html_to_text below"
def
__init__
(
self
):
self
.
reset
()
self
.
fed
=
[]
def
handle_data
(
self
,
d
):
self
.
fed
.
append
(
d
)
def
handle_entityref
(
self
,
name
):
self
.
fed
.
append
(
'&
%
s;'
%
name
)
def
get_data
(
self
):
return
''
.
join
(
self
.
fed
)
def
html_to_text
(
html
):
"strips the html tags off of the text to return plaintext"
s
=
MLStripper
()
s
.
feed
(
html
)
return
s
.
get_data
()
\ No newline at end of file
common/lib/xmodule/xmodule/annotator_token.py
View file @
c2425200
...
@@ -23,8 +23,8 @@ def retrieve_token(userid, secret):
...
@@ -23,8 +23,8 @@ def retrieve_token(userid, secret):
dtnow
=
datetime
.
datetime
.
now
()
dtnow
=
datetime
.
datetime
.
now
()
dtutcnow
=
datetime
.
datetime
.
utcnow
()
dtutcnow
=
datetime
.
datetime
.
utcnow
()
delta
=
dtnow
-
dtutcnow
delta
=
dtnow
-
dtutcnow
newhour
,
newmin
=
divmod
((
delta
.
days
*
24
*
60
*
60
+
delta
.
seconds
+
30
)
//
60
,
60
)
newhour
,
newmin
=
divmod
((
delta
.
days
*
24
*
60
*
60
+
delta
.
seconds
+
30
)
//
60
,
60
)
# pylint: disable=E1103
newtime
=
"
%
s
%+02
d:
%02
d"
%
(
dtnow
.
isoformat
(),
newhour
,
newmin
)
newtime
=
"
%
s
%+02
d:
%02
d"
%
(
dtnow
.
isoformat
(),
newhour
,
newmin
)
# pylint: disable=E1103
# uses the issued time (UTC plus timezone), the consumer key and the user's email to maintain a
# uses the issued time (UTC plus timezone), the consumer key and the user's email to maintain a
# federated system in the annotation backend server
# federated system in the annotation backend server
custom_data
=
{
"issuedAt"
:
newtime
,
"consumerKey"
:
secret
,
"userId"
:
userid
,
"ttl"
:
86400
}
custom_data
=
{
"issuedAt"
:
newtime
,
"consumerKey"
:
secret
,
"userId"
:
userid
,
"ttl"
:
86400
}
...
...
common/lib/xmodule/xmodule/tests/test_annotator_mixin.py
0 → 100644
View file @
c2425200
"""
This test will run for annotator_mixin.py
"""
import
unittest
from
lxml
import
etree
from
xmodule.annotator_mixin
import
get_instructions
,
get_extension
,
html_to_text
class
HelperFunctionTest
(
unittest
.
TestCase
):
"""
Tests to ensure that the following helper functions work for the annotation tool
"""
sample_xml
=
'''
<annotatable>
<instructions><p>Helper Test Instructions.</p></instructions>
</annotatable>
'''
sample_sourceurl
=
"http://video-js.zencoder.com/oceans-clip.mp4"
sample_youtubeurl
=
"http://www.youtube.com/watch?v=yxLIu-scR9Y"
sample_html
=
'<p><b>Testing here</b> and not bolded here</p>'
def
test_get_instructions
(
self
):
"""
Function takes in an input of a specific xml string with surrounding instructions tags and returns a valid html string.
"""
xmltree
=
etree
.
fromstring
(
self
.
sample_xml
)
expected_xml
=
u"<div><p>Helper Test Instructions.</p></div>"
actual_xml
=
get_instructions
(
xmltree
)
# pylint: disable=W0212
self
.
assertIsNotNone
(
actual_xml
)
self
.
assertEqual
(
expected_xml
.
strip
(),
actual_xml
.
strip
())
xmltree
=
etree
.
fromstring
(
'<annotatable>foo</annotatable>'
)
actual
=
get_instructions
(
xmltree
)
# pylint: disable=W0212
self
.
assertIsNone
(
actual
)
def
test_get_extension
(
self
):
"""
Tests whether given a url if the video will return a youtube source or extension
"""
expectedyoutube
=
'video/youtube'
expectednotyoutube
=
'video/mp4'
result1
=
get_extension
(
self
.
sample_sourceurl
)
# pylint: disable=W0212
result2
=
get_extension
(
self
.
sample_youtubeurl
)
# pylint: disable=W0212
self
.
assertEqual
(
expectedyoutube
,
result2
)
self
.
assertEqual
(
expectednotyoutube
,
result1
)
def
test_html_to_text
(
self
):
expectedText
=
"Testing here and not bolded here"
result
=
html_to_text
(
self
.
sample_html
)
self
.
assertEqual
(
expectedText
,
result
)
\ No newline at end of file
common/lib/xmodule/xmodule/tests/test_annotator_token.py
View file @
c2425200
common/lib/xmodule/xmodule/tests/test_videoannotation.py
View file @
c2425200
common/lib/xmodule/xmodule/textannotation_module.py
View file @
c2425200
...
@@ -6,6 +6,7 @@ from pkg_resources import resource_string
...
@@ -6,6 +6,7 @@ from pkg_resources import resource_string
from
xmodule.x_module
import
XModule
from
xmodule.x_module
import
XModule
from
xmodule.raw_module
import
RawDescriptor
from
xmodule.raw_module
import
RawDescriptor
from
xblock.core
import
Scope
,
String
from
xblock.core
import
Scope
,
String
from
xmodule.annotator_mixin
import
get_instructions
from
xmodule.annotator_token
import
retrieve_token
from
xmodule.annotator_token
import
retrieve_token
import
textwrap
import
textwrap
...
@@ -70,12 +71,7 @@ class TextAnnotationModule(AnnotatableFields, XModule):
...
@@ -70,12 +71,7 @@ class TextAnnotationModule(AnnotatableFields, XModule):
def
_extract_instructions
(
self
,
xmltree
):
def
_extract_instructions
(
self
,
xmltree
):
""" Removes <instructions> from the xmltree and returns them as a string, otherwise None. """
""" Removes <instructions> from the xmltree and returns them as a string, otherwise None. """
instructions
=
xmltree
.
find
(
'instructions'
)
return
get_instructions
(
xmltree
)
if
instructions
is
not
None
:
instructions
.
tag
=
'div'
xmltree
.
remove
(
instructions
)
return
etree
.
tostring
(
instructions
,
encoding
=
'unicode'
)
return
None
def
get_html
(
self
):
def
get_html
(
self
):
""" Renders parameters to template. """
""" Renders parameters to template. """
...
...
common/lib/xmodule/xmodule/videoannotation_module.py
View file @
c2425200
...
@@ -7,6 +7,7 @@ from pkg_resources import resource_string
...
@@ -7,6 +7,7 @@ from pkg_resources import resource_string
from
xmodule.x_module
import
XModule
from
xmodule.x_module
import
XModule
from
xmodule.raw_module
import
RawDescriptor
from
xmodule.raw_module
import
RawDescriptor
from
xblock.core
import
Scope
,
String
from
xblock.core
import
Scope
,
String
from
xmodule.annotator_mixin
import
get_instructions
,
get_extension
from
xmodule.annotator_token
import
retrieve_token
from
xmodule.annotator_token
import
retrieve_token
import
textwrap
import
textwrap
...
@@ -65,24 +66,11 @@ class VideoAnnotationModule(AnnotatableFields, XModule):
...
@@ -65,24 +66,11 @@ class VideoAnnotationModule(AnnotatableFields, XModule):
def
_extract_instructions
(
self
,
xmltree
):
def
_extract_instructions
(
self
,
xmltree
):
""" Removes <instructions> from the xmltree and returns them as a string, otherwise None. """
""" Removes <instructions> from the xmltree and returns them as a string, otherwise None. """
instructions
=
xmltree
.
find
(
'instructions'
)
return
get_instructions
(
xmltree
)
if
instructions
is
not
None
:
instructions
.
tag
=
'div'
xmltree
.
remove
(
instructions
)
return
etree
.
tostring
(
instructions
,
encoding
=
'unicode'
)
return
None
def
_get_extension
(
self
,
srcurl
):
def
_get_extension
(
self
,
srcurl
):
''' get the extension of a given url '''
''' get the extension of a given url '''
if
'youtu'
in
srcurl
:
return
get_extension
(
srcurl
)
return
'video/youtube'
else
:
spliturl
=
srcurl
.
split
(
"."
)
extensionplus1
=
spliturl
[
len
(
spliturl
)
-
1
]
spliturl
=
extensionplus1
.
split
(
"?"
)
extensionplus2
=
spliturl
[
0
]
spliturl
=
extensionplus2
.
split
(
"#"
)
return
'video/'
+
spliturl
[
0
]
def
get_html
(
self
):
def
get_html
(
self
):
""" Renders parameters to template. """
""" Renders parameters to template. """
...
...
common/static/css/vendor/ova/richText-annotator.css
View file @
c2425200
...
@@ -17,9 +17,21 @@
...
@@ -17,9 +17,21 @@
}
}
.annotator-wrapper
.mce-container
{
.annotator-wrapper
.mce-container
{
z-index
:
3000000000
!important
;
/*To fix full-screen problems*/
z-index
:
3000000000
!important
;
/*To fix full-screen problems*/
}
}
.mce-container-body
{
min-width
:
400px
;
}
.iframe
[
id
=
"annotator-field"
]
{
width
:
inherit
;
min-width
:
400px
;
}
div
.mce-tinymce.mce-container.mce-panel
{
min-width
:
400px
;
}
/* Some change in the design of Annotator */
/* Some change in the design of Annotator */
.annotator-editor
.annotator-widget
{
.annotator-editor
.annotator-widget
{
...
...
common/static/js/vendor/ova/flagging-annotator.js
View file @
c2425200
common/static/js/vendor/ova/reply-annotator.js
View file @
c2425200
...
@@ -82,6 +82,7 @@ Annotator.Plugin.Reply = (function(_super) {
...
@@ -82,6 +82,7 @@ Annotator.Plugin.Reply = (function(_super) {
var
string
;
var
string
;
return
self
;
return
self
;
});
});
field
.
remove
();
this
.
annotation
=
annotation
;
this
.
annotation
=
annotation
;
//Create the actions for the buttons
//Create the actions for the buttons
return
ret
;
return
ret
;
...
...
common/static/js/vendor/ova/tags-annotator.js
View file @
c2425200
/*
/*
HighlightTags Annotator Plugin v1.0 (https://github.com/lduarte1991/tags-annotator)
Copyright (C) 2014 Luis F Duarte
License: https://github.com/lduarte1991/tags-annotator/blob/master/LICENSE.rst
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*===============================================================================
===============================================================================
===============================================================================
===============================================================================
==============================================================================*/
/*
* jQuery Plugin: Tokenizing Autocomplete Text Entry
* jQuery Plugin: Tokenizing Autocomplete Text Entry
* Version 1.6.0
* Version 1.6.0
*
*
...
@@ -22,7 +46,7 @@ var DEFAULT_SETTINGS = {
...
@@ -22,7 +46,7 @@ var DEFAULT_SETTINGS = {
// Display settings
// Display settings
hintText
:
"Type in a search term"
,
hintText
:
"Type in a search term"
,
noResultsText
:
"No
results
"
,
noResultsText
:
"No
t Found. Hit ENTER to add a personal tag.
"
,
searchingText
:
"Searching..."
,
searchingText
:
"Searching..."
,
deleteText
:
"×"
,
deleteText
:
"×"
,
animateDropdown
:
true
,
animateDropdown
:
true
,
...
@@ -271,6 +295,9 @@ $.TokenList = function (input, url_or_data, settings) {
...
@@ -271,6 +295,9 @@ $.TokenList = function (input, url_or_data, settings) {
add_token
(
$
(
selected_dropdown_item
).
data
(
"tokeninput"
));
add_token
(
$
(
selected_dropdown_item
).
data
(
"tokeninput"
));
hidden_input
.
change
();
hidden_input
.
change
();
return
false
;
return
false
;
}
else
{
add_token
({
id
:
$
(
this
).
val
(),
name
:
$
(
this
).
val
()});
hidden_input
.
change
();
}
}
break
;
break
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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