def rate(request, id, rating): item = get_object_or_404(Item, id=id) if not request.is_ajax(): return redirect(item.get_absolute_url()) qs = ItemVote.objects.filter(item=item, user=request.user, review=None) if qs.count(): vote = qs[0] vote.ratio = int(rating) else: vote = ItemVote(item=item, user=request.user, ratio=int(rating)) vote.ip_address = request.META.get("REMOTE_ADDR", None) vote.timestamp = datetime.datetime.now() vote.save() return JsonResponse(get_item_details(vote.item, request))
def import_votes(self, user_id): c = self.mconn.cursor() c.execute("select s.vote_date, s.ratio, s.host_ip, i.upc, i.id from item_votes s inner join items i on s.ref_item=i.id where s.ref_user=%s order by s.id", [user_id,]) for vote_date, ratio, host_ip, upc, id in c.fetchall(): if vote_date is not None: item = self.get_item(upc) if not item: self.missing_items.add(id) continue o = ItemVote( user_id = user_id, item = item, timestamp = vote_date, ratio = ratio, ip_address = host_ip ) o.save()