Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Updated django3.2.9 #59

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions conduit/apps/articles/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from django.contrib import admin
from .models import *

class ArticleAdmin(admin.ModelAdmin):
list_display = ['slug', 'title', 'description']


admin.site.register(Article, ArticleAdmin)


class CommentAdmin(admin.ModelAdmin):
search_fields = ['author', 'body']
list_display = ['author', 'body']


admin.site.register(Comment, CommentAdmin)


class TagAdmin(admin.ModelAdmin):
list_display = ['tag', 'slug']


admin.site.register(Tag, TagAdmin)
3 changes: 2 additions & 1 deletion conduit/apps/authentication/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def authenticate(self, request):
# if we didn't decode these values.
prefix = auth_header[0].decode('utf-8')
token = auth_header[1].decode('utf-8')
# token = auth_header[1]

if prefix.lower() != auth_header_prefix:
# The auth header prefix is not what we expected. Do not attempt to
Expand All @@ -75,7 +76,7 @@ def _authenticate_credentials(self, request, token):
successful, return the user and token. If not, throw an error.
"""
try:
payload = jwt.decode(token, settings.SECRET_KEY)
payload = jwt.decode(token, settings.SECRET_KEY, algorithms=['HS256'])
except:
msg = 'Invalid authentication. Could not decode token.'
raise exceptions.AuthenticationFailed(msg)
Expand Down
7 changes: 5 additions & 2 deletions conduit/apps/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ def _generate_jwt_token(self):

token = jwt.encode({
'id': self.pk,
'exp': int(dt.strftime('%s'))
# 'exp': int(dt.strftime('%s'))
'exp': 1642356260
}, settings.SECRET_KEY, algorithm='HS256')

return token.decode('utf-8')
# return token.decode('utf-8')
return token
# return jwt.decode(token, settings.SECRET_KEY, algorithms=['HS256'])
7 changes: 7 additions & 0 deletions conduit/apps/profiles/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin
from .models import *

class ProfilesAdmin(admin.ModelAdmin):
list_display = ['user','bio']

admin.site.register(Profile, ProfilesAdmin)
4 changes: 2 additions & 2 deletions conduit/apps/profiles/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ def get_following(self, instance):
if request is None:
return False

if not request.user.is_authenticated():
if not request.user.is_authenticated:
return False

follower = request.user.profile
followee = instance

return follower.is_following(followee)
return follower.is_following(followee)
14 changes: 11 additions & 3 deletions conduit/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"""

import os

import django_heroku
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

Expand Down Expand Up @@ -57,6 +57,7 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
]

ROOT_URLCONF = 'conduit.urls'
Expand Down Expand Up @@ -127,11 +128,12 @@
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.10/howto/static-files/

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'

CORS_ORIGIN_WHITELIST = (
'0.0.0.0:4000',
'localhost:4000',
'http://0.0.0.0:3000',
'http://localhost:3000',
)

# Tell Django about the custom `User` model we created. The string
Expand All @@ -150,3 +152,9 @@
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
'PAGE_SIZE': 20,
}

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

# STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

django_heroku.settings(locals())
9 changes: 5 additions & 4 deletions conduit/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
"""
from django.conf.urls import include, url
from django.contrib import admin
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
url(r'^admin/', admin.site.urls),

url(r'^api/', include('conduit.apps.articles.urls', namespace='articles')),
url(r'^api/', include('conduit.apps.authentication.urls', namespace='authentication')),
url(r'^api/', include('conduit.apps.profiles.urls', namespace='profiles')),
url(r'^api/', include(('conduit.apps.articles.urls','conduit.apps.articles'), namespace='articles')),
url(r'^api/', include(('conduit.apps.authentication.urls','conduit.apps.authentication'), namespace='authentication')),
url(r'^api/', include(('conduit.apps.profiles.urls','conduit.apps.profiles'), namespace='profiles')),
]
22 changes: 16 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
Django==1.10.5
django-cors-middleware==1.3.1
django-extensions==1.7.1
djangorestframework==3.4.4
PyJWT==1.4.2
six==1.10.0
asgiref==3.4.1
dj-database-url==0.5.0
Django==3.2.9
django-cors-headers==3.10.0
django-cors-middleware==1.5.0
django-extensions==3.1.5
django-heroku==0.3.1
djangorestframework==3.12.4
gunicorn==20.1.0
psycopg2==2.9.2
PyJWT==2.3.0
python-decouple==3.5
pytz==2021.3
six==1.16.0
sqlparse==0.4.2
whitenoise==5.3.0
Empty file added static/.keep
Empty file.