Exemplo n.º 1
0
Arquivo: views.py Projeto: 19andt/test
    def get(self, request, *args, **kwargs):
        # Checking if user is authenticated
        if request.user.is_authenticated():
            # Getting the new subscription count
            observers = []

            for item in SubscriptionController.GetObservers(request.user):
                if item.timestamp > request.user.last_login:
                    observers.append(SubscriptionSerializer(item).data)
            # Getting the new review count
            reviews = []

            for item in ReviewController.ReviewsForUser(request.user):
                if item.created > request.user.last_login and item.added_by != request.user:
                    reviews.append({
                        'review':
                        ReviewSerializer(item).data,
                        'topic_list':
                        ReviewTopicController.GetTopics(item)
                    })

            # Returning the response with reviews and subscription list
            return JsonResponse({
                'Reviews': reviews,
                'Observers': observers,
                'UserAuthenticated': True
            })
        else:
            # User is not authenticated
            return JsonResponse({'UserAuthenticated': False})
Exemplo n.º 2
0
    def GetReviewsForTopic(Topic, User):
        # Getting the reviews for a topic from the review controller
        reviews=list(ReviewController.GetReviewsByTopic(Topic=Topic))

        # Making a dictionary for the review and the rating information
        derived_list={}

        # Looping through each item in the review list
        for index, review_item in enumerate(sorted(reviews, key=lambda x: x.created)[::-1]):
            # Initializing the comment list
            comment_list = []

            # Getting comments
            for comment in CommentController.GetCommments(Review=review_item):
                comment_list.append(CommentSerializer(comment).data)

            # Adding a dictionary object with the int as key and review and rating data as a part of another dictionary
            derived_list[index]={
                'review': ReviewSerializer(review_item).data,
                'rating': RatingController.GetRating(Person=User, Review=review_item),
                'topic_list': ReviewTopicController.GetTopics(Review=review_item),
                'comment_list': comment_list
            }

        # Returning the derived list
        return derived_list
Exemplo n.º 3
0
 def get(self, request, id, *args, **kwargs):
     # Checking if the user is authenticated
     if request.user.is_authenticated():
         # Getting the review by ID
         review = ReviewController.GetReviewByID(ID=id)
         # Checking if the review is empty
         if review is not None:
             # Returning the response with the review details
             return JsonResponse({
                 'Review':
                 ReviewSerializer(review).data,
                 'Rating':
                 RatingController.GetRating(Person=request.user,
                                            Review=review),
                 'TopicList':
                 ReviewTopicController.GetTopics(Review=review),
                 'MaxRating':
                 5
             })
         else:
             # Returning the response with unable to find the review
             return JsonResponse({'Review': None, 'MaxRating': 5})
     else:
         # Returning the response with unable to find the review
         return JsonResponse({'Review': None, 'MaxRating': 5})
Exemplo n.º 4
0
    def GetReviewsByTopic(Topic):
        # Getting the reviews for a topic
        qs = ReviewTopicController.GetReviews(Topic=Topic)

        review_list=[]
        for item in qs:
            review_list.append(item.review)
        return review_list
Exemplo n.º 5
0
 def get(self, request, *args, **kwargs):
     if request.user.is_authenticated():
         trending_list = ReviewTopicController.GetTrendingTopics(7)
         return JsonResponse({
             'TrendingTopics': trending_list,
             'UserAuthenticated': True
         })
     return JsonResponse({'UserAuthenticated': False})
Exemplo n.º 6
0
    def GetReviewsForUser(User):
        # Getting the interests for the user
        interests=InterestController.GetInterests(User=User)
        # Getting the subscription for the user
        subscriptions=SubscriptionController.GetSubscriptions(User=User)

        # Making an empty list of reviews
        reviews=[]

        # Appending the reviews added by the user to the list
        # reviews.extend(list(ReviewController.GetReviewsByUser(User=User)))

        # Appending the reviews by the interest to the list
        for interest in interests:
            reviews.extend(list(ReviewController.GetReviewsByTopic(Topic=interest.topic)))

        # Appending the reviews by the subscriptions to the list
        for subscription in subscriptions:
            reviews.extend(list(ReviewController.ReviewsByUser(User=subscription.reviewer)))

        # Making a dictionary of reviews with ID as a key
        dictionary={}

        # Looping through each object in the review list
        for obj in reviews:
            dictionary[obj.pk]=obj

        # Retrieving unique reviews from the dictionary
        reviews=dictionary.values()

        # Making a dictionary for the review and the rating information
        derived_list={}

        # Looping through each item in the unique review list
        for index, review_item in enumerate(sorted(reviews, key=lambda x: x.created)[::-1]):
            # Initializing the comment list
            comment_list = []

            # Getting comments
            for comment in CommentController.GetCommments(Review=review_item):
                comment_list.append(CommentSerializer(comment).data)

            # Adding a dictionary object with the int as key and review and rating data as a part of another dictionary
            derived_list[index]={
                'review': ReviewSerializer(review_item).data,
                'rating': RatingController.GetRating(Person=User, Review=review_item),
                'topic_list': ReviewTopicController.GetTopics(Review=review_item),
                'comment_list': comment_list
            }

        # Returning the derived list
        return derived_list
Exemplo n.º 7
0
    def AddReview(Data):
        # Creating a new review object and adding the parameters
        new_review=review.objects.create(
            added_by=Data.get('added_by'),
            caption=Data.get('caption'),
            briefing=Data.get('briefing'),
            # review_rating=Data.get('review_rating'),
            # pic=Data.get('pic')
        )
        # Saving the new review
        new_review.save()

        print(Data)
        InterestController.AddInterests(Data.get('added_by'), Data.get('topic_list'))

        review_topics = []
        for item in Data.get('topic_list'):
            review_topics.append(TopicController.GetTopic(Name=item.get('text'))[0])

        print(review_topics)
        ReviewTopicController.AddTopics(new_review, review_topics)
        return True
Exemplo n.º 8
0
    def GetReviewsByUser(User):
        # Getting the review added by the user
        reviews = review.objects.filter(added_by=User)

        derived_list = {}

        for index, review_item in enumerate(sorted(reviews, key=lambda x: x.created)[::-1]):
            # Initializing the comment list
            comment_list = []

            # Getting comments
            for comment in CommentController.GetCommments(Review=review_item):
                comment_list.append(CommentSerializer(comment).data)

            # Adding a dictionary object with the int as key and review and rating data as a part of another dictionary
            derived_list[index] = {
                'review': ReviewSerializer(review_item).data,
                'rating': RatingController.GetRating(Person=User, Review=review_item),
                'topic_list': ReviewTopicController.GetTopics(Review=review_item),
                'comment_list': comment_list
            }

        # Returning the derived list
        return derived_list