Пример #1
0
 def get(self, confid, secret):
     """Download all speakers and proposals for a conference"""
     # Super-Reviewers
     committee = []
     if confid == 'droidcon-2016':
         committee = ['*****@*****.**',
                      '*****@*****.**']
     # get conference
     conference = Conference.get_by_id(confid)
     # check if the provided secret is correct
     if conference.secret != secret:
         self.response.http_status_message(403)
         return
     speakers = Speaker.query()
     proposals = Proposal.query(ancestor=conference.key)
     reviews = Review.query()
     speakers_dict = [dict(s.to_dict(), **dict(id=s.key.id()))
                      for s in speakers]
     proposals_dict = []
     # create a fast lookup table - reviews by parent
     reviews_by_parent = {}
     for r in reviews:
         parent = r.key.parent()
         rlist = reviews_by_parent[parent]
         if rlist is None:
             rlist = []
         rlist.append(r)
         reviews_by_parent[parent] = rlist
     # crete a fast lookup table - speaker by key
     speakers_by_id = {}
     for s in speakers:
         speakers_by_key[s.key] = s
     for p in proposals:
         p_dict = p.to_dict()
         p_dict['id'] = p.key.id()
         p_r = {}
         p_sum = 0
         for r in reviews_by_parent[p.key]:
             p_r[r.key.id()] = r.to_dict()
             if r.rating:
                 if r.key.id() in committee:
                     # double the rating!
                     p_sum = p_sum + r.rating
                 p_sum = p_sum + r.rating
         s = speakers_by_key[p.speaker]
         if s is not None:
             p_dict['speaker-email'] = s.email
             p_dict['speaker-name'] = s.name
             p_dict['speaker-surname'] = s.surname
             if s.rating:
                 p_sum = p_sum + s.rating
         p_dict['reviews'] = p_r
         p_dict['rating'] = p_sum
         proposals_dict.append(p_dict)
     self.response.headers['Content-Type'] = 'application/json'
     obj = {
         'speakers': speakers_dict,
         'proposals': proposals_dict,
     }
     self.response.out.write(json.dumps(obj, cls=DatastoreEncoder))
Пример #2
0
 def get(self, confid):
     user = users.get_current_user()
     if not user:
         login_url = users.create_login_url(self.request.url)
         self.redirect(login_url)
         return
     new_only = confid.startswith('new:')
     if new_only:
         confid = confid[4:]
     # get the conference
     conference = Conference.get_by_id(confid)
     # check if the user is an admin
     if user.email() not in conference.reviewers:
         self.response.out.write("You are not authorized")
         return
     # get existing proposals
     proposals = Proposal.query(ancestor=conference.key).fetch()
     # get existing reviews
     reviews = Review.query(ancestor=conference.key).fetch()
     # filter by this users
     reviews = [r for r in reviews if r.key.id() == user.email()]
     proposals_reviewed = []
     # add the review to the matching proposal
     for r in reviews:
         for p in proposals:
             if r.key.parent() == p.key:
                 p.review = r
                 proposals_reviewed.append(p.key)
     if new_only:
         proposals = [p for p in proposals
                      if p.key not in proposals_reviewed]
     # set of stuff to display in the template
     template_values = {
         'user': user,
         'logout_url': users.create_logout_url(self.request.url),
         'conference': conference,
         'proposals': proposals,
         'reviews': reviews,
     }
     # display template with the reviews & proposals
     template = JINJA_ENVIRONMENT.get_template('review.html')
     self.response.write(template.render(template_values))