Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-analytics-data-api
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-analytics-data-api
Commits
d9a771da
Commit
d9a771da
authored
Jan 03, 2017
by
Dennis Jen
Committed by
GitHub
Jan 03, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upgraded django, drf, and removed django-model-utils. (#149)
parent
d1bcc5be
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
21 deletions
+27
-21
analytics_data_api/management/commands/set_api_key.py
+14
-10
analyticsdataserver/router.py
+10
-7
requirements/base.txt
+3
-4
No files found.
analytics_data_api/management/commands/set_api_key.py
View file @
d9a771da
"""A command to set the API key for a user using when using TokenAuthentication."""
"""A command to set the API key for a user using when using TokenAuthentication."""
from
optparse
import
make_option
from
django.contrib.auth
import
get_user_model
from
django.contrib.auth
import
get_user_model
from
django.core.management.base
import
BaseCommand
,
CommandError
from
django.core.management.base
import
BaseCommand
,
CommandError
...
@@ -15,29 +13,35 @@ class Command(BaseCommand):
...
@@ -15,29 +13,35 @@ class Command(BaseCommand):
"""A command to set the API key for a user using when using TokenAuthentication."""
"""A command to set the API key for a user using when using TokenAuthentication."""
help
=
'Set the API key for the specified user.'
help
=
'Set the API key for the specified user.'
args
=
'<username> <api_key>'
option_list
=
BaseCommand
.
option_list
+
(
def
add_arguments
(
self
,
parser
):
make_option
(
'--delete-key'
,
action
=
'store_true'
,
default
=
False
,
help
=
"Delete API key for user"
),
parser
.
add_argument
(
'username'
,
nargs
=
'?'
)
)
parser
.
add_argument
(
'api_key'
,
nargs
=
'?'
)
parser
.
add_argument
(
'--delete-key'
,
action
=
'store_true'
,
default
=
False
,
help
=
"Delete API key for user"
,
)
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
if
len
(
args
)
<
1
:
if
options
[
'username'
]
is
None
:
raise
CommandError
(
"You must supply a username."
)
raise
CommandError
(
"You must supply a username."
)
username
=
args
[
0
]
username
=
options
[
'username'
]
if
options
[
'delete_key'
]:
if
options
[
'delete_key'
]:
delete_user_auth_token
(
username
)
delete_user_auth_token
(
username
)
print
'Removed API key for user: <{0}>'
.
format
(
username
)
print
'Removed API key for user: <{0}>'
.
format
(
username
)
else
:
else
:
if
len
(
args
)
<
2
:
if
options
[
'api_key'
]
is
None
:
raise
CommandError
(
"You must supply both a username and key."
)
raise
CommandError
(
"You must supply both a username and key."
)
# pylint: disable=no-member
# pylint: disable=no-member
user
,
_
=
User
.
objects
.
get_or_create
(
username
=
username
)
user
,
_
=
User
.
objects
.
get_or_create
(
username
=
username
)
try
:
try
:
key
=
args
[
1
]
key
=
options
[
'api_key'
]
set_user_auth_token
(
user
,
key
)
set_user_auth_token
(
user
,
key
)
except
AttributeError
:
except
AttributeError
:
print
"The key
%
s is in use by another user. Please select another key."
%
key
print
"The key
%
s is in use by another user. Please select another key."
%
key
analyticsdataserver/router.py
View file @
d9a771da
...
@@ -3,22 +3,25 @@ from django.conf import settings
...
@@ -3,22 +3,25 @@ from django.conf import settings
class
AnalyticsApiRouter
(
object
):
class
AnalyticsApiRouter
(
object
):
def
db_for_read
(
self
,
model
,
**
hints
):
# pylint: disable=unused-argument
def
db_for_read
(
self
,
model
,
**
hints
):
# pylint: disable=unused-argument
return
self
.
_get_database
(
model
)
# pylint: disable=protected-access
return
self
.
_get_database
(
model
.
_meta
.
app_label
)
def
_get_database
(
self
,
mod
el
):
def
_get_database
(
self
,
app_lab
el
):
if
model
.
_meta
.
app_label
==
'v0'
:
# pylint: disable=protected-access
if
app_label
==
'v0'
:
return
getattr
(
settings
,
'ANALYTICS_DATABASE'
,
'default'
)
return
getattr
(
settings
,
'ANALYTICS_DATABASE'
,
'default'
)
return
None
return
None
def
db_for_write
(
self
,
model
,
**
hints
):
# pylint: disable=unused-argument
def
db_for_write
(
self
,
model
,
**
hints
):
# pylint: disable=unused-argument
return
self
.
_get_database
(
model
)
# pylint: disable=protected-access
return
self
.
_get_database
(
model
.
_meta
.
app_label
)
def
allow_relation
(
self
,
obj1
,
obj2
,
**
hints
):
# pylint: disable=unused-argument
def
allow_relation
(
self
,
obj1
,
obj2
,
**
hints
):
# pylint: disable=unused-argument
return
self
.
_get_database
(
obj1
)
==
self
.
_get_database
(
obj2
)
# pylint: disable=protected-access
return
self
.
_get_database
(
obj1
.
_meta
.
app_label
)
==
self
.
_get_database
(
obj2
.
_meta
.
app_label
)
def
allow_migrate
(
self
,
database
,
model
):
def
allow_migrate
(
self
,
database
,
app_label
,
model_name
=
None
,
**
hints
):
# pylint: disable=unused-argument
dest_db
=
self
.
_get_database
(
mod
el
)
dest_db
=
self
.
_get_database
(
app_lab
el
)
if
dest_db
is
not
None
:
if
dest_db
is
not
None
:
return
database
==
dest_db
return
database
==
dest_db
else
:
else
:
...
...
requirements/base.txt
View file @
d9a771da
boto==2.42.0 # MIT
boto==2.42.0 # MIT
Django==1.
9.9
# BSD License
Django==1.
10.4
# BSD License
django-countries==4.0 # MIT
django-countries==4.0 # MIT
django-model-utils==2.5.2 # BSD
djangorestframework==3.5.3 # BSD
djangorestframework==3.4.6 # BSD
django-rest-swagger==0.3.8 # BSD
django-rest-swagger==0.3.8 # BSD
djangorestframework-csv==1.4.1 # BSD
djangorestframework-csv==1.4.1 # BSD
django-storages==1.
4
.1 # BSD
django-storages==1.
5
.1 # BSD
elasticsearch-dsl==0.0.11 # Apache 2.0
elasticsearch-dsl==0.0.11 # Apache 2.0
ordered-set==2.0.1 # MIT
ordered-set==2.0.1 # MIT
tqdm==4.10.0 # MIT
tqdm==4.10.0 # MIT
...
...
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