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

Update django project to lastest version of requirements and compatibility with newer version #51

Open
wants to merge 4 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ celerybeat-schedule

# dotenv
.env
.venv

# virtualenv
venv/
Expand Down
24 changes: 24 additions & 0 deletions conduit/apps/articles/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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)
2 changes: 1 addition & 1 deletion conduit/apps/articles/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def get_favorited(self, instance):
if request is None:
return False

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

return request.user.profile.has_favorited(instance)
Expand Down
2 changes: 2 additions & 0 deletions conduit/apps/articles/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@
CommentsDestroyAPIView.as_view()),

url(r'^tags/?$', TagListAPIView.as_view()),


]
15 changes: 15 additions & 0 deletions conduit/apps/profiles/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.contrib import admin
from .models import *


class ProfileAdmin(admin.ModelAdmin):
list_display = ['user', 'team']


admin.site.register(Profile, ProfileAdmin)

class TeamAdmin(admin.ModelAdmin):
list_display = ['name']


admin.site.register(Team, TeamAdmin)
32 changes: 32 additions & 0 deletions conduit/apps/profiles/migrations/0004_auto_20210520_0732.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Generated by Django 3.2.3 on 2021-05-20 07:32

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('profiles', '0003_profile_favorites'),
]

operations = [
migrations.CreateModel(
name='Team',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('name', models.CharField(max_length=255)),
],
options={
'ordering': ['-created_at', '-updated_at'],
'abstract': False,
},
),
migrations.AddField(
model_name='profile',
name='team',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='articles', to='profiles.team'),
),
]
7 changes: 7 additions & 0 deletions conduit/apps/profiles/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.db import models
from django.db.models.fields.related import ForeignKey

from conduit.apps.core.models import TimestampedModel

Expand All @@ -12,6 +13,9 @@ class Profile(TimestampedModel):
'authentication.User', on_delete=models.CASCADE
)

team = models.ForeignKey(
'profiles.Team', on_delete=models.CASCADE, related_name='members', null=True,
)
# Each user profile will have a field where they can tell other users
# something about themselves. This field will be empty when the user
# creates their account, so we specify `blank=True`.
Expand Down Expand Up @@ -68,3 +72,6 @@ def unfavorite(self, article):
def has_favorited(self, article):
"""Returns True if we have favorited `article`; else False."""
return self.favorites.filter(pk=article.pk).exists()

class Team(TimestampedModel):
name = models.CharField(max_length=255)
2 changes: 1 addition & 1 deletion conduit/apps/profiles/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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
Expand Down
3 changes: 2 additions & 1 deletion conduit/apps/profiles/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.conf.urls import url

from .views import ProfileRetrieveAPIView, ProfileFollowAPIView
from .views import ProfileRetrieveAPIView, ProfileFollowAPIView,AllTeamAPIView

urlpatterns = [
url(r'^profiles/(?P<username>\w+)/?$', ProfileRetrieveAPIView.as_view()),
url(r'^profiles/(?P<username>\w+)/follow/?$',
ProfileFollowAPIView.as_view()),
url(r'^teams/$', AllTeamAPIView.as_view()),
]
34 changes: 33 additions & 1 deletion conduit/apps/profiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from rest_framework.response import Response
from rest_framework.views import APIView

from .models import Profile
from .models import *
from .renderers import ProfileJSONRenderer
from .serializers import ProfileSerializer

Expand Down Expand Up @@ -70,3 +70,35 @@ def post(self, request, username=None):
})

return Response(serializer.data, status=status.HTTP_201_CREATED)


class AllTeamAPIView(APIView):

def get(self, request, format=None):
try:
data = []

all_team = Team.objects.all()

for team in all_team:
myDict = {}
myDict['name'] = team.name

members = []

array_profile = team.members.all()
for profile in array_profile:
dict2 = {}
dict2['username'] = profile.user.username
members.append(dict2)

myDict['members'] = members

data.append(myDict)

return Response({'teams': data}, status=status.HTTP_200_OK)

except Exception as e:
print(e)
return Response({'status': "Internal Server Error, We'll Check It Later"},
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
2 changes: 1 addition & 1 deletion conduit/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']


# Application definition
Expand Down
6 changes: 3 additions & 3 deletions conduit/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
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')),
]
15 changes: 9 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
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.3.4
Django==3.2.3
django-cors-middleware==1.5.0
django-extensions==3.1.3
djangorestframework==3.12.4
PyJWT==2.1.0
pytz==2021.1
six==1.16.0
sqlparse==0.4.1