Example #1
0
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'

        ogl = OilGasLease()
        ogl.bookPage = '12/345'
        ogl.county = 'Custer'

        t = Tract()
        t.sec = '01'
        t.twn = '02N'
        t.rng = '03W'

        #ez = EzTest(id=1)
        #ez.sprop = 'a string'
        #ez.iprop = 1
        #ez.put()

        ogl.put()
        t.oilGasLease = ogl
        t.put()

        outputString = 'a tract: ' + t.secTwnRng() + '\n' + 'a lease: ' + str(
            ogl)

        self.response.out.write(outputString)
Example #2
0
 def LoadTract(self, data, request):
     type = request.get('datatype')
     oglID = request.get('oglID')
     if type == 'csv':
         if data != None:
             tracts = Tract.FromCSVFile(data.file)
             for tract in tracts:
                 tract.put()
     elif type == 'json':
         if data != None:
             lease = OilGasLease.get_by_key_name(oglID)
             if lease:
                 tract = Tract.FromJSON(data)
                 tract.oilGasLease = lease
                 if tract:
                     tract.put()
             else:
                 raise LeaseMissingLoadError(oglID)
Example #3
0
 def DeleteAll(self):
     print "DELETED!"
     db.delete(OilGasLease.all())
     db.delete(DocImage.all())
     db.delete(Tract.all())
         
     query = blobstore.BlobInfo.all()
     blobs = query.fetch(400)
     if len(blobs) > 0:
         for blob in blobs:
             blob.delete()
Example #4
0
    def DeleteAll(self):
        print "DELETED!"
        db.delete(OilGasLease.all())
        db.delete(DocImage.all())
        db.delete(Tract.all())

        query = blobstore.BlobInfo.all()
        blobs = query.fetch(400)
        if len(blobs) > 0:
            for blob in blobs:
                blob.delete()
Example #5
0
 def get(self):
     self.response.headers['Content-Type'] = 'text/plain'
     
     ogl = OilGasLease()
     ogl.bookPage = '12/345'
     ogl.county = 'Custer'
     
     t = Tract()
     t.sec = '01'
     t.twn = '02N'
     t.rng = '03W'
     
     #ez = EzTest(id=1)        
     #ez.sprop = 'a string'
     #ez.iprop = 1
     #ez.put()
     
     ogl.put()
     t.oilGasLease = ogl
     t.put()
     
     outputString = 'a tract: ' + t.secTwnRng() + '\n' + 'a lease: ' + str(ogl)
     
     self.response.out.write(outputString)
Example #6
0
def CreateZipFile(date, zipFileKey):

    #leases = OilGasLease.all().filter("date >", date)
    try:
        zipFileModel = ZipFileModel.get(db.Key(zipFileKey))
        zipFileModel.status = 'running'
        zipFileModel.put()

        stream = StringIO.StringIO()
        zipFile = zipfile.ZipFile(stream,
                                  'w',
                                  compression=zipfile.ZIP_DEFLATED)

        leases = OilGasLease.all()

        if date:
            leases = leases.filter('date >', date)

        s = OilGasLease.ToCsv(leases)
        zipFile.writestr("OilGasLease.csv", s.getvalue())

        tracts = list()
        tempFiles = list()
        count = 0
        try:
            for lease in leases:
                tracts.extend(lease.Tracts)
                if count % 100 == 0:
                    zipFileModel.status = str(count)
                    zipFileModel.put()
                count += 1

        except db.Timeout:
            leases = OilGasLease.all()
            if date:
                leases = leases.filter('date >', date)

            for lease in leases.run(offset=count):
                tracts.extend(lease.Tracts)
                if csvOnly == False:
                    DocImage.WriteToZip(lease.Images, zipFile)

                if count % 100 == 0:
                    zipFileModel.status = str(count)
                    zipFileModel.put()
                count += 1

        zipFileModel.status = 'writing Tract data to zipfile'
        zipFileModel.put()
        s = Tract.ToCsv(tracts)
        zipFile.writestr("Tracts.csv", s.getvalue())
        zipFile.close()

        blob = files.blobstore.create(
            mime_type='application/zip',
            _blobinfo_uploaded_filename='LandStreamData.zip')

        zipFileModel.status = 'writing zip file to blobstore'
        zipFileModel.put()
        with files.open(blob, 'a') as f:
            stream.seek(0)
            while True:
                buf = stream.read(2048)
                if buf == "":
                    break
                f.write(buf)

        files.finalize(blob)
        zipFileModel.blob = files.blobstore.get_blob_key(blob)
        zipFileModel.status = 'done'
        zipFileModel.put()
    except Exception, detail:
        zipFileModel.status = repr(detail)
        zipFileModel.put()