示例#1
0
    def _processEntity(self, entity):
        key_name = entity.key().name()
        parent = entity.scope
        properties = {
            'abstract': entity.abstract,
            'additional_info': entity.additional_info,
            'content': entity.content,
            'created_on': entity.created_on,
            'is_publicly_visible': entity.is_publicly_visible,
            'last_modified_on': entity.last_modified_on,
            'mentor': entity.mentor,
            'org': entity.org,
            'possible_mentors': entity.possible_mentors,
            'program': entity.program,
            'status': entity.status,
            'title': entity.title,
        }

        # check if the proposal has already been processed
        # this is a heristic, but we can assume that one student can't submit two
        # proposals at the very same time
        query = db.Query(GSoCProposal)
        query.ancestor(entity.scope)
        query.filter('created_on = ', entity.created_on)
        if query.get():
            return

        # create a new GSoCProposal entity
        proposal = GSoCProposal(parent=parent, **properties)
        proposal.put()

        to_put = []
        # convert all the comments for the old proposal
        query = db.Query(Review)
        query.filter('scope = ', entity)
        for comment in query:
            # get profile instance
            q = db.Query(GSoCProfile)
            q.ancestor(comment.author)
            q.filter('scope =', entity.program)
            author = q.get()

            if not author:
                # if, for some reason, there is no profile, we skip this comment
                import logging
                logging.warning('No profile for user %s.' %
                                (comment.author.link_id))
                continue

            properties = {
                'author': author,
                'content': comment.content,
                'is_private': not comment.is_public,
                'created': comment.created
            }
            new_comment = GSoCComment(parent=proposal, **properties)
            to_put.append(new_comment)

        db.run_in_transaction(db.put, to_put)