Example #1
0
def get_user_recent_activity(user):
 
    ratings = Rating.objects.filter(user=user).order_by('-date')[:5]
   
    feed = []
    
    for r in ratings:
        r.type = "business"
        r.business = get_single_bus_data(r.business, user, isSideBar=True)
        r.user.photo = get_user_profile_pic(r.user)
        feed.append(r)
    allcomments = Comment.objects.filter(user=user).order_by('-date')
    for c in allcomments:
        try: 
            tc = TagComment.objects.get(thread=c)
            tc.type = "tagcomment"
            tc.business = get_single_bus_data(tc.business, user, isSideBar=True)
            tc.user.photo = get_user_profile_pic(c.user)

            feed.append(tc)
        except:
            pass
        
        try:
            bc = BusinessComment.objects.get(thread=c)
            bc.business = get_single_bus_data(bc.business, user, isSideBar=True)
            bc.type = "buscomment"
            bc.user.photo = get_user_profile_pic(c.user)
            feed.append(bc) 
        except:
            pass
    return feed
Example #2
0
def add_bus_rating(request):
    if request.method == "POST":
        try:
            business = Business.objects.get(id=request.POST["bid"])
        except Business.DoesNotExist:
            print("bus does not exist!")
            return HttpResponse("{'success': 'false'}")

        rat = request.POST["rating"]
        try:
            rating = Rating.objects.get(business=business, user=request.user)
        except Rating.DoesNotExist:
            logger.debug("In vote create a new rating!")
            rating = Rating(business=business, user=request.user, rating=rat)
        else:
            Rating.objects.filter(business=business, user=request.user).delete()
            rating = Rating(business=business, user=request.user, rating=rat)

        rating.save()
        response_data = dict()
        response_data["bid"] = str(request.POST["bid"])
        response_data["success"] = "true"
        response_data["rating"] = rat
        context = {}
        business.rating = rating.rating
        context["business"] = get_single_bus_data(business, request.user)
        return render_to_response("ratings/listing/rate_data.html", context)
        # return HttpResponse("{'success':'true', 'rating': '" + str(rat) + "'}")
    else:
        raise Http404("What are you doing here?")
Example #3
0
def ans_business_questions(request,bus_id):
    if not request.user.is_authenticated():
        return HttpResponseRedirect('/accounts/login/?next=%s'%request.path)

    if request.method != 'POST':
        b = get_object_or_404(Business, pk=bus_id)
        try:
            b.photourl = get_photo_web_url(b)
        except:
            b.photourl= "" #NONE
        questions = get_questions(b,request.user)
        b = get_single_bus_data(b,request.user)

        context = get_default_bus_context(b, request.user)
        context['questions'] = questions
        context['value_questions'] = getValueTagsWithOptions()
        print(context['value_questions'][0].options)
        return render_to_response('ratings/contribute/ans_questions.html', context_instance=RequestContext(request,context))
    else:
        
        bid = request.POST['bid']
        values = []   
        booleans = []
        #get the list of anwers
        for key in request.POST:
            if key.find('answer') > -1:
                booleans.append(request.POST[key])
        for key in request.POST:
            if key.find('values') > -1:
                values.append(request.POST[key])
                
        b = Business.objects.get(id=bid)
        
        for v in booleans:
            ans = v.split('_')[1]
            qid = v.split('_')[0]
            hardtag = HardTag.objects.get(id=qid)
            if ans == 'y':
                BooleanQuestion.objects.create(hardtag=hardtag,business = b,user=request.user,agree=True)
            else:
                BooleanQuestion.objects.create(hardtag=hardtag,business = b,user=request.user,agree=False) 
        
        
        for v in values:
            ans = v.split('_')[1]
            vid = v.split('_')[0]
            valuetag = ValueTag.objects.get(id=vid)
            IntegerQuestion.objects.create(valuetag=valuetag,business = b,user=request.user,value=ans) 
          
        return redirect('/ratings/'+str(bus_id)+'/')
Example #4
0
def get_default_bus_context(b,user):
    comments = get_business_comments(b)
    bus_tags = get_tags_business(b,user=user,q="")
        
        
    user_tags = get_tags_user(user,"")
    top_tags = get_top_tags(10)    
    hard_tags = get_hard_tags(b)
    value_tags = get_value_tags(b)
    
    
    pages = get_pages(b,bus_tags,user)
    

    
    b = get_single_bus_data(b,user)
    context = {}
    context.update({
        'business' : b,
        'comments': comments, 
        'lat':b.lat,
        'lng':b.lon,  
        'bus_tags':bus_tags, 
        'pages': pages, 
        'master_summary': get_master_summary_tag(),
        'tags': Tag.objects.all().order_by('-descr').reverse(),
        'user_sorts':user_tags,
        'top_sorts':top_tags,
        'all_sorts':get_all_sorts(4),
        'hard_tags':hard_tags,
        'value_tags':value_tags,
        'location_term':get_community(user) ,
        'communities': Community.objects.all(),
        'following_business': is_user_subscribed(b,user),
         'feed' : get_bus_recent_activity(b),
        'bus_photos': get_all_bus_photos(b)
        })

    return context