Exemple #1
0
    def get(self, request, num_posts):
        categories = (
            "Lifestyle",
            "IT",
            "Events",
            "Tutoring",
            "Art",
            "Household",
            "Labor",
            "Other",
        )
        posts = {}
        api = APIV1()

        for category in categories:
            result = api.post_top_n(category, num_posts)

            posts_in_category = {}
            for post in result['Posts']:
                fields = {
                    'request_type': post['fields']['request_type'],
                    'deadline': post['fields']['deadline'],
                    'title': post['fields']['title'],
                    'zip_code': post['fields']['zip_code'],
                    'id': post['pk']
                }

                posts_in_category[post['pk']] = fields

            posts[category] = posts_in_category
        return JsonResponse({'data': posts}, status=200)
Exemple #2
0
 def post(self, request): 
     
     data = request.body.decode('utf-8')
     newdata = json.loads(data)
     api = APIV1()
     first_name = newdata['first_name']
     last_name = newdata['last_name']
     email = newdata['email']
     password = newdata['password']
     rating = float(newdata['rating'])
     description = newdata['description']
     education = newdata['education']
     zip_code = int(newdata['zip_code'])
     # data2 = {
     #     'first_name': first_name,
     #     'last_name': last_name,
     #     'email':  email,
     #     'password': password,
     #     'rating':  rating,
     #     'description': description,
     #     'education': education,
     #     'zip_code': zip_code,
     # }
     
     
     res = api.user_create(first_name,last_name,email, password, description, education)
     return JsonResponse(res, safe=False)
Exemple #3
0
    def get(self, request, post_id):

        api = APIV1()

        if 'HTTP_AUTHORIZATION' in request.META:
            token = str(request.META['HTTP_AUTHORIZATION']).split()[1]
            profile = api.profile_get_with_token(token)
            if 'id' in profile[1]:
                user_id = profile[1]['id']
            else:
                user_id = -1
            post = api.post_get_and_log(post_id, user_id)
        else:
            post = api.post_get_and_log(post_id, -1)

        recommended = []

        for rec in post[1]['post']['recommendations']:
            rec_post = api.post_get(rec)[1]
            rec_post_id = rec_post['post']
            rec_post_id['id'] = rec_post['id']
            recommended.append(rec_post_id)

        post[1]['post']['recommendations'] = recommended
        return JsonResponse(post, safe=False)
Exemple #4
0
    def post(self, request):

        data = request.body.decode('utf-8')
        newdata = json.loads(data)
        api = APIV1()

        email = newdata['email']
        password = newdata['password']

        response_code, response_body = api.login_login(email, password)

        return JsonResponse(response_body, status=response_code)
Exemple #5
0
    def post(self, request):

        data = request.body.decode('utf-8')
        newdata = json.loads(data)
        api = APIV1()
        first_name = newdata['first_name']
        last_name = newdata['last_name']
        email = newdata['email']
        password = newdata['password']

        response_code, response = api.login_create(first_name, last_name,
                                                   email, password)
        return JsonResponse(response, status=response_code, safe=False)
Exemple #6
0
    def post(self, request, token):

        data = request.body.decode('utf-8')
        newdata = json.loads(data)
        api = APIV1()

        title = newdata['title']
        details = newdata['details']
        category = newdata['category']
        preferred_contact = newdata['preferred_contact']
        deadline = newdata['deadline']
        request_type = newdata['request_type']
        zip_code = newdata['zip_code']
        res = api.post_create(title, details, category, preferred_contact,
                              deadline, request_type, zip_code, token)

        return JsonResponse(res, safe=False)
Exemple #7
0
 def get(self, request, token):
     api = APIV1()
     res = api.login_logout(token)
     return JsonResponse(res, safe=False)
Exemple #8
0
 def get(self, request, keywords):
     api = APIV1()
     results = api.post_search(keywords)
     return JsonResponse({"posts": results})