Commit d9a771da by Dennis Jen Committed by GitHub

Upgraded django, drf, and removed django-model-utils. (#149)

parent d1bcc5be
"""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.core.management.base import BaseCommand, CommandError
......@@ -15,29 +13,35 @@ class Command(BaseCommand):
"""A command to set the API key for a user using when using TokenAuthentication."""
help = 'Set the API key for the specified user.'
args = '<username> <api_key>'
option_list = BaseCommand.option_list + (
make_option('--delete-key', action='store_true', default=False, help="Delete API key for user"),
def add_arguments(self, parser):
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):
if len(args) < 1:
if options['username'] is None:
raise CommandError("You must supply a username.")
username = args[0]
username = options['username']
if options['delete_key']:
delete_user_auth_token(username)
print 'Removed API key for user: <{0}>'.format(username)
else:
if len(args) < 2:
if options['api_key'] is None:
raise CommandError("You must supply both a username and key.")
# pylint: disable=no-member
user, _ = User.objects.get_or_create(username=username)
try:
key = args[1]
key = options['api_key']
set_user_auth_token(user, key)
except AttributeError:
print "The key %s is in use by another user. Please select another key." % key
......@@ -3,22 +3,25 @@ from django.conf import settings
class AnalyticsApiRouter(object):
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, model):
if model._meta.app_label == 'v0': # pylint: disable=protected-access
def _get_database(self, app_label):
if app_label == 'v0':
return getattr(settings, 'ANALYTICS_DATABASE', 'default')
return None
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
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):
dest_db = self._get_database(model)
def allow_migrate(self, database, app_label, model_name=None, **hints): # pylint: disable=unused-argument
dest_db = self._get_database(app_label)
if dest_db is not None:
return database == dest_db
else:
......
boto==2.42.0 # MIT
Django==1.9.9 # BSD License
Django==1.10.4 # BSD License
django-countries==4.0 # MIT
django-model-utils==2.5.2 # BSD
djangorestframework==3.4.6 # BSD
djangorestframework==3.5.3 # BSD
django-rest-swagger==0.3.8 # 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
ordered-set==2.0.1 # MIT
tqdm==4.10.0 # MIT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment