Skip to content

Commit

Permalink
Merge pull request #387 from kgrandis/feature/pep8
Browse files Browse the repository at this point in the history
First pass at making codebase PEP8 compliant. Mostly non-aggressive a…
  • Loading branch information
ljwolford committed Apr 27, 2016
2 parents 1670667 + e85d9ca commit cb7326b
Show file tree
Hide file tree
Showing 90 changed files with 6,628 additions and 6,406 deletions.
24 changes: 14 additions & 10 deletions adl_lrs/forms.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import json
from django import forms


class ValidatorForm(forms.Form):
jsondata = forms.CharField(label='Data', required=True,
widget=forms.Textarea(attrs={'cols':100, 'rows':20}))

jsondata = forms.CharField(label='Data', required=True,
widget=forms.Textarea(attrs={'cols': 100, 'rows': 20}))


class RegisterForm(forms.Form):
username = forms.CharField(max_length=200, label='Name')
email = forms.EmailField(max_length=200, label='Email')
password = forms.CharField(label='Password',
widget=forms.PasswordInput(render_value=False))
password2 = forms.CharField(label='Password Again',
password = forms.CharField(label='Password',
widget=forms.PasswordInput(render_value=False))
password2 = forms.CharField(label='Password Again',
widget=forms.PasswordInput(render_value=False))

def clean(self):
Expand All @@ -22,13 +24,15 @@ def clean(self):
return cleaned
raise forms.ValidationError("Passwords did not match")


class RegClientForm(forms.Form):
name = forms.CharField(max_length=200, label='Name')
description = forms.CharField(label='Description', required=False,
widget=forms.Textarea(attrs={'cols':50, 'rows':10}))
description = forms.CharField(label='Description', required=False,
widget=forms.Textarea(attrs={'cols': 50, 'rows': 10}))
rsa = forms.BooleanField(label='RSA Signature Method', required=False)
secret = forms.CharField(max_length=1024, label='Public RSA Key', required=False,
widget=forms.Textarea(attrs={'cols':50, 'rows':10}))
widget=forms.Textarea(attrs={'cols': 50, 'rows': 10}))


class HookRegistrationForm(forms.Form):
name = forms.CharField(max_length=50, label='Name', required=True)
Expand All @@ -44,4 +48,4 @@ def clean(self):
json.loads(json_filters)
except Exception:
raise forms.ValidationError("filters are not valid JSON")
return cleaned
return cleaned
89 changes: 45 additions & 44 deletions adl_lrs/management/commands/clear_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,49 @@
from django.db.models import get_app, get_models
from django.contrib.auth.models import User


class Command(BaseCommand):
help = 'Clears all data in the apps (does not clear users), clears cache and deletes any media files'
option_list = BaseCommand.option_list + (
make_option(
'--sa',
dest = 'saveagents',
default = False,
help = 'Save the agents associated with the users\' emails',
metavar = 'SA'
),
)
def handle(self, *args, **options):
# To preserve users' agents add -sa True when running command
sa = False
if options['saveagents']:
sa = True

apps = []
apps.append(get_app('lrs'))
apps.append(get_app('oauth_provider'))
apps.append(get_app('oauth2'))

# Clear app(db) data
for app in apps:
for model in get_models(app):
if app.__name__.split('.')[0] == 'lrs' and model.__name__ == "Agent" and sa:
user_emails = ["mailto:" + s for s in User.objects.all().values_list('email', flat=True)]
model.objects.exclude(mbox__in=user_emails).delete()
self.stdout.write("Deleted all %s objects from - %s except for the Agents associated with LRS users\n" % (model.__name__, app.__name__.split('.')[0]))
else:
model.objects.all().delete()
self.stdout.write("Deleted all %s objects from - %s\n" % (model.__name__, app.__name__.split('.')[0]))

# Clear cache data
cache.clear()

# Clear media folders
for subdir, dirs, files in os.walk(settings.MEDIA_ROOT):
for dr in dirs:
for sd, ds, fs in os.walk(os.path.join(settings.MEDIA_ROOT, dr)):
for f in fs:
os.remove(os.path.join(sd, f))

self.stdout.write("Successfully cleared all data from the apps\n")
help = 'Clears all data in the apps (does not clear users), clears cache and deletes any media files'
option_list = BaseCommand.option_list + (
make_option(
'--sa',
dest='saveagents',
default=False,
help='Save the agents associated with the users\' emails',
metavar='SA'
),
)

