From aeb0d4d033d0c88137199808da8048fbe1185902 Mon Sep 17 00:00:00 2001 From: mojtabaakbari221b Date: Wed, 19 May 2021 12:47:13 +0430 Subject: [PATCH 1/4] add .venv in .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 2b00f1b..a4471ff 100644 --- a/.gitignore +++ b/.gitignore @@ -77,6 +77,7 @@ celerybeat-schedule # dotenv .env +.venv # virtualenv venv/ From 19bbfba6381098d474f61837d36051d9305338b0 Mon Sep 17 00:00:00 2001 From: mojtabaakbari221b Date: Wed, 19 May 2021 14:48:49 +0430 Subject: [PATCH 2/4] change 2 includation --- conduit/urls.py | 6 +++--- requirements.txt | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/conduit/urls.py b/conduit/urls.py index 54612f9..ed6f90f 100644 --- a/conduit/urls.py +++ b/conduit/urls.py @@ -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')), ] diff --git a/requirements.txt b/requirements.txt index 6eb9d54..8a75b85 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -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 +Django +django-cors-middleware +django-extensions +djangorestframework +PyJWT +six From a0117f079f8335351f2d788c86ab40f432cfed84 Mon Sep 17 00:00:00 2001 From: mojtabaakbari221b Date: Wed, 19 May 2021 15:50:10 +0430 Subject: [PATCH 3/4] git serializers --- conduit/apps/articles/admin.py | 24 ++++++++++++++++++++++++ conduit/apps/articles/serializers.py | 2 +- conduit/apps/profiles/serializers.py | 2 +- conduit/settings.py | 2 +- requirements.txt | 15 +++++++++------ 5 files changed, 36 insertions(+), 9 deletions(-) create mode 100644 conduit/apps/articles/admin.py diff --git a/conduit/apps/articles/admin.py b/conduit/apps/articles/admin.py new file mode 100644 index 0000000..ee99c74 --- /dev/null +++ b/conduit/apps/articles/admin.py @@ -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) \ No newline at end of file diff --git a/conduit/apps/articles/serializers.py b/conduit/apps/articles/serializers.py index 167909b..a61ed67 100644 --- a/conduit/apps/articles/serializers.py +++ b/conduit/apps/articles/serializers.py @@ -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) diff --git a/conduit/apps/profiles/serializers.py b/conduit/apps/profiles/serializers.py index b799082..4d2ee8c 100644 --- a/conduit/apps/profiles/serializers.py +++ b/conduit/apps/profiles/serializers.py @@ -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 diff --git a/conduit/settings.py b/conduit/settings.py index 17b2df7..2d97c19 100644 --- a/conduit/settings.py +++ b/conduit/settings.py @@ -25,7 +25,7 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = [] +ALLOWED_HOSTS = ['*'] # Application definition diff --git a/requirements.txt b/requirements.txt index 8a75b85..bec789a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,9 @@ -Django -django-cors-middleware -django-extensions -djangorestframework -PyJWT -six +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 \ No newline at end of file From b8d3e5d8b4e5066686c5c33968acde2e2efed531 Mon Sep 17 00:00:00 2001 From: mojtabaakbari221b Date: Thu, 20 May 2021 13:45:55 +0430 Subject: [PATCH 4/4] add teams api --- conduit/apps/articles/urls.py | 2 ++ conduit/apps/profiles/admin.py | 15 ++++++++ .../migrations/0004_auto_20210520_0732.py | 32 +++++++++++++++++ conduit/apps/profiles/models.py | 7 ++++ conduit/apps/profiles/urls.py | 3 +- conduit/apps/profiles/views.py | 34 ++++++++++++++++++- 6 files changed, 91 insertions(+), 2 deletions(-) create mode 100644 conduit/apps/profiles/admin.py create mode 100644 conduit/apps/profiles/migrations/0004_auto_20210520_0732.py diff --git a/conduit/apps/articles/urls.py b/conduit/apps/articles/urls.py index ed3e46e..70bb755 100644 --- a/conduit/apps/articles/urls.py +++ b/conduit/apps/articles/urls.py @@ -25,4 +25,6 @@ CommentsDestroyAPIView.as_view()), url(r'^tags/?$', TagListAPIView.as_view()), + + ] diff --git a/conduit/apps/profiles/admin.py b/conduit/apps/profiles/admin.py new file mode 100644 index 0000000..38e091b --- /dev/null +++ b/conduit/apps/profiles/admin.py @@ -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) \ No newline at end of file diff --git a/conduit/apps/profiles/migrations/0004_auto_20210520_0732.py b/conduit/apps/profiles/migrations/0004_auto_20210520_0732.py new file mode 100644 index 0000000..ed9927f --- /dev/null +++ b/conduit/apps/profiles/migrations/0004_auto_20210520_0732.py @@ -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'), + ), + ] diff --git a/conduit/apps/profiles/models.py b/conduit/apps/profiles/models.py index 6c47aa8..fffe614 100644 --- a/conduit/apps/profiles/models.py +++ b/conduit/apps/profiles/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.db.models.fields.related import ForeignKey from conduit.apps.core.models import TimestampedModel @@ -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`. @@ -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) \ No newline at end of file diff --git a/conduit/apps/profiles/urls.py b/conduit/apps/profiles/urls.py index 7ca5610..4ef10fb 100644 --- a/conduit/apps/profiles/urls.py +++ b/conduit/apps/profiles/urls.py @@ -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\w+)/?$', ProfileRetrieveAPIView.as_view()), url(r'^profiles/(?P\w+)/follow/?$', ProfileFollowAPIView.as_view()), + url(r'^teams/$', AllTeamAPIView.as_view()), ] diff --git a/conduit/apps/profiles/views.py b/conduit/apps/profiles/views.py index 674c66c..ac2f76d 100644 --- a/conduit/apps/profiles/views.py +++ b/conduit/apps/profiles/views.py @@ -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 @@ -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)