Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tdt4242-base-APU
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tor Martin Frøberg Wang
tdt4242-base-APU
Commits
bc5b79fe
Commit
bc5b79fe
authored
4 years ago
by
Tobias Ørstad
Browse files
Options
Downloads
Patches
Plain Diff
Fix secfit code smells
parent
877d6e88
No related branches found
Branches containing commit
No related tags found
2 merge requests
!31
Complete exercise 3
,
!25
Backendsecfitsmells
Pipeline
#126981
passed
4 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
backend/secfit/secfit/djangoHeroku.py
+45
-94
45 additions, 94 deletions
backend/secfit/secfit/djangoHeroku.py
backend/secfit/secfit/settings.py
+0
-14
0 additions, 14 deletions
backend/secfit/secfit/settings.py
backend/secfit/secfit/views.py
+0
-0
0 additions, 0 deletions
backend/secfit/secfit/views.py
with
45 additions
and
108 deletions
backend/secfit/secfit/djangoHeroku.py
+
45
−
94
View file @
bc5b79fe
#import logging
import
os
import
dj_database_url
from
django.test.runner
import
DiscoverRunner
...
...
@@ -12,105 +10,58 @@ def settings(config, *, db_colors=False, databases=True, test_runner=True, stati
# Database configuration.
# TODO: support other database (e.g. TEAL, AMBER, etc, automatically.)
if
databases
:
# Integrity check.
if
'
DATABASES
'
not
in
config
:
config
[
'
DATABASES
'
]
=
{
'
default
'
:
None
}
conn_max_age
=
config
.
get
(
'
CONN_MAX_AGE
'
,
MAX_CONN_AGE
)
if
db_colors
:
# Support all Heroku databases.
# TODO: This appears to break TestRunner.
for
(
env
,
url
)
in
os
.
environ
.
items
():
if
env
.
startswith
(
'
HEROKU_POSTGRESQL
'
):
db_color
=
env
[
len
(
'
HEROKU_POSTGRESQL_
'
):].
split
(
'
_
'
)[
0
]
#logger.info('Adding ${} to DATABASES Django setting ({}).'.format(env, db_color))
config
[
'
DATABASES
'
][
db_color
]
=
dj_database_url
.
parse
(
url
,
conn_max_age
=
conn_max_age
,
ssl_require
=
True
)
if
'
DATABASE_URL
'
in
os
.
environ
:
#logger.info('Adding $DATABASE_URL to default DATABASE Django setting.')
# Configure Django for DATABASE_URL environment variable.
config
[
'
DATABASES
'
][
'
default
'
]
=
dj_database_url
.
config
(
conn_max_age
=
conn_max_age
,
ssl_require
=
True
)
#logger.info('Adding $DATABASE_URL to TEST default DATABASE Django setting.')
# Enable test database if found in CI environment.
if
'
CI
'
in
os
.
environ
:
config
[
'
DATABASES
'
][
'
default
'
][
'
TEST
'
]
=
config
[
'
DATABASES
'
][
'
default
'
]
#else:
#logger.info('$DATABASE_URL not found, falling back to previous settings!')
databasesettings
(
config
,
db_colors
)
if
test_runner
:
if
test_runner
and
'
CI
'
in
os
.
environ
:
# Enable test runner if found in CI environment.
if
'
CI
'
in
os
.
environ
:
config
[
'
TEST_RUNNER
'
]
=
'
django_heroku.HerokuDiscoverRunner
'
config
[
'
TEST_RUNNER
'
]
=
'
django_heroku.HerokuDiscoverRunner
'
# Staticfiles configuration.
if
staticfiles
:
#logger.info('Applying Heroku Staticfiles configuration to Django settings.')
config
[
'
STATIC_ROOT
'
]
=
os
.
path
.
join
(
config
[
'
BASE_DIR
'
],
'
staticfiles
'
)
config
[
'
STATIC_URL
'
]
=
'
/static/
'
configsettings
(
config
)
# Ensure STATIC_ROOT exists.
os
.
makedirs
(
config
[
'
STATIC_ROOT
'
],
exist_ok
=
True
)
if
allowed_hosts
:
config
[
'
ALLOWED_HOSTS
'
]
=
[
'
*
'
]
# SECRET_KEY configuration.
if
secret_key
and
'
SECRET_KEY
'
in
os
.
environ
:
# Set the Django setting from the environment variable.
config
[
'
SECRET_KEY
'
]
=
os
.
environ
[
'
SECRET_KEY
'
]
def
databasesettings
(
config
,
db_colors
):
# Integrity check.
if
'
DATABASES
'
not
in
config
:
config
[
'
DATABASES
'
]
=
{
'
default
'
:
None
}
conn_max_age
=
config
.
get
(
'
CONN_MAX_AGE
'
,
MAX_CONN_AGE
)
if
db_colors
:
# Support all Heroku databases.
# TODO: This appears to break TestRunner.
for
(
env
,
url
)
in
os
.
environ
.
items
():
if
env
.
startswith
(
'
HEROKU_POSTGRESQL
'
):
db_color
=
env
[
len
(
'
HEROKU_POSTGRESQL_
'
):].
split
(
'
_
'
)[
0
]
config
[
'
DATABASES
'
][
db_color
]
=
dj_database_url
.
parse
(
url
,
conn_max_age
=
conn_max_age
,
ssl_require
=
True
)
if
'
DATABASE_URL
'
in
os
.
environ
:
# Configure Django for DATABASE_URL environment variable.
config
[
'
DATABASES
'
][
'
default
'
]
=
dj_database_url
.
config
(
conn_max_age
=
conn_max_age
,
ssl_require
=
True
)
# Enable test database if found in CI environment.
if
'
CI
'
in
os
.
environ
:
config
[
'
DATABASES
'
][
'
default
'
][
'
TEST
'
]
=
config
[
'
DATABASES
'
][
'
default
'
]
# Insert Whitenoise Middleware.
try
:
config
[
'
MIDDLEWARE_CLASSES
'
]
=
tuple
([
'
whitenoise.middleware.WhiteNoiseMiddleware
'
]
+
list
(
config
[
'
MIDDLEWARE_CLASSES
'
]))
except
KeyError
:
config
[
'
MIDDLEWARE
'
]
=
tuple
([
'
whitenoise.middleware.WhiteNoiseMiddleware
'
]
+
list
(
config
[
'
MIDDLEWARE
'
]))
def
staticsettins
(
config
):
config
[
'
STATIC_ROOT
'
]
=
os
.
path
.
join
(
config
[
'
BASE_DIR
'
],
'
staticfiles
'
)
config
[
'
STATIC_URL
'
]
=
'
/static/
'
# En
able GZip
.
config
[
'
STATIC
FILES_STORAGE
'
]
=
'
whitenoise.storage.CompressedManifestStaticFilesStorage
'
# En
sure STATIC_ROOT exists
.
os
.
makedirs
(
config
[
'
STATIC
_ROOT
'
],
exist_ok
=
True
)
if
allowed_hosts
:
#logger.info('Applying Heroku ALLOWED_HOSTS configuration to Django settings.')
config
[
'
ALLOWED_HOSTS
'
]
=
[
'
*
'
]
"""
if logging:
logger.info(
'
Applying Heroku logging configuration to Django settings.
'
)
# Insert Whitenoise Middleware.
try
:
config
[
'
MIDDLEWARE_CLASSES
'
]
=
tuple
([
'
whitenoise.middleware.WhiteNoiseMiddleware
'
]
+
list
(
config
[
'
MIDDLEWARE_CLASSES
'
]))
except
KeyError
:
config
[
'
MIDDLEWARE
'
]
=
tuple
([
'
whitenoise.middleware.WhiteNoiseMiddleware
'
]
+
list
(
config
[
'
MIDDLEWARE
'
]))
config[
'
LOGGING
'
] = {
'
version
'
: 1,
'
disable_existing_loggers
'
: False,
'
formatters
'
: {
'
verbose
'
: {
'
format
'
: (
'
%(asctime)s [%(process)d] [%(levelname)s]
'
+
'
pathname=%(pathname)s lineno=%(lineno)s
'
+
'
funcname=%(funcName)s %(message)s
'
),
'
datefmt
'
:
'
%Y-%m-%d %H:%M:%S
'
},
'
simple
'
: {
'
format
'
:
'
%(levelname)s %(message)s
'
}
},
'
handlers
'
: {
'
null
'
: {
'
level
'
:
'
DEBUG
'
,
'
class
'
:
'
logging.NullHandler
'
,
},
'
console
'
: {
'
level
'
:
'
DEBUG
'
,
'
class
'
:
'
logging.StreamHandler
'
,
'
formatter
'
:
'
verbose
'
}
},
'
loggers
'
: {
'
testlogger
'
: {
'
handlers
'
: [
'
console
'
],
'
level
'
:
'
INFO
'
,
}
}
}
"""
# SECRET_KEY configuration.
if
secret_key
:
if
'
SECRET_KEY
'
in
os
.
environ
:
#logger.info('Adding $SECRET_KEY to SECRET_KEY Django setting.')
# Set the Django setting from the environment variable.
config
[
'
SECRET_KEY
'
]
=
os
.
environ
[
'
SECRET_KEY
'
]
# Enable GZip.
config
[
'
STATICFILES_STORAGE
'
]
=
'
whitenoise.storage.CompressedManifestStaticFilesStorage
'
\ No newline at end of file
This diff is collapsed.
Click to expand it.
backend/secfit/secfit/settings.py
+
0
−
14
View file @
bc5b79fe
...
...
@@ -140,20 +140,6 @@ STATIC_URL = "/static/"
MEDIA_ROOT
=
os
.
path
.
join
(
BASE_DIR
,
"
media
"
)
MEDIA_URL
=
"
/media/
"
# REST_FRAMEWORK = {
# "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
# "PAGE_SIZE": 10,
# #"DEFAULT_AUTHENTICATION_CLASSES": (
# # "rest_framework_simplejwt.authentication.JWTAuthentication",
# #),
# 'DEFAULT_AUTHENTICATION_CLASSES': (
# # 'rest_framework.authentication.SessionAuthentication',
# "rest_framework_simplejwt.authentication.JWTAuthentication"
# ),
# }
REST_FRAMEWORK
=
{
"
DEFAULT_PAGINATION_CLASS
"
:
"
rest_framework.pagination.PageNumberPagination
"
,
...
...
This diff is collapsed.
Click to expand it.
backend/secfit/secfit/views.py
deleted
100644 → 0
+
0
−
0
View file @
877d6e88
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment