Skip to content

Commit 248e00f

Browse files
committed
Import settings correctly
- Add management command
1 parent 2abab42 commit 248e00f

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
from optparse import make_option
3+
from django.core.management.base import BaseCommand
4+
from django.contrib.auth.models import User
5+
from kpi.utils.permissions import grant_default_model_level_perms
6+
7+
8+
class Command(BaseCommand):
9+
def add_arguments(self, parser):
10+
parser.add_argument('--username',
11+
action='store',
12+
dest='username',
13+
default=False,
14+
help="Add username i.e --username <username>")
15+
16+
def handle(self, *args, **options):
17+
username = options.get('username')
18+
if username:
19+
users = User.objects.filter(username=username)
20+
if users:
21+
grant_default_model_level_perms(users[0])
22+
sys.stdout.write("done")
23+
else:
24+
sys.stdout.write("user does not exist")
25+
else:
26+
sys.stdout.write("please provide a username")

kpi/utils/ona_authentication.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ def get_api_token(json_web_token):
2323
try:
2424
jwt_payload = jwt.decode(
2525
json_web_token,
26-
settings.get("JWT_SECRET_KEY", ""),
27-
algorithms=[settings.get("JWT_ALGORITHM", "HS256")]
26+
getattr(settings, "JWT_SECRET_KEY", ""),
27+
algorithms=[getattr(settings, "JWT_ALGORITHM", "HS256")]
2828
)
2929

3030
api_token = Token.objects.using("kobocat").select_related('user').get(

kpi/views/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
def home(request):
26-
return HttpResponseRedirect(settings.get("ONADATA_HOME"))
26+
return HttpResponseRedirect(getattr(settings, "ONADATA_HOME", "https://onadata.com"))
2727

2828

2929
def browser_tests(request):

0 commit comments

Comments
 (0)