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
142c9fdb
Commit
142c9fdb
authored
Apr 20, 2013
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved handle_request out of views
parent
6e1b08e4
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
19 deletions
+21
-19
src/djanalytics/core/djobject.py
+2
-2
src/djanalytics/core/registry.py
+17
-0
src/djanalytics/core/views.py
+2
-17
No files found.
src/djanalytics/core/djobject.py
View file @
142c9fdb
...
@@ -50,9 +50,9 @@ def http_rpc_helper(baseurl, view_or_query, function, headers = {}):
...
@@ -50,9 +50,9 @@ def http_rpc_helper(baseurl, view_or_query, function, headers = {}):
def
local_call_helper
(
view_or_query
,
function
):
def
local_call_helper
(
view_or_query
,
function
):
''' Make a call (functionally identical to RPC) to the local djanalytics instance
''' Make a call (functionally identical to RPC) to the local djanalytics instance
'''
'''
import
djanalytics.core.
views
import
djanalytics.core.
registry
def
rpc_call
(
**
kwargs
):
def
rpc_call
(
**
kwargs
):
return
djanalytics
.
core
.
views
.
handle_request
(
view_or_query
,
function
,
**
kwargs
)
return
djanalytics
.
core
.
registry
.
handle_request
(
view_or_query
,
function
,
**
kwargs
)
return
rpc_call
return
rpc_call
class
embed
():
class
embed
():
...
...
src/djanalytics/core/registry.py
View file @
142c9fdb
...
@@ -98,3 +98,20 @@ def schema_helper():
...
@@ -98,3 +98,20 @@ def schema_helper():
endpoints
.
append
({
'category'
:
rh
[
'category'
],
'class'
:
cls
,
'name'
:
name
,
'doc'
:
rh
[
'doc'
]})
endpoints
.
append
({
'category'
:
rh
[
'category'
],
'class'
:
cls
,
'name'
:
name
,
'doc'
:
rh
[
'doc'
]})
return
endpoints
return
endpoints
def
handle_request
(
cls
,
name
,
**
kwargs
):
''' Generic code to handle views and requests '''
args
=
dict
()
categories
=
request_handlers
[
cls
]
if
name
in
categories
:
handler_dict
=
categories
[
name
]
else
:
raise
Http404
(
name
+
" is not a valid function"
)
handler
=
handler_dict
[
'function'
]
if
'args'
in
handler_dict
:
arglist
=
handler_dict
[
'arglist'
]
else
:
arglist
=
inspect
.
getargspec
(
handler
)
.
args
from
util
import
optional_parameter_call
,
default_optional_kwargs
return
optional_parameter_call
(
handler
,
default_optional_kwargs
,
kwargs
,
arglist
)
src/djanalytics/core/views.py
View file @
142c9fdb
...
@@ -47,23 +47,6 @@ def schema(request):
...
@@ -47,23 +47,6 @@ def schema(request):
return
HttpResponse
(
"
\n
"
.
join
(
sorted
([
"<dt><p><b>{class}/{name}</b> <i>{category}</i></dt><dd>{doc}</dd>"
.
format
(
**
rh
)
for
rh
in
endpoints
])))
return
HttpResponse
(
"
\n
"
.
join
(
sorted
([
"<dt><p><b>{class}/{name}</b> <i>{category}</i></dt><dd>{doc}</dd>"
.
format
(
**
rh
)
for
rh
in
endpoints
])))
return
HttpResponse
(
json
.
dumps
(
endpoints
))
return
HttpResponse
(
json
.
dumps
(
endpoints
))
def
handle_request
(
cls
,
name
,
**
kwargs
):
''' Generic code from handle_view and handle_query '''
args
=
dict
()
categories
=
request_handlers
[
cls
]
if
name
in
categories
:
handler_dict
=
categories
[
name
]
else
:
raise
Http404
(
name
+
" is not a valid function"
)
handler
=
handler_dict
[
'function'
]
if
'args'
in
handler_dict
:
arglist
=
handler_dict
[
'arglist'
]
else
:
arglist
=
inspect
.
getargspec
(
handler
)
.
args
return
optional_parameter_call
(
handler
,
default_optional_kwargs
,
kwargs
,
arglist
)
@auth.auth
@auth.auth
def
handle_view
(
request
,
name
,
**
kwargs
):
def
handle_view
(
request
,
name
,
**
kwargs
):
''' Handles generic view.
''' Handles generic view.
...
@@ -72,6 +55,7 @@ def handle_view(request, name, **kwargs):
...
@@ -72,6 +55,7 @@ def handle_view(request, name, **kwargs):
'''
'''
kwargs
.
update
(
request
.
POST
.
items
())
kwargs
.
update
(
request
.
POST
.
items
())
kwargs
.
update
(
request
.
GET
.
items
())
kwargs
.
update
(
request
.
GET
.
items
())
from
registry
import
handle_request
return
HttpResponse
(
handle_request
(
'view'
,
name
,
**
kwargs
))
return
HttpResponse
(
handle_request
(
'view'
,
name
,
**
kwargs
))
@auth.auth
@auth.auth
...
@@ -82,6 +66,7 @@ def handle_query(request, name, **kwargs):
...
@@ -82,6 +66,7 @@ def handle_query(request, name, **kwargs):
'''
'''
kwargs
.
update
(
request
.
POST
.
items
())
kwargs
.
update
(
request
.
POST
.
items
())
kwargs
.
update
(
request
.
GET
.
items
())
kwargs
.
update
(
request
.
GET
.
items
())
from
registry
import
handle_request
request_data
=
handle_request
(
'query'
,
name
,
**
kwargs
)
request_data
=
handle_request
(
'query'
,
name
,
**
kwargs
)
try
:
try
:
request_data
=
json
.
dumps
(
request_data
)
request_data
=
json
.
dumps
(
request_data
)
...
...
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