コード例 #1
0
    def post(self):
        applicant = self.user
        application_key = applicant.application
        application = application_key.get()

        if application.submit_time != None:
            logging.info('Attempt to upload file to submitted application by %s', applicant.email)
            self.abort(423)
            return

        if len(application.other_materials) >= 3:
            self.abort(403)
            return

        upload_files = self.get_uploads('other-material')
        if len(application.other_materials) + len(upload_files) > 3:
            for stopped_upload_file in upload_files[5-len(application.advocacy_materials):]:
                stopped_upload_file.delete()
            upload_files = upload_files[0: 3-len(application.other_materials)]

        for blob_info in upload_files:
            application.other_materials.append(blob_info.key())
        application.put()

        response = []
        for blob_info in upload_files:
            response.append('{"key": "%s", "filename": "%s", "content_type": "%s", "size": "%s"}' % (blob_info.key(), blob_info.filename, blob_info.content_type, byteConversion(blob_info.size)))
        self.response.headers['Content-Type'] = 'application/json'
        self.response.write(json.dumps(response))
コード例 #2
0
    def post(self):
        applicant = self.user
        application_key = applicant.application
        application = application_key.get()

        if application.submit_time != None:
            logging.info('Attempt to upload advocacy material to submitted application by %s', applicant.email)
            self.response.write('<script language="javascript" type="text/javascript">window.top.window.finishUpload(0);</script>')
            return

        if len(application.advocacy_materials) >= 5:
            self.response.write('<script language="javascript" type="text/javascript">window.top.window.finishUpload(1);</script>')
            return

        upload_files = self.get_uploads('advocacy-material')
        if len(application.advocacy_materials) + len(upload_files) > 5:
            for stopped_upload_file in upload_files[5-len(application.advocacy_materials):]:
                stopped_upload_file.delete()
            upload_files = upload_files[0: 5-len(application.advocacy_materials)]

        try:
            for blob_info in upload_files:
                application.advocacy_materials.append(blob_info.key())
            application.put()

            self.response.write('<script language="javascript" type="text/javascript">window.top.window.finishUpload(')
            response = []
            for blob_info in upload_files:
                response.append('{"key": "%s", "filename": "%s", "content_type": "%s", "size": "%s"}' % (blob_info.key(), blob_info.filename, blob_info.content_type, byteConversion(blob_info.size)))
            self.response.write(json.dumps(response))
            self.response.write(');</script>')
        except Exception, e:
            logging.error("Error with uploading: %s" % e)
            self.response.clear()
            self.response.write('<script language="javascript" type="text/javascript">window.top.window.finishUpload(0);</script>')