def get_review_text(request): """Get the review text for the given productid.""" if request.method != 'POST': return HttpResponseBadRequest("Only accessible with POST.") json_data = json.loads(request.body.decode('utf-8')) try: productid = json_data['productid'] product = Product.objects.get(id=productid) except: return HttpResponseBadRequest("The product doesn't exist.") try: userid = json_data['userid'] user = User.objects.get(id=userid) except: return HttpResponseBadRequest("The user doesn't exist.") review_data = utils.get_review_data(user, product) if review_data is False: return HttpResponseBadRequest("The review doesn't exist.") return JsonResponse(review_data)
def get_initial_data(request): """ENDPOINT - Returns initial data.""" products = get_products() for p in products: # we update with review data (the user review) rd = dict(review=utils.get_review_data(request.user, p['id'])) p.update(rd) # we update with review info (who reviewed it) rev_info = utils.get_reviewers(request.user, p['id']) if rev_info: p.update(rev_info) # we update with wishlist tag p['iswish'] = is_wish(request.user.pk, p['id']) tags = Tag.objects.get_tag_names() try: tabs = list((request.user.usercontrolgroup .control_group.tabs.values_list('tab', flat=True))) except: tabs = None show_user_pics = True display_reviews_in_user_pages = True network_traversing = True display_all_reviews = True try: show_user_pics = request.user.usercontrolgroup.control_group.show_user_pictures except: pass try: display_reviews_in_user_pages = request.user.usercontrolgroup.control_group.display_reviews_in_user_pages except: pass try: network_traversing = request.user.usercontrolgroup.control_group.network_traversing except: pass try: display_all_reviews = request.user.usercontrolgroup.control_group.display_all_reviews except: pass response = dict( minwishes=settings.MIN_NUMBER_WISHES, displayReviewsInUserPages=display_reviews_in_user_pages, networkTraversing=network_traversing, displayAllReviews=display_all_reviews, showUsersPics=show_user_pics, tabs=tabs, tags=tags, products=products, review_elements=utils.get_review_tree()) return JsonResponse(response)
def get_initial_data(request): """ENDPOINT -- Get initial data.""" products = get_products() # We add the review data for each product for p in products: rd = dict(review=get_review_data(request.user, p['id'])) p.update(rd) tags = Tag.objects.get_tag_names() review_tree = get_review_tree() number_reviews = get_number_reviews(request.user) data = { 'minreviews': settings.MIN_NUMBER_REVIEWS, 'products': products, 'tags': tags, 'name': request.user.first_name, 'reviewElements': review_tree, 'numberReviews': number_reviews } return http.JsonResponse(data)
def get_user_page(request): if request.method == 'POST': json_data = json.loads(request.body.decode('utf-8')) try: user_id = json_data['userid'] user = User.objects.get(id=user_id) except: return HttpResponseBadRequest("The user doesn't exists.") elif request.method == 'GET': user = request.user try: products = [x['product'] for x in Reviewing.objects.filter(user=user).values("product")] all_products = get_products() reviewed_products = [p for p in all_products if p['id'] in products] for p in reviewed_products: p['iswish'] = is_wish(request.user.pk, p['id']) p['review'] = utils.get_review_data(user.id, p['id']) except: pass friends = get_friends(user) friends_res = [] for f in friends: friends_res.append(get_user(f)) response = dict( user=get_user(user.id), friends=friends_res, products=reviewed_products ) return JsonResponse(response)
def step1(request): """PAGE -- The main phase 1 reviewing page that loads the React app.""" current_phase = Phase.objects.all().first().phase if (request.user.userstep.phase1_step != 1 or current_phase != 1) and\ not request.user.is_superuser: return redirect_user_to_current_step(request.user) else: try: Tracked.objects.create( user=request.user, data={ 'userAgent': request.META.get('HTTP_USER_AGENT', None), 'referrer': request.META.get('HTTP_REFERER', None), }, hook='REVIEW_APP_ENTERED', ) except: pass products = get_products() # We add the review data for each product for p in products: rd = dict(review=get_review_data(request.user, p['id'])) p.update(rd) tags = Tag.objects.get_tag_names() number_reviews = get_number_reviews(request.user) review_tree = get_review_tree() context_dict = { 'products': json.dumps(products), 'tags': tags, 'name': request.user.first_name, 'review_elements': review_tree, 'number_reviews': number_reviews } return render(request, 'phase1/step1.djhtml', context_dict)