Skip to content

Commit

Permalink
Merge pull request #436 from SCCapstone/social-comment
Browse files Browse the repository at this point in the history
done commenting
  • Loading branch information
lxaw authored Mar 31, 2023
2 parents 35caacc + 3047abf commit 4561e4c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
6 changes: 4 additions & 2 deletions delta_web/delta/social/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
# Naveen Chithan (@nchithan)
#
# File name:
#
# Admin.py
# Brief description:
# Set up the admin page for the social Django app. You can visit the admin page by going to /admin.
#
from django.contrib import admin

# import models
from .models import (Review,NotificationReview,
Conversation, Message,NotificationMessage,NotificationNews,
NotificationWhatsHot
Expand All @@ -24,7 +26,6 @@
class ReviewAdmin(admin.ModelAdmin):
fields = ['author','text','title','pub_date','active','rating']


class NotificationReviewAdmin(admin.ModelAdmin):
fields = ['text','read','pub_date','sender','recipient','review','title']

Expand All @@ -43,6 +44,7 @@ class NotificationNewsAdmin(admin.ModelAdmin):
class NotificationWhatsHotAdmin(admin.ModelAdmin):
fields = ['text','read','pub_date','recipient','title']

# Register admin models and admin settings to the website
admin.site.register(Review,ReviewAdmin)
admin.site.register(NotificationReview,NotificationReviewAdmin)
admin.site.register(Conversation,ConversationAdmin)
Expand Down
8 changes: 8 additions & 0 deletions delta_web/delta/social/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

# review api
class ViewsetReview(viewsets.ModelViewSet):
# need to be logged in (ie have an API key) to use this resource
permission_classes = [
permissions.IsAuthenticated,
]
Expand All @@ -46,26 +47,32 @@ class ViewsetReview(viewsets.ModelViewSet):
def get_queryset(self):
return self.request.user.review_set.all().order_by('-pub_date')

# create an object
def perform_create(self,serializer):
serializer.save(author=self.request.user,file=CSVFile.objects.get(pk=self.request.data['file']))

# get an instance of an object
def retrieve(self,request,pk=None):
return Response(self.serializer_class(Review.objects.get(pk=pk)).data)

# update an object
def partial_update(self,request,*args,**kwargs):
super().partial_update(request,*args,**kwargs)
return Response(self.serializer_class(Review.objects.get(pk=kwargs['pk'])).data)

# notification API
class ViewsetNotificationReview(viewsets.ModelViewSet):
# need to be logged in (have an API key) to access
permission_classes = [
permissions.IsAuthenticated,
]
serializer_class = SerializerNotificationReview

# get all notifications, order them by publication date
def get_queryset(self):
return self.request.user.recipient_notification_post_set.all().order_by('-pub_date')

# create a notification
def perform_create(self,serializer):
serializer.save()

Expand All @@ -74,6 +81,7 @@ def perform_create(self,serializer):
def get_unread(self,request):
return Response(SerializerNotificationReview(self.request.user.recipient_notification_post_set.filter(read=False).order_by('-pub_date'),many=True).data)

# perform the read action on a notification
@action(methods=['get'],detail=True)
def perform_read(self,*args,**kwargs):
instance = self.get_object()
Expand Down
3 changes: 2 additions & 1 deletion delta_web/delta/social/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
# Naveen Chithan (@nchithan)
#
# File name:
#
# urls.py
# Brief description:
# Routes the API endpoints to a URL.
#
from django.urls import path

Expand Down
18 changes: 0 additions & 18 deletions delta_web/delta/social/views.py

This file was deleted.

0 comments on commit 4561e4c

Please sign in to comment.