コード例 #1
0
    def get(self, **kwargs):
        job = JobModel.get(kwargs['jobid']) 
        output = StringIO.StringIO()
        z = zipfile.ZipFile(output,'w')
        
        history = JobHistoryModel.all()
        history.filter("Job = ", job)
        items = ""
        for item in history: 
            username = item.CreatedBy.username
            items += item.Created.strftime("%b %d %Y - %I:%M%P") + "," + username +","+ item.Description+"\r\n"
        
        historycsv = StringIO.StringIO(items)
        z.writestr("history.csv", historycsv.read().encode('utf-8'))
        historycsv.close()
        
        communication = CommunicationModel.all()
        communication.filter("Job = ", job)
        items = ""
        for item in communication: 
            username = item.CreatedBy.username
            items += item.Created.strftime("%b %d %Y - %I:%M%P") + "," + username +","+ item.Text+"\r\n"
        
        commcsv = StringIO.StringIO(items)
        z.writestr("communication.csv", commcsv.read().encode('utf-8'))
        commcsv.close()

        artifacts = job.Artifacts
        items = ""
        for item in artifacts:
            file = blobstore.get(item)
            items += file.filename+"\r\n"
        
        filescsv = StringIO.StringIO(items)
        z.writestr("files.csv", filescsv.read().encode('utf-8'))
        filescsv.close()
        
        items = ""
        items += "name, " + job.Nickname + "\r\n"
        items += "description, " + job.Description + "\r\n"
        items += "created, " + job.Created.strftime("%b %d %Y - %I:%M%P") + "\r\n"
        items += "created by, " + job.CreatedBy.username + "\r\n"
        items += "client, " + job.Client.Name + "\r\n"
        if job.Quote: 
            items += "quote, " + job.Quote + "\r\n"
        
        datacsv = StringIO.StringIO(items)
        z.writestr("data.csv", datacsv.read().encode('utf-8'))
        datacsv.close()
        
        z.close()
        
        response = Response(output.getvalue())
        response.headers["Content-Type"] = "multipart/x-zip"
        response.headers['Content-Disposition'] = "attachment; filename=" + job.JobNumber +".zip"
        
        return response
コード例 #2
0
    def get(self, **kwargs):
        job = JobModel.get(kwargs['jobid']) 

        blobstore.delete(job.Artifacts)
        job.Artifacts = []
        
        history = JobHistoryModel.all()
        history.filter("Job = ", job)
        for item in history:
            logging.log(logging.INFO, "deleted %s" % item.key())
            item.delete()
        
        communication = CommunicationModel.all()
        communication.filter("Job = ", job)
        for item in communication: 
            logging.log(logging.INFO, "deleted %s" % item.key())
            item.delete()

        job.delete()
        self.set_message('success', 'The job, files, and all related information were successfully cleared.', flash=True, life=5)
        return redirect_to('home')