Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
insights
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
insights
Commits
76ab893e
Commit
76ab893e
authored
Jul 21, 2013
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
name can be a list
parent
f3c5a8b3
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
5 deletions
+36
-5
src/edinsights/core/decorators.py
+4
-0
src/edinsights/core/registry.py
+15
-5
src/edinsights/modules/testmodule/__init__.py
+12
-0
src/edinsights/modules/tests.py
+5
-0
No files found.
src/edinsights/core/decorators.py
View file @
76ab893e
...
...
@@ -67,6 +67,10 @@ def view(category = None, name = None, description = None, args = None):
args: Optional argspec for the function. This is generally better
omitted.
TODO: human_name: Name without Python name restrictions -- e.g.
"Daily uploads" instead of "daily_uploads" -- for use in
human-usable dashboards.
'''
def
view_factory
(
f
):
registry
.
register_handler
(
'view'
,
category
,
name
,
description
,
f
,
args
)
...
...
src/edinsights/core/registry.py
View file @
76ab893e
...
...
@@ -33,11 +33,21 @@ def register_handler(cls, category, name, description, f, args):
category
+=
"+"
if
cls
not
in
request_handlers
:
request_handlers
[
cls
]
=
{}
if
name
in
request_handlers
[
cls
]:
# We used to have this be an error.
# We changed to a warning for the way we handle dummy values.
log
.
warn
(
"{0} already in {1}"
.
format
(
name
,
category
))
# raise KeyError(name+" already in "+category)
request_handlers
[
cls
][
name
]
=
{
'function'
:
f
,
'name'
:
name
,
'doc'
:
description
,
'category'
:
category
}
# We may want to register under multiple names. E.g.
# edx.get_grades and (once adopted globally) generic
# get_grades
if
isinstance
(
name
,
list
):
names
=
name
else
:
names
=
[
name
]
for
n
in
names
:
if
n
in
request_handlers
[
cls
]:
# We used to have this be an error.
# We changed to a warning for the way we handle dummy values.
log
.
warn
(
"{0} already in {1}"
.
format
(
n
,
category
))
# raise KeyError(name+" already in "+category)
request_handlers
[
cls
][
n
]
=
{
'function'
:
f
,
'name'
:
n
,
'doc'
:
description
,
'category'
:
category
}
class
StreamingEvent
:
''' Event object. Behaves like the normal JSON event dictionary,
...
...
src/edinsights/modules/testmodule/__init__.py
View file @
76ab893e
...
...
@@ -164,3 +164,15 @@ def djt_fake_user_count(query):
the network, as well as optional parameters like fs, db, etc.
'''
return
"<html>Users: {uc}</html>"
.
format
(
uc
=
query
.
djt_fake_user_count
())
@query
(
name
=
[
'djt_three_name'
,
'edx_djt_three_name'
,
'edx.djt_three_name'
])
def
djt_three_name
():
return
"I have three names"
@query
(
name
=
'djt_check_three_name'
)
def
check_three_name
(
query
):
if
query
.
djt_three_name
()
!=
"I have three names"
:
raise
Exception
(
"oops"
)
if
query
.
edx_djt_three_name
()
!=
"I have three names"
:
raise
Exception
(
"oops"
)
return
"Works"
src/edinsights/modules/tests.py
View file @
76ab893e
...
...
@@ -151,3 +151,8 @@ class SimpleTest(TestCase):
c
=
Client
()
response
=
c
.
get
(
'/view/djt_fake_user_count'
)
.
content
self
.
assertEqual
(
response
,
"<html>Users: 2</html>"
)
def
test_multiname
(
self
):
c
=
Client
()
response
=
c
.
get
(
'/query/djt_check_three_name'
)
.
content
self
.
assertEqual
(
response
,
"Works"
)
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