def handle(self, *args, **options):
# To preserve users' agents add -sa True when running command
sa = False
if options['saveagents']:
sa = True

apps = []
apps.append(get_app('lrs'))
apps.append(get_app('oauth_provider'))
apps.append(get_app('oauth2'))

# Clear app(db) data
for app in apps:
for model in get_models(app):
if app.__name__.split('.')[0] == 'lrs' and model.__name__ == "Agent" and sa:
user_emails = ["mailto:" + s for s in User.objects.all().values_list('email', flat=True)]
model.objects.exclude(mbox__in=user_emails).delete()
self.stdout.write("Deleted all %s objects from - %s except for the Agents associated with LRS users\n" % (model.__name__, app.__name__.split('.')[0]))
else:
model.objects.all().delete()
self.stdout.write("Deleted all %s objects from - %s\n" % (model.__name__, app.__name__.split('.')[0]))

# Clear cache data
cache.clear()

# Clear media folders
for subdir, dirs, files in os.walk(settings.MEDIA_ROOT):
for dr in dirs:
for sd, ds, fs in os.walk(os.path.join(settings.MEDIA_ROOT, dr)):
for f in fs:
os.remove(os.path.join(sd, f))

self.stdout.write("Successfully cleared all data from the apps\n")
66 changes: 33 additions & 33 deletions adl_lrs/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
'PASSWORD': 'password',
'HOST': 'localhost',
'PORT': '',
}
}
}

# Local time zone for this installation. Choices can be found here:
Expand Down Expand Up @@ -105,7 +105,7 @@
# OAuth1 callback views
OAUTH_AUTHORIZE_VIEW = 'oauth_provider.views.authorize_client'
OAUTH_CALLBACK_VIEW = 'oauth_provider.views.callback_view'
OAUTH_SIGNATURE_METHODS = ['plaintext','hmac-sha1','rsa-sha1']
OAUTH_SIGNATURE_METHODS = ['plaintext', 'hmac-sha1', 'rsa-sha1']
OAUTH_REALM_KEY_NAME = '%s://%s/xAPI' % (SITE_SCHEME, SITE_DOMAIN)

# THIS IS OAUTH2 STUFF
Expand All @@ -120,15 +120,15 @@

# List STATEMENTS_WRITE and STATEMENTS_READ_MINE first so they get defaulted in oauth2/forms.py
OAUTH_SCOPES = (
(STATEMENTS_WRITE,'statements/write'),
(STATEMENTS_READ_MINE,'statements/read/mine'),
(STATEMENTS_READ,'statements/read'),
(STATE,'state'),
(DEFINE,'define'),
(PROFILE,'profile'),
(ALL_READ,'all/read'),
(ALL,'all')
)
(STATEMENTS_WRITE, 'statements/write'),
(STATEMENTS_READ_MINE, 'statements/read/mine'),
(STATEMENTS_READ, 'statements/read'),
(STATE, 'state'),
(DEFINE, 'define'),
(PROFILE, 'profile'),
(ALL_READ, 'all/read'),
(ALL, 'all')
)

SESSION_KEY = 'oauth2'

Expand All @@ -149,10 +149,10 @@
'LOCATION': 'cache_statement_list',
'TIMEOUT': 86400,
},
'attachment_cache':{
'BACKEND':'django.core.cache.backends.db.DatabaseCache',
'LOCATION':'attachment_cache',
'TIMEOUT': 86400,
'attachment_cache': {
'BACKEND': 'django.core.cache.backends.db.DatabaseCache',
'LOCATION': 'attachment_cache',
'TIMEOUT': 86400,
},
}

Expand Down Expand Up @@ -256,7 +256,7 @@

REQUEST_HANDLER_LOG_DIR = path.join(PROJECT_ROOT, 'logs/django_request.log')
DEFAULT_LOG_DIR = path.join(PROJECT_ROOT, 'logs/lrs.log')
CELERY_TASKS_LOG_DIR = path.join(PROJECT_ROOT, 'logs/celery_tasks.log')
CELERY_TASKS_LOG_DIR = path.join(PROJECT_ROOT, 'logs/celery_tasks.log')

CELERYD_HIJACK_ROOT_LOGGER = False

