当前位置: 首页>>代码示例>>Python>>正文


Python Conference.get_by_id方法代码示例

本文整理汇总了Python中models.Conference.get_by_id方法的典型用法代码示例。如果您正苦于以下问题:Python Conference.get_by_id方法的具体用法?Python Conference.get_by_id怎么用?Python Conference.get_by_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Conference的用法示例。


在下文中一共展示了Conference.get_by_id方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from models import Conference [as 别名]
# 或者: from models.Conference import get_by_id [as 别名]
 def get(self, confid, secret):
     """Download all speakers and proposals for a conference"""
     # Super-Reviewers
     committee = []
     if confid == 'droidcon-2016':
         committee = ['[email protected]',
                      '[email protected]']
     # 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))
开发者ID:GDGVienna,项目名称:cfp-manager,代码行数:62,代码来源:backup.py

示例2: post

# 需要导入模块: from models import Conference [as 别名]
# 或者: from models.Conference import get_by_id [as 别名]
 def post(self, confid):
     user = users.get_current_user()
     if not user:
         login_url = users.create_login_url(self.request.url)
         self.redirect(login_url)
         return
     # get the conference
     if confid.startswith('new:'):
         confid = confid[4:]
     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 proposal id & proposal
     proposal_id = long(self.request.get('proposal_id'))
     proposal = Proposal.get_by_id(id=proposal_id, parent=conference.key)
     if not proposal:
         self.response.out.write("No proposal found for this id (" +
                                 str(proposal_id) + ")")
         return
     # get existing review by this user
     review = Review.get_by_id(id=user.email(), parent=proposal.key)
     if not review:
         review = Review(id=user.email(), parent=proposal.key)
     # store value for the review
     review.comment = self.request.get('comment')
     if self.request.get('rating'):
         review.rating = int(self.request.get('rating'))
     # store in Data Store
     review.put()
     # redirect to get
     self.redirect(self.request.url)
开发者ID:GDGVienna,项目名称:cfp-manager,代码行数:35,代码来源:review.py

示例3: post

# 需要导入模块: from models import Conference [as 别名]
# 或者: from models.Conference import get_by_id [as 别名]
 def post(self, confid):
     """Accept proposals via POST requests"""
     # get parameters from request
     name = self.request.get("name")
     surname = self.request.get("surname")
     email = self.request.get("email")
     bio = self.request.get("bio")
     useOld = self.request.get("use-old")
     title = self.request.get("title")
     abstract = self.request.get("abstract")
     duration = int(self.request.get("duration"))
     comment = self.request.get("comment")
     # timestamp 'now'
     now = datetime.now()
     # search for conference
     conference = Conference.get_by_id(confid)
     if not conference:
         self.error("Conference not found", 404)
         return
     # search for speaker?
     speakerKey = None
     if useOld:
         # get speakers for email
         speakers = Speaker.query(Speaker.email == email)
         # and order by modified-date (reverse) to get the last one
         speakers = speakers.order(-Speaker.modified).iter()
         if speakers.has_next():
             speaker = speakers.next()
             speakerKey = speaker.key
     if not speakerKey:
         # create speaker object
         speaker = Speaker(name=name, surname=surname, email=email,
                           bio=bio, created=now, modified=now)
         speakerKey = speaker.put()
     # submit proposal
     proposal = Proposal(parent=conference.key, speaker=speakerKey,
                         abstract=abstract, duration=duration,
                         title=title, comment=comment, created=now,
                         modified=now)
     proposalKey = proposal.put()
     if proposalKey:
         self.success()
     else:
         self.error("Error when storing proposal", 500)
开发者ID:GDGVienna,项目名称:cfp-manager,代码行数:46,代码来源:proposal.py

示例4: get

# 需要导入模块: from models import Conference [as 别名]
# 或者: from models.Conference import get_by_id [as 别名]
 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))
开发者ID:GDGVienna,项目名称:cfp-manager,代码行数:44,代码来源:review.py

示例5: submitProposal

# 需要导入模块: from models import Conference [as 别名]
# 或者: from models.Conference import get_by_id [as 别名]
 def submitProposal(self, request):
     """Submit a new talk proposal"""
     if not request.title or not request.speaker:
         raise endpoints.BadRequestException(
             "Required field (title and/or speaker key) missing"
         )
     # get the speaker (check if it exists)
     speaker = ndb.Key(urlsafe=request.speaker).get()
     if not speaker:
         raise endpoints.BadRequestException(
             "Speaker entity not found"
         )
     if speaker.key.kind() != "Speaker":
         raise endpoints.BadRequestException(
             "Invalid key kind for speaker specified"
         )
     # get the conference (check if it exists)
     conf = Conference.get_by_id(request.conferenceId)
     if not conf:
         raise endpoints.BadRequestException(
             "Invalid conference identifier specified"
         )
     # TODO: check if call for papers is still open
     # fill the data structure for creating the entity
     data = {field.name: getattr(request, field.name)
             for field in request.all_fields()}
     # delete conference id, link to parent
     del data['conferenceId']
     data['parent'] = conf.key
     # update the speaker reference
     data['speaker'] = speaker.key
     # set the created date/time stamp
     data['created'] = datetime.now()
     data['modified'] = data['created']
     # store in Datastore - with correct parent
     proposalKey = Proposal(**data).put()
     # return value
     retVal = ProposalKeyForm()
     retVal.key = proposalKey.urlsafe()
     retVal.title = request.title
     return retVal
开发者ID:GDGVienna,项目名称:cfp-manager,代码行数:43,代码来源:manager.py

示例6: post

# 需要导入模块: from models import Conference [as 别名]
# 或者: from models.Conference import get_by_id [as 别名]
 def post(self, confid=''):
     user = users.get_current_user()
     if not user:
         login_url = users.create_login_url('/')
         self.redirect(login_url)
         return
     # check if the user is admin
     if not users.is_current_user_admin():
         self.response.out.write("You are not authorized")
         return
     # get conference
     if not confid:
         confid = self.request.get('id')
     conference = Conference.get_by_id(confid)
     if not conference:
         conference = Conference(id=confid)
     # update fields of the conference
     conference.name = self.request.get('name')
     conference.subtitle = self.request.get('subtitle')
     conference.reviewers = self.request.get('reviewers').split()
     # put the changes conference element
     conference.put()
     # redirect to the get page
     self.redirect(self.request.url)
开发者ID:GDGVienna,项目名称:cfp-manager,代码行数:26,代码来源:conference.py


注:本文中的models.Conference.get_by_id方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。