Exemplo n.º 1
0
    def set_form_contest(self):
        """sets the contest data """
        if self.contest_id:
            try:
                self.contest = db.get_contest(self.contest_id)
            except:
                log.error("Contest ID: {0} not found".format(self.contest_id))
                self.contest_id = ''
        elif self.contests:
            ##get first contest from first group
            if self.contest_groups and self.contest_groups[0]['contests']:
                self.contest = self.contest_groups[0]['contests'][0]
            else:
                self.contest = self.contests[0]

            if self.contest:
                self.contest_id = self.contest.id

        if self.contest:
            def get_decisions():
                return db.get_contest_decisions(self.contest)


            #eventually we got to only return only a page of opinions at a time,
            #but we don't have a real database yet so we have to do our summaries manually in code

            #we don't want to cache for the demo we want results right away.
            # self.contest.decisions = helpers.get_cache(cache, 'all_decisions_{0}'.format(self.contest.id),
            #                                             get_decisions, 300)

            self.contest.decisions = get_decisions()



            self.all_opinions = self.contest.get_all_opinions()
            self.official_opinions = self.contest.get_official_opinions()
            self.all_opinion_summary = Opinion.get_opinion_summary(
                self.all_opinions, self.contest.contestants,self.contest.decision_type, self.contest.allow_write_ins)
            self.official_opinion_summary = Opinion.get_opinion_summary(
                self.official_opinions, self.contest.contestants,
                self.contest.decision_type, self.contest.allow_write_ins)
Exemplo n.º 2
0
def make_request(payload):
    """Makes a request using the configuration specified in settings.py, and 
    the payload that has been passed in"""

    log.info("make_request\n{0}\n{1}".format(settings.API_URL,
                                               payload['method']))

    # log.debug("make_request\n{0}\n{1}".format(settings.API_URL,
    #                                             json.dumps(payload)))

    response = requests.post(settings.API_URL,
                             data=json.dumps(payload),
                             headers={"content-type": "application/json"},
                             auth=(settings.API_USER, settings.API_PASS))

    #log.debug(response.content)
    response_json = response.json()

    if 'error' in response_json:
        log.error(response_json['error'])

    return response_json