コード例 #1
0
ファイル: ToDo.py プロジェクト: philipjellis/Warehouse
    def loadss(self, event):
        def comparekey(header,correct):
            if header <> correct:
                return 'Column heading ' + header + ' should be ' + correct +'\n'
            return ''

        dialog = wx.FileDialog(None, "Choose a file", os.getcwd(),"","",wx.OPEN)
        if dialog.ShowModal() == wx.ID_OK:
            ssfil = dialog.GetPath()
            msg = ''
            try:
                xl_data = readXLList(ssfil)
            except:
                msg = 'To load multiple tasks from a spreadsheet, I need to see\n \
a simple spreadsheet with columns titled:\nClient\nProject\nOwner\nResponsible\nDescription\nDue.\n\n\
There is an example at l:\warehouse\jokenacoloadproject.xlsx.\n \
See Phil if you want more explanation.'
            if not msg:
                headers = xl_data[0].keys()
                correct_keys = ['Client', 'Project', 'TaskId', 'Owner', 'Responsible', 'Description', 'Due']
                proper_keys = ['Client', 'pProject', 'tTaskId', 'pOwner', 'tResponsible', 'tDescription', 'tDue']
                while len(headers) < len(correct_keys): # this and the next statement make sure we deal with too long or short headers ok
                    headers.append('')
                while len(correct_keys) < len(headers):
                    correct_keys.append('')
                for h,c in zip(headers,correct_keys):
                    msg += comparekey(h,c)
            if not msg: # then we are ok
                for rownum, row in enumerate(xl_data):
                    if row['Project'] not in self.projects():
                        if row['Owner'] in self.people():
                            self.new_proj(row['Client'],row['Project'],row['Owner'])
                        else:
                            msg += 'Bad owner ' + row['Owner'] + ' in line ' + str(rownum) + '\n'
                    if row['Responsible'] not in self.people():
                        msg += 'Bad responsible person ' + row['Responsible'] + ' in line ' + str(rownum) + '\n'
                    try:
                        row['Due'].year
                    except:
                        msg += 'Bad due date ' + str(row['Due']) + ' in line ' + str(rownum) + '\n'
                    msg += self.new_task(row)
            if msg:
                dlg = sm(self.parent,
                         msg,
                         'Errors in input spreadsheet', 
                         pos=wx.wx.DefaultPosition,
                         size=(500,300))
                retcode = dlg.ShowModal()
                dlg.Destroy()
                self.td_conn.rollback()
            else:
                rc = wx.MessageBox(str(rownum+1)+' rows inserted.' , 'Loaded Tasks', wx.OK | wx.ICON_INFORMATION)                
                self.td_conn.commit()
        dialog.Destroy()
コード例 #2
0
ファイル: ToDo - Copy.py プロジェクト: philipjellis/Warehouse
    def loadss(self, event):
        def comparekey(header, correct):
            if header <> correct:
                return "Column heading " + header + " should be " + correct + "\n"
            return ""

        dialog = wx.FileDialog(None, "Choose a file", os.getcwd(), "", "", wx.OPEN)
        if dialog.ShowModal() == wx.ID_OK:
            ssfil = dialog.GetPath()
            xl_data = readXLList(ssfil)
            headers = xl_data[0].keys()
            correct_keys = ["Client", "Project" "TaskId", "Owner", "Responsible", "Description", "Due"]
            proper_keys = ["Client", "pProject" "tTaskId", "pOwner", "tResponsible", "tDescription", "tDue"]
            msg = ""
            while len(headers) < len(
                correct_keys
            ):  # this and the next statement make sure we deal with too long or short headers ok
                headers.append("")
            while len(correct_keys) < len(headers):
                correct_keys.append("")
            for h, c in zip(headers, correct_keys):
                msg += comparekey(h, c)
            if not msg:  # then we are ok
                for rownum, row in enumerate(xl_data):
                    if row["Project"] not in self.projects():
                        if row["Owner"] in self.people():
                            self.new_proj(row["Client"], row["Project"], row["Owner"])
                        else:
                            msg += "Bad owner " + row["Owner"] + " in line " + str(rownum) + "\n"
                    if row["Responsible"] not in self.people():
                        msg += "Bad responsible person " + row["Responsible"] + " in line " + str(rownum) + "\n"
                    try:
                        row["Due"].year
                    except:
                        msg += "Bad due date " + str(row["Due"]) + " in line " + str(rownum) + "\n"
                    if not msg:  # still ok
                        self.new_task(row)
            if msg:
                print msg
                dlg = sm(self.parent, msg, "Errors in input spreadsheet", pos=wx.wx.DefaultPosition, size=(500, 300))
                retcode = dlg.ShowModal()
                dlg.Destroy()
        dialog.Destroy()