def get_unauthenticated_context(): top_tags = get_top_tags(10) context = { \ 'top_sorts':top_tags,\ 'all_sorts':get_all_sorts(4),\ 'location_term':get_community(None)\ } return context
def get_default_blank_context(user): user_tags = get_tags_user(user,"") top_tags = get_top_tags(10) community = get_community(user) context = {\ 'communities': Community.objects.all(),\ 'community': community,\ 'user_sorts':user_tags,\ 'top_sorts':top_tags,\ 'tags': Tag.objects.all(),\ 'all_sorts':get_all_sorts(4),\ 'questions': HardTag.objects.all(),\ 'location_term':community } return context
def add_business(request): if not request.user.is_authenticated(): return HttpResponseRedirect('/accounts/login/?next=%s'%request.path) if request.method == 'POST': # add a business form = BusinessForm(request.POST, request.FILES) name = form.data['name'] logger.debug("Creation of business %s by %s", name,request.user.username) address = form.data['address'] city = form.data['city'] state = form.data['state'] loc = address + " " + city + " " + state latlng = get_lat(loc) if latlng: b = create_business(name, address, state, city, lat=latlng[0], lon =latlng[1]) else: b = create_business(name, address, state, city, lat=0, lon =0) if 'image' in request.FILES: img = request.FILES['image'] add_photo_by_upload(img,b,request.user,default=True) community = get_community(request.user) bm = BusinessMembership(business=b,community=community) bm.save() values = request.POST.getlist('answers') for v in values: 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) return redirect('/ratings/'+str(b.id)+'/') else: # Print a business form context = get_default_blank_context(request.user) context['questions'] = get_questions(None,request.user) context['form'] = BusinessForm() return render_to_response('ratings/contribute/add_business.html', context, context_instance=RequestContext(request))
def add_activity(request): if request.method == 'POST': # add a business form = ActivityForm(request.POST, request.FILES) name = form.data['name'] logger.debug("Creation of business %s by %s", name,request.user.username) descr = form.data['descr'] start = form.data['start'] end = form.data['end'] cid = form.data['community'] community = Community.objects.get(id=cid) act = create_activity(name=name,creator=request.user, descr=descr,community = community, start=start,end=end) act.save() community = get_community(request.user) return activities(request) else: # Print a boring business form f = ActivityForm() return render_to_response('activities/add_activity.html', {'form': f}, context_instance=RequestContext(request))
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
def activities(request): community = get_community(request.user) businesses = [] try: busMembership = BusinessMembership.objects.filter(community = community) for b in busMembership: businesses.append(b.business) except: logger.debug("error in getting businesses community, maybe businesses wasnt put in community?") businesses = Business.objects.all() activities = get_activites(community) paginator = Paginator(activities, 10) # Show 25 contacts per page page = request.GET.get('page') try: activities = paginator.page(page) except (PageNotAnInteger, TypeError): activities = paginator.page(1) except EmptyPage: activities = paginator.page(paginator.num_pages) return render_to_response('activities/activities.html', {'activities': activities, 'community':community}, context_instance=RequestContext(request))