def processSubmission(user_id, user_name, submission_key):
    # update summary
    submission = submission_key.get()
    summary = SurveySubmissionSummary.get_or_insert("%s" % submission.year, parent=submission.survey)
    recordSubmission(summary.key, submission)

    # create dog ownership if needed
    roles = DogOwnerRole.gql("WHERE role = :1 AND dog = :2 AND user_id = :3 AND valid = true", "dog_owner", submission.koira, user_id)
    if roles.count() == 0:
        role = DogOwnerRole(user_id=user_id, role="dog_owner", 
                            owner_name=user_name, dog=submission.koira, valid=False)
        role.put()
        submission.owner_confirmed = False
    else:
        submission.owner_confirmed = True
        submission.Put()
Esempio n. 2
0
            self.request.set_status(401)

Role.collectionHandler(RoleCollectionHandler)

class DogOwnerRoleCollectionHandler (HardenedHandler):
    def get_(self, user):
        if users.is_current_user_admin():
            if self.request.params.has_key('valid'):
                self.genericGetCollection(ndb.gql("SELECT __key__ FROM DogOwnerRole WHERE valid=:1", self.request.params['valid'] == 'true'), "==> %s")
            else:
                self.genericGetCollection(ndb.gql("SELECT __key__ FROM DogOwnerRole"))
        else:
            self.request.set_status(401)


DogOwnerRole.collectionHandler(DogOwnerRoleCollectionHandler)

class DogOwnerRoleIndividualHandler (HardenedHandler):
    def get_(self, user, key):
        if users.is_current_user_admin():
            self.genericIndividualGet(user, key)
        else:
            self.request.set_status(401)

    def post_(self, user, key):
        if users.is_current_user_admin():
            entity = ndb.Key(urlsafe=key).get()
            if entity:
                was_valid = entity.valid
                entity.populateFromRequest(self.request.Params)
                if entity.valid and not was_valid: