Exemple #1
0
    def handle(self, *args, **options):
        count = options["reviews"]

        ignored = 0
        # generate reviews
        for i in range(count):
            print "generate review %d" % (i + 1)
            order = random.choice(Order.objects.all())
            if not order.orderitem_set.all():
                print "ignore order: %d, it has no orderitems" % order.id
                continue
            orderitem = random.choice(order.orderitem_set.all())
            if Review.objects.filter(orderitem=orderitem).first():
                print "ignoring orderitem: %s, it has a review already" % orderitem
                ignored += 1
                continue
            r = Review()
            r.orderitem = orderitem
            r.rating = random.randint(1, 5)
            r.language = order.table.restaurant.menu.language
            r.text = random.choice(review_texts)
            r.user = order.user
            r.save()

        self.stdout.write('Successfully added %d reviews' % (count - ignored))
Exemple #2
0
def save_review_from_row(review_row):
    review= Review()
    userprofile = UserProfile.objects.get(id=review_row[1])
    sake = Product.objects.get(id=review_row[2])

    review.id = review_row[0]
    review.user = userprofile
    review.sake = sake
    review.rating = review_row[3]
    review.content = review_row[4]
    review.date = datetime.datetime.now()
    review.save()
Exemple #3
0
def main():
    reviews = json.loads(open("reviews.json", "r").read())

    Review.objects.filter(is_crawled=True).delete()
    total_added = 0
    for review in reviews:
        code = review["course"]
        course_query = CourseCode.objects.filter(code=code)
        if course_query.exists():
            r = Review()
            r.course = course_query[0].course
            r.rating = review["rating"]
            r.grade = review["grade"]
            r.text = review["text"].replace("<div>", "").replace("</div>", "")
            r.is_crawled = True
            r.created_at = str_to_timestamp(review["created_at"])
            r.updated_at = str_to_timestamp(review["updated_at"])
            r.author = DEFAULT_USER
            r.save()
            total_added += 1
            if total_added % 50 == 0:
                print "Added %s reviews" % total_added
Exemple #4
0
def add_review(request, slug):

    user = request.user
    userprofile = UserProfile.objects.get(user=user)
    sake = get_object_or_404(Product, slug=slug)
    form = ReviewForm(request.POST, instance=userprofile)

    try:
        review_check = Review.objects.get(user=userprofile, sake=sake)

    except Review.DoesNotExist:
        pass
    else:
        messages.info(request,
                      'You have already written a review for this sake.')
        return HttpResponseRedirect(reverse('product', args=(slug, )))

    if request.method == 'POST':
        form = ReviewForm(data=request.POST, instance=userprofile)
        if form.is_valid():
            review = Review()
            content = form.cleaned_data['content']
            rating = form.cleaned_data['rating']
            review.user = userprofile
            review.content = content
            review.rating = rating
            review.date = datetime.now()
            review.sake = sake
            review.save()
            form.save()
            update_clusters(is_new_user=False)
            messages.success(request, "Thank you for your review!")
            return HttpResponseRedirect(reverse('product', args=(slug, )))

    return render(request, 'reviews/add_review.html', {
        'sake': sake,
        'form': form
    })