Exemplo n.º 1
0
 def AddInterests(User, Data):
     for item in Data:
         if item['type'] == 'new':
             topic_data = {
                 'name': item['text'],
                 'added_by': User,
                 'description': ''
             }
             if TopicController.AddTopic(Data=topic_data):
                 # Creating a new object for the interest and adding the parameters
                 new_interest = interest.objects.create(
                     user=User,
                     topic=TopicController.GetTopic(Name=item['text'])[0])
                 # Saving the interest
                 new_interest.save()
         else:
             # Checking if interest is present in database for the user
             qs = interest.objects.filter(
                 user=User,
                 topic=TopicController.GetTopic(Name=item['text'])[0])
             if qs.count() == 0:
                 # Creating a new object for the interest and adding the parameters
                 new_interest = interest.objects.create(
                     user=User,
                     topic=TopicController.GetTopic(Name=item['text'])[0])
                 # Saving the interest
                 new_interest.save()
     return True
Exemplo n.º 2
0
 def UpdateInterests(User, Data):
     # Getting the interests for the user
     qs = interest.objects.filter(user=User)
     # Converting the query results into a list
     qs_list = list(qs)
     # Printing the query set
     print(qs_list)
     # Looping through each item in the Data
     for item in Data:
         # Checking if the interest was previously added
         if item['type'] == 'old':
             # Filtering the query set for the topic name and the topic is not present
             if qs.filter(topic__name=item['text']).count() == 0:
                 # Creating a new object of interest and adding the parameters
                 new_interest = interest.objects.create(
                     user=User,
                     topic=TopicController.GetTopic(Name=item['text'])[0])
                 # Saving the interest object
                 new_interest.save()
             # Filtering th equery set for the topic name and topic is present
             elif qs.filter(topic__name=item['text']).count() == 1:
                 # Removing the item from the query set and *not from the database*
                 print('Removing')
                 print(item)
                 qs_list.remove(
                     list(qs.filter(topic__name=item['text']))[0])
                 # Printing the query set
                 print(qs_list)
         # Checking if interest is newly added by the user
         elif item['type'] == 'new':
             # Making a dictionary for the topic parameters
             topic_data = {
                 'name': item['text'],
                 'added_by': User,
                 'description': ''
             }
             # Adding the new topic into the database
             if TopicController.AddTopic(Data=topic_data):
                 # Creating a new object for the interest and adding the parameters
                 new_interest = interest.objects.create(
                     user=User,
                     topic=TopicController.GetTopic(Name=item['text'])[0])
                 # Saving the interest
                 new_interest.save()
     # Deleting the unused item from the database
     for item in qs_list:
         item.delete()
     # Returning
     return True
Exemplo n.º 3
0
 def get(self, request, *args, **kwargs):
     # Checking if the user is authenticated
     if request.user.is_authenticated():
         # Getting the interests for the user
         interest = InterestController.GetInterests(User=request.user)
         # Checking if the interests count is greater than zero
         if interest.count() > 0:
             # Getting the topics from the interests
             topics = interest.values_list('topic', flat=True)
             interest = []
             # Looping through the topics received
             for topic_id in topics:
                 # Getting the topic from ID
                 topic = TopicController.GetTopic(ID=topic_id)
                 # Checking if the topic is empty
                 if topic is not None:
                     # Appending the topic name to the interest
                     interest.append(topic[0].name)
         else:
             # Emptying the interest list
             interest = []
             # Returning the response with the interest list
         return JsonResponse({
             'InterestList': interest,
             'UserAuthenticated': True
         })
     else:
         # Returning the response without interest list
         return JsonResponse({'UserAuthenticated': False})
Exemplo n.º 4
0
    def post(self, request, topic_name, *args, **kwargs):
        try:
            # Getting the data from the request
            data = json.loads(request.body.decode('utf-8'))
        except:
            data = {}
        if request.user.is_authenticated():
            # Getting the topic from the controller
            qs = TopicController.GetTopic(Name=topic_name)
            if qs.count() != 0:
                current_topic = qs[0]
                if data.get('description') != None:
                    # Updating the description
                    current_topic.description = data.get('description')

                # Procedure for storing images
                if request.FILES.get('pic') != None:
                    pic = request.FILES.get('pic')
                    fs = FileSystemStorage()
                    filename = fs.save(
                        'topic/' + str(uuid.uuid4()) + '.' +
                        pic.name.split('.')[-1], pic)
                    uploaded_file_url = fs.url(filename)
                    current_topic.pic = uploaded_file_url[7:]
                # Save topic
                current_topic.save()
                # Returning the list
                return JsonResponse({'UpdateStatus': True})
            else:
                return JsonResponse({'UpdateStatus': False})
        else:
            return JsonResponse({'UpdateStatus': False})
Exemplo n.º 5
0
 def post(self, request, *args, **kwargs):
     # Getting the data from the request
     data=json.loads(request.body.decode('utf-8'))
     topic_list=[]
     # Getting the topics from the controller and appending it to the list
     for item in TopicController.GetTopics(Name=data.get('topic_name')):
         topic_list.append(item)
     # Returning the list
     return JsonResponse({'TopicList': topic_list})
Exemplo n.º 6
0
 def get(self, request, topic_name, *args, **kwargs):
     # Searching for the topic name in the database
     qs = TopicController.GetTopic(Name=topic_name)
     print(topic_name)
     # Returning the result
     if qs.count() == 0:
         return JsonResponse({'Topic': None})
     else:
         return JsonResponse({'Topic': TopicSerializer(qs[0]).data})
Exemplo n.º 7
0
 def post(self, request, topic_name, *args, **kwargs):
     # Getting the data from the request
     data = json.loads(request.body.decode('utf-8'))
     print(data)
     if request.user.is_authenticated():
         if data.get('update_interest_status'):
             if InterestController.AddInterests(User=request.user,
                                                Data=[{
                                                    'type': 'old',
                                                    'text': topic_name
                                                }]):
                 return JsonResponse({
                     'InterestStatus': True,
                     'UpdateInterestStatus': True,
                     'UserAuthenticated': True
                 })
             else:
                 qs = InterestController.GetInterest(
                     User=request.user,
                     Topic=TopicController.GetTopic(Name=topic_name))
                 print(qs)
                 if qs.count() == 1:
                     return JsonResponse({
                         'InterestStatus': True,
                         'UpdateInterestStatus': False,
                         'UserAuthenticated': True
                     })
                 else:
                     return JsonResponse({
                         'InterestStatus': False,
                         'UpdateInterestStatus': False,
                         'UserAuthenticated': True
                     })
         else:
             InterestController.DeleteInterest(
                 User=request.user,
                 Topic=TopicController.GetTopic(Name=topic_name))
             return JsonResponse({
                 'InterestStatus': False,
                 'UpdateInterestStatus': True,
                 'UserAuthenticated': True
             })
     else:
         return JsonResponse({'UserAuthenticated': False})
Exemplo n.º 8
0
    def GetTrendingTopics(days):
        time_threshold = datetime.now() - timedelta(days=days)
        print(time_threshold)
        topics = review_topic.objects.values('topic').filter(
            created__gt=time_threshold)

        topic_list = []
        for topic in topics:
            topic_list.append(
                TopicController.GetTopic(ID=topic.get('topic'))[0].name)

        topic_list = [[i, j]
                      for i, j in Counter(topic_list).most_common()[:10]]
        return topic_list
Exemplo n.º 9
0
 def get(self, request, topic_name, *args, **kwargs):
     if request.user.is_authenticated():
         qs = InterestController.GetInterest(
             User=request.user,
             Topic=TopicController.GetTopic(Name=topic_name))
         print(qs)
         if qs.count() == 1:
             return JsonResponse({
                 'InterestStatus': True,
                 'UserAuthenticated': True
             })
         else:
             return JsonResponse({
                 'InterestStatus': False,
                 'UserAuthenticated': True
             })
     else:
         return JsonResponse({'UserAuthenticated': False})
Exemplo n.º 10
0
 def get(self, request, topic_name, *args, **kwargs):
     # Checking if the user is authenticated
     if request.user.is_authenticated():
         # Getting the topic from the topic controller
         topic = TopicController.GetTopic(Name=topic_name)
         # Returning the response with reviews for the topic
         return JsonResponse({
             'ReviewsList':
             ReviewController.GetReviewsForTopic(Topic=topic,
                                                 User=request.user),
             'MaxRating':
             5,
             'User':
             UserSerializer(request.user).data
         })
     else:
         # Returning the response with no reviews
         return JsonResponse({'ReviewsList': {}, 'MaxRating': 5})
Exemplo n.º 11
0
Arquivo: views.py Projeto: 19andt/test
    def post(self, request, *args, **kwargs):
        # Getting the data from the request
        data = json.loads(request.body.decode('utf-8'))
        print(data)

        user_list = []
        # Getting the users from the controller and appending it to the list
        for item in GetUser.get_users(Name=data.get('search_text')):
            user_list.append(item)

        topic_list = []
        # Getting the topics from the controller and appending it to the list
        for item in TopicController.GetTopics(Name=data.get('search_text')):
            topic_list.append(item)
        return JsonResponse({
            'SearchingFor': data.get('search_text'),
            'TopicList': topic_list,
            'UserList': user_list
        })
Exemplo n.º 12
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.º 13
0
 def post(self, request, *args, **kwargs):
     # Getting the data from the request
     data = json.loads(request.body.decode('utf-8'))
     # Checking if the user is authenticated
     if request.user.is_authenticated():
         # Making a dictionary for the review parameters
         new_topic = {
             'name': data.get('name'),
             'description': data.get('description'),
             'added_by': request.user,
         }
         # Adding the new review into the database
         if TopicController.AddTopic(new_topic):
             InterestController.AddInterests(User=request.user,
                                             Data=[{
                                                 'type': 'old',
                                                 'text': data.get('name')
                                             }])
             # Returning the response with new review added
             return JsonResponse({'AddTopicStatus': True})
         else:
             # Returning the response with unable add new review
             return JsonResponse({'AddTopicStatus': False})