def get_poll_chart_url(self, poll_id, demographic_url_string="", type="", do_spillover=""): gcf = GChartFactory() ps = PollService() p = Poll.objects.get(id=poll_id) results = ps.get_poll_results(poll=p, drop_zero_results=True) pchart = gcf.get_pie_chart(results) print pchart.get_url() return pchart.get_url()
def getPollsForLister(self, polls=None, user=None, page_num=1, page_link_prefix=""): """ @param user: ALWAYS the request.user given a list of poll objects, this will return a hash with a list of tuples with the following order { "paginator":paginator object, "polls":[(poll, file, tags), ...] } This badboy also returns some major paging shit!!!!! """ if polls == None: return None request_user = user pollListerHash = {} paged_polls = Paginator(polls, consts.POLL_LISTER_RPP) pollListerHash["paginator"] = paged_polls pollListerHash["total"] = len(polls) polls_page = paged_polls.page(page_num) page_hash = paging_utils.setup_page_hash( paginator=paged_polls, page_num=page_num, page_link_prefix=page_link_prefix) pollListerHash.update(page_hash) polls = polls_page.object_list aug_polls = [] # go over db polls for p in polls: file = None poll_files = p.pollfile_set.all() len_pf = len(poll_files) more_pics = None # check the files first # do single or more picture logic if len_pf > 0: more_pics = 1 if len_pf > 1: more_pics = 2 for pf in poll_files: if pf.main_file == True: # set main thumbnail if selected file = pf.file if file == None: file = poll_files[0].file # get the tags tags = p.tags.all() # store the link domain domain = urlparse(p.link) # check if the REQUEST user has voted voted = False watching = False if request_user and request_user.is_authenticated(): count = p.pollvote_set.filter(user=request_user).count() if count > 0: voted = True rqst_us = UserService(user=request_user).getUserData() if rqst_us.polls_watched.filter(poll=p).count() > 0: watching = True # store it all on the super tuple # gets unpacked in the lister icons = False if p.link or more_pics or p.video_link: icons = True poll_user_data = UserService(p.user).getUserData() results = self.get_poll_results(p, drop_zero_results=True) gcf = GChartFactory() gchart = gcf.get_chart(results, 125, 125) pollhash = {} pollhash['poll'] = p pollhash['file'] = file pollhash['more_pics'] = more_pics pollhash['tags'] = tags pollhash['domain'] = domain pollhash['voted'] = voted pollhash['icons'] = icons pollhash['poll_user_data'] = poll_user_data pollhash['watching'] = watching if p.total_votes > 0: pollhash['chart_url'] = gchart.get_url() else: pollhash[ 'chart_url'] = '/i/icons/chart_ph%d.png' % random.randint( 1, 3) aug_polls.append(pollhash) #aug_polls.append((p, file, more_pics, tags, domain[1], voted, icons, poll_user_data, watching)) pollListerHash["polls"] = aug_polls return pollListerHash
def getPollsForLister(self, polls=None, user=None, page_num=1, page_link_prefix=""): """ @param user: ALWAYS the request.user given a list of poll objects, this will return a hash with a list of tuples with the following order { "paginator":paginator object, "polls":[(poll, file, tags), ...] } This badboy also returns some major paging shit!!!!! """ if polls == None: return None request_user = user pollListerHash = {} paged_polls = Paginator(polls, consts.POLL_LISTER_RPP) pollListerHash["paginator"] = paged_polls pollListerHash["total"] = len(polls) polls_page = paged_polls.page(page_num) page_hash = paging_utils.setup_page_hash(paginator=paged_polls, page_num=page_num, page_link_prefix=page_link_prefix) pollListerHash.update(page_hash) polls = polls_page.object_list aug_polls = [] # go over db polls for p in polls: file = None poll_files = p.pollfile_set.all() len_pf = len(poll_files) more_pics = None # check the files first # do single or more picture logic if len_pf > 0: more_pics = 1 if len_pf > 1: more_pics = 2 for pf in poll_files: if pf.main_file == True: # set main thumbnail if selected file = pf.file if file == None: file = poll_files[0].file # get the tags tags = p.tags.all() # store the link domain domain = urlparse(p.link) # check if the REQUEST user has voted voted=False watching = False if request_user and request_user.is_authenticated(): count = p.pollvote_set.filter(user=request_user).count() if count > 0: voted=True rqst_us = UserService(user=request_user).getUserData() if rqst_us.polls_watched.filter(poll=p).count() > 0: watching = True # store it all on the super tuple # gets unpacked in the lister icons = False if p.link or more_pics or p.video_link: icons = True poll_user_data = UserService(p.user).getUserData() results = self.get_poll_results(p, drop_zero_results=True) gcf = GChartFactory() gchart = gcf.get_chart(results, 125, 125) pollhash = {} pollhash['poll'] = p pollhash['file'] = file pollhash['more_pics'] = more_pics pollhash['tags'] = tags pollhash['domain'] = domain pollhash['voted'] = voted pollhash['icons'] = icons pollhash['poll_user_data'] = poll_user_data pollhash['watching'] = watching if p.total_votes > 0: pollhash['chart_url'] = gchart.get_url() else: pollhash['chart_url'] = '/i/icons/chart_ph%d.png' % random.randint(1,3) aug_polls.append(pollhash) #aug_polls.append((p, file, more_pics, tags, domain[1], voted, icons, poll_user_data, watching)) pollListerHash["polls"] = aug_polls return pollListerHash