Expand All @@ -280,29 +280,29 @@
},
'handlers': {
'default': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': DEFAULT_LOG_DIR,
'maxBytes': 1024*1024*5, # 5 MB
'maxBytes': 1024 * 1024 * 5, # 5 MB
'backupCount': 5,
'formatter':'standard',
},
'formatter': 'standard',
},
'request_handler': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'filename': REQUEST_HANDLER_LOG_DIR,
'maxBytes': 1024*1024*5, # 5 MB
'backupCount': 5,
'formatter':'standard',
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': REQUEST_HANDLER_LOG_DIR,
'maxBytes': 1024 * 1024 * 5, # 5 MB
'backupCount': 5,
'formatter': 'standard',
},
'celery_handler': {
'level':'DEBUG',
'class':'logging.handlers.RotatingFileHandler',
'level': 'DEBUG',
'class': 'logging.handlers.RotatingFileHandler',
'filename': CELERY_TASKS_LOG_DIR,
'maxBytes': 1024*1024*5, # 5 MB
'maxBytes': 1024 * 1024 * 5, # 5 MB
'backupCount': 5,
'formatter':'standard',
},
'formatter': 'standard',
},
},
'loggers': {
'lrs': {
Expand All @@ -319,6 +319,6 @@
'handlers': ['celery_handler'],
'level': 'DEBUG',
'propagate': True
},
},
}
}
62 changes: 31 additions & 31 deletions adl_lrs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,41 @@
admin.autodiscover()

urlpatterns = patterns('adl_lrs.views',
# for anyone trying to hit the xapi endpoints
url(r'^XAPI/', include('lrs.urls')),
url(r'^xapi/', include('lrs.urls')),
url(r'^xAPI/', include('lrs.urls')),
# for anyone trying to hit the xapi endpoints
url(r'^XAPI/', include('lrs.urls')),
url(r'^xapi/', include('lrs.urls')),
url(r'^xAPI/', include('lrs.urls')),

# start of non xapi endpoints
# comment the next line to disable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^actexample1/$', 'actexample1'),
url(r'^actexample2/$', 'actexample2'),
url(r'^oauth2/', include('oauth2_provider.provider.oauth2.urls', namespace='oauth2')),
url(r'^$', 'home'),
url(r'^register', 'register'),
url(r'^regclient2', 'reg_client2'),
url(r'^regclient', 'reg_client'),
url(r'^me/statements', 'my_statements'),
url(r'^me/download/statements', 'my_download_statements'),
url(r'^me/activities/states', 'my_activity_states'),
url(r'^me/activities/state', 'my_activity_state'),
url(r'^me/apps', 'my_app_status'),
url(r'^me/tokens2', 'delete_token2'),
url(r'^me/tokens', 'delete_token'),
url(r'^me/clients', 'delete_client'),
url(r'^me', 'me'),
url(r'^statementvalidator', 'stmt_validator'),
)
# start of non xapi endpoints
# comment the next line to disable the admin:
url(r'^admin/', include(admin.site.urls)),
url(r'^actexample1/$', 'actexample1'),
url(r'^actexample2/$', 'actexample2'),
url(r'^oauth2/', include('oauth2_provider.provider.oauth2.urls', namespace='oauth2')),
url(r'^$', 'home'),
url(r'^register', 'register'),
url(r'^regclient2', 'reg_client2'),
url(r'^regclient', 'reg_client'),
url(r'^me/statements', 'my_statements'),
url(r'^me/download/statements', 'my_download_statements'),
url(r'^me/activities/states', 'my_activity_states'),
url(r'^me/activities/state', 'my_activity_state'),
url(r'^me/apps', 'my_app_status'),
url(r'^me/tokens2', 'delete_token2'),
url(r'^me/tokens', 'delete_token'),
url(r'^me/clients', 'delete_client'),
url(r'^me', 'me'),
url(r'^statementvalidator', 'stmt_validator'),
)

# Login and logout patterns
urlpatterns += patterns('',
url(r'^accounts/login/$', 'django.contrib.auth.views.login', name="login"),
url(r'^accounts/logout/$', 'adl_lrs.views.logout_view', name="logout"),
)
url(r'^accounts/login/$', 'django.contrib.auth.views.login', name="login"),
url(r'^accounts/logout/$', 'adl_lrs.views.logout_view', name="logout"),
)

# Allows admins to view attachments in admin console
if settings.DEBUG:
urlpatterns += patterns('adl_lrs.views',
url(r'^media/attachment_payloads/(?P<path>.*)$', 'admin_attachments'),
)
urlpatterns += patterns('adl_lrs.views',
url(r'^media/attachment_payloads/(?P<path>.*)$', 'admin_attachments'),
)
Loading

0 comments on commit cb7326b

Please sign in to comment.