-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Final tests with development server, Login signup set up
- Loading branch information
Showing
199 changed files
with
37,645 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: gunicorn social_media_api.wsgi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
from django.contrib import admin | ||
from django.contrib import admin | ||
from .models import CustomUser, Follow | ||
|
||
# Register the CustomUser model | ||
admin.site.register(CustomUser) | ||
|
||
# Register your models here. | ||
# Register the Follow model | ||
admin.site.register(Follow) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# accounts/serializers.py | ||
from rest_framework import serializers | ||
from .models import CustomUser, Follow | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,72 @@ | ||
from django.shortcuts import render | ||
from rest_framework import viewsets, permissions | ||
from .models import CustomUser | ||
from .serializers import UserSerializer | ||
from .models import CustomUser, Follow | ||
from .serializers import UserSerializer, FollowSerializer | ||
from rest_framework.decorators import api_view, permission_classes | ||
from rest_framework.permissions import IsAuthenticated | ||
from rest_framework.response import Response | ||
from rest_framework import status | ||
from django.contrib.auth import get_user_model | ||
from .models import Follow | ||
from .serializers import FollowSerializer | ||
from django.urls import reverse_lazy | ||
from django.views.generic import ListView, DetailView, CreateView, UpdateView | ||
from .models import CustomUser | ||
|
||
User = get_user_model() | ||
# Create your views here. | ||
from django.contrib.auth import login, authenticate | ||
from django.shortcuts import render, redirect | ||
|
||
class UserViewSet(viewsets.ModelViewSet): | ||
queryset = CustomUser.objects.all() | ||
serializer_class = UserSerializer | ||
permission_classes = [permissions.IsAuthenticatedOrReadOnly] | ||
|
||
class UserListView(ListView): | ||
model = CustomUser | ||
template_name = 'accounts/user_list.html' | ||
context_object_name = 'users' | ||
|
||
class UserDetailView(DetailView): | ||
model = CustomUser | ||
template_name = 'accounts/user_detail.html' | ||
context_object_name = 'user' | ||
|
||
class UserCreateView(CreateView): | ||
model = CustomUser | ||
template_name = 'accounts/user_create.html' | ||
fields = ['username', 'email', 'password', 'bio', 'profile_picture'] | ||
success_url = '/' | ||
|
||
def form_valid(self, form): | ||
form.save() | ||
username = form.cleaned_data.get('username') | ||
raw_password = form.cleaned_data.get('password') | ||
user = authenticate(username=username, password=raw_password) | ||
login(self.request, user) | ||
return redirect('home') | ||
|
||
class UserUpdateView(UpdateView): | ||
model = CustomUser | ||
template_name = 'accounts/user_update.html' | ||
fields = ['username', 'email', 'bio', 'profile_picture'] | ||
success_url = '/' | ||
|
||
@api_view(['POST']) | ||
@permission_classes([IsAuthenticated]) | ||
def follow_user(request, user_id): | ||
try: | ||
user_to_follow = User.objects.get(id=user_id) | ||
user_to_follow = CustomUser.objects.get(id=user_id) | ||
if Follow.objects.filter(follower=request.user, following=user_to_follow).exists(): | ||
return Response({'detail': 'Already following this user.'}, status=status.HTTP_400_BAD_REQUEST) | ||
if request.user == user_to_follow: | ||
return Response({'detail': 'You cannot follow yourself.'}, status=status.HTTP_400_BAD_REQUEST) | ||
Follow.objects.create(follower=request.user, following=user_to_follow) | ||
return Response({'detail': 'Followed successfully.'}, status=status.HTTP_200_OK) | ||
except User.DoesNotExist: | ||
except CustomUser.DoesNotExist: | ||
return Response({'detail': 'User not found.'}, status=status.HTTP_404_NOT_FOUND) | ||
|
||
@api_view(['POST']) | ||
@permission_classes([IsAuthenticated]) | ||
def unfollow_user(request, user_id): | ||
try: | ||
user_to_unfollow = User.objects.get(id=user_id) | ||
user_to_unfollow = CustomUser.objects.get(id=user_id) | ||
follow_instance = Follow.objects.filter(follower=request.user, following=user_to_unfollow) | ||
if follow_instance.exists(): | ||
follow_instance.delete() | ||
return Response({'detail': 'Unfollowed successfully.'}, status=status.HTTP_200_OK) | ||
return Response({'detail': 'You are not following this user.'}, status=status.HTTP_400_BAD_REQUEST) | ||
except User.DoesNotExist: | ||
except CustomUser.DoesNotExist: | ||
return Response({'detail': 'User not found.'}, status=status.HTTP_404_NOT_FOUND) | ||
|
||
|
||
class UserListView(ListView): | ||
model = CustomUser | ||
template_name = 'accounts/user_list.html' | ||
context_object_name = 'users' | ||
|
||
class UserDetailView(DetailView): | ||
model = CustomUser | ||
template_name = 'accounts/user_detail.html' | ||
context_object_name = 'user' | ||
|
||
class UserCreateView(CreateView): | ||
model = CustomUser | ||
template_name = 'accounts/user_create.html' | ||
fields = ['username', 'email', 'bio', 'profile_picture'] | ||
success_url = reverse_lazy('user-list') | ||
|
||
class UserUpdateView(UpdateView): | ||
model = CustomUser | ||
template_name = 'accounts/user_update.html' | ||
fields = ['username', 'email', 'bio', 'profile_picture'] | ||
success_url = reverse_lazy('user-list') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from django.contrib import admin | ||
from django.contrib import admin | ||
from .models import Notification | ||
|
||
# Register your models here. | ||
# Register the Notification model | ||
admin.site.register(Notification) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
from django.contrib import admin | ||
from django.contrib import admin | ||
from .models import Post | ||
|
||
# Register your models here. | ||
# Register the Post model | ||
admin.site.register(Post) |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
from django.shortcuts import render | ||
|
||
def home_view(request): | ||
return render(request, 'home.html') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.