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
56448d82
Commit
56448d82
authored
Apr 18, 2013
by
Piotr Mitros
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up of djobject
parent
881f3413
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
16 deletions
+29
-16
src/djanalytics/core/djobject.py
+29
-16
No files found.
src/djanalytics/core/djobject.py
View file @
56448d82
...
@@ -10,6 +10,16 @@ import json
...
@@ -10,6 +10,16 @@ import json
schema
=
None
schema
=
None
def
find_in_schema
(
cls
=
None
,
name
=
None
):
items
=
[]
for
item
in
schema
:
if
cls
and
item
[
'class'
]
!=
cls
:
continue
if
name
and
item
[
'name'
]
!=
name
:
continue
items
.
append
(
item
)
return
items
def
http_rpc_helper
(
baseurl
,
view_or_query
,
function
,
headers
=
{}):
def
http_rpc_helper
(
baseurl
,
view_or_query
,
function
,
headers
=
{}):
if
baseurl
:
if
baseurl
:
baseembedurl
=
baseurl
+
view_or_query
+
"/"
baseembedurl
=
baseurl
+
view_or_query
+
"/"
...
@@ -26,7 +36,7 @@ def http_rpc_helper(baseurl, view_or_query, function, headers = {}):
...
@@ -26,7 +36,7 @@ def http_rpc_helper(baseurl, view_or_query, function, headers = {}):
raise
AttributeError
(
function
)
raise
AttributeError
(
function
)
error
=
"Error calling {func} {status}"
.
format
(
func
=
function
,
status
=
response
.
status_code
)
error
=
"Error calling {func} {status}"
.
format
(
func
=
function
,
status
=
response
.
status_code
)
raise
Exception
(
error
)
raise
Exception
(
error
)
rpc_call
.
__doc__
=
"rpc call"
rpc_call
.
__doc__
=
find_in_schema
(
cls
=
view_or_query
,
name
=
function
)[
0
][
'doc'
]
return
rpc_call
return
rpc_call
def
local_call_helper
(
view_or_query
,
function
):
def
local_call_helper
(
view_or_query
,
function
):
...
@@ -37,17 +47,20 @@ def local_call_helper(view_or_query, function):
...
@@ -37,17 +47,20 @@ def local_call_helper(view_or_query, function):
class
embed
():
class
embed
():
def
__init__
(
self
,
view_or_query
,
baseurl
=
None
,
headers
=
{}):
def
__init__
(
self
,
view_or_query
,
baseurl
=
None
,
headers
=
{}):
global
schema
self
.
_baseurl
=
baseurl
self
.
_baseurl
=
baseurl
self
.
_view_or_query
=
view_or_query
self
.
_headers
=
headers
self
.
_refresh_schema
()
def
_refresh_schema
(
self
):
global
schema
if
not
schema
:
if
not
schema
:
if
baseurl
:
if
self
.
_
baseurl
:
url
=
baseurl
+
"schema"
url
=
self
.
_
baseurl
+
"schema"
schema
=
json
.
loads
(
requests
.
get
(
url
)
.
content
)
schema
=
json
.
loads
(
requests
.
get
(
url
)
.
content
)
else
:
else
:
import
djobject.views
import
djobject.views
schema
=
djobject
.
views
.
schema_helper
()
schema
=
djobject
.
views
.
schema_helper
()
self
.
_view_or_query
=
view_or_query
self
.
_headers
=
headers
def
__getattr__
(
self
,
attr
):
def
__getattr__
(
self
,
attr
):
## Disallow internal. This is necessary both for analytics,
## Disallow internal. This is necessary both for analytics,
...
@@ -56,19 +69,19 @@ class embed():
...
@@ -56,19 +69,19 @@ class embed():
if
attr
[
0
]
==
'_'
:
if
attr
[
0
]
==
'_'
:
return
return
if
self
.
_baseurl
:
if
self
.
_baseurl
:
return
http_rpc_helper
(
self
.
_baseurl
,
self
.
_view_or_query
,
attr
)
helper
=
http_rpc_helper
(
self
.
_baseurl
,
self
.
_view_or_query
,
attr
)
else
:
else
:
return
local_call_helper
(
self
.
_view_or_query
,
attr
)
helper
=
local_call_helper
(
self
.
_view_or_query
,
attr
)
# Set the docstring
helper
.
__doc__
=
find_in_schema
(
cls
=
self
.
_view_or_query
,
name
=
attr
)[
0
][
'doc'
]
helper
.
__name__
=
"remote_"
+
attr
return
helper
## TODO: Use probe/schema to populate this
## TODO: Use probe/schema to populate this
def
__dir__
(
self
):
def
__dir__
(
self
):
results
=
[]
self
.
_refresh_schema
()
probeurl
=
self
.
_baseurl
+
"probe/"
+
self
.
_view_or_query
return
[
i
[
"name"
]
for
i
in
find_in_schema
(
cls
=
self
.
_view_or_query
)]
classes
=
requests
.
get
(
probeurl
,
headers
=
self
.
_headers
)
.
content
.
split
(
'
\n
'
)
for
param_set
in
classes
:
items
=
requests
.
get
(
probeurl
+
"/"
+
param_set
,
headers
=
self
.
_headers
)
.
content
.
split
(
'
\n
'
)
results
=
results
+
items
return
results
def
__repr__
(
self
):
def
__repr__
(
self
):
return
self
.
_view_or_query
+
" object host: ["
+
self
.
_baseurl
+
"]"
return
self
.
_view_or_query
+
" object host: ["
+
self
.
_baseurl
+
"]"
...
@@ -82,4 +95,4 @@ if __name__ == "__main__":
...
@@ -82,4 +95,4 @@ if __name__ == "__main__":
djo
=
djobject
(
baseurl
=
"http://127.0.0.1:8000/"
)
djo
=
djobject
(
baseurl
=
"http://127.0.0.1:8000/"
)
print
djo
.
query
.
djt_event_count
()
print
djo
.
query
.
djt_event_count
()
print
djo
.
query
.
djt_user_event_count
(
user
=
"bob"
)
print
djo
.
query
.
djt_user_event_count
(
user
=
"bob"
)
#
print djo.query.__dir__()
print
djo
.
query
.
__dir__
()
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