def get(self, slug): response = {} try: mp = MP.all().filter('slug =', slug)[0] response['mp'] = utils.mp_to_dict(mp) except: self.returnJSON(404, response) return self.query = MPVote.all().filter('mp_slug =', slug) self.filterQueryOnParam('question') self.filterQueryOnParam('selection') response['votes'] = [] for vote in self.query: d = db.to_dict(vote) d['question'] = utils.question_to_dict(vote.parent()) del d['mp_party'] del d['mp_constituency'] del d['mp_slug'] del d['mp_name'] response['votes'].append(d) response['total'] = len(response['votes']) self.returnJSON(200, response)
def get(self, id=None): key = '%s' % (id.strip()) logging.info('Request for MP %s', key) mp = MP.all().filter('aristotleid =', long(id)).get() if not mp: self.error(404) articles = helpers.cached(key, lambda:helpers.load_from_json_endpoint('http://content.guardianapis.com/search.json?q=%s' % (quote(mp.name))), 60*60) helpers.render_template(self, 'mp.html', {'mp':mp, 'articles':articles})
def get(self, slug): response = {} try: response['mp'] = db.to_dict(MP.all().filter('slug =', slug)[0]) response['mp']['vote_details'] = '/mps/%s/votes' % slug except: response['error'] = 'Cannot find mp' self.returnJSON(404, response) self.returnJSON(200, response)
def get(self): response = {'mps': []} self.query = MP.all() response['total'] = self.query.count() self.filterQueryOnParam('gender') self.filterQueryOnParam('party') response = self.addPagingFilters(response) for mp in self.query: u = db.to_dict(mp) u['details'] = '/mps/%s' % mp.slug response['mps'].append(u) self.returnJSON(200, response)
def get(self): response = { 'mps': [] } self.query = MP.all() response['total'] = self.query.count() self.filterQueryOnParam('gender') self.filterQueryOnParam('party') response = self.addPagingFilters(response) for mp in self.query: u = db.to_dict(mp) u['details'] = '/mps/%s' % mp.slug response['mps'].append(u) self.returnJSON(200, response)
def get(self): helpers.render_template(self, 'index.html', {'mps':MP.all()})