def OnAddTag( self, event ): bl = Server(self.URL)[BLOG] p = Post.load(bl, self.blogpost) tags = [ str(x.key) for x in bl.view("all/tags", group = True) if str(x.key) not in map(str,p.tags) ] if tags: dialog = wx.SingleChoiceDialog(None, "Choose a Tag or press Cancel to type it", "Tags", tags) tag = "" if dialog.ShowModal() == wx.ID_OK: tag = dialog.GetStringSelection() else: tag = wx.GetTextFromUser( "Type a Tag ", "Tag") if tag: tag = tag.upper() dialog.Destroy() if tag: bl = Server(self.URL)[BLOG] p = Post.load(bl, self.blogpost) tagList = p.tags tagList.append(tag) tagList = list(set(tagList)) tagList.sort() p.tags = tagList p.store(bl) #event = wx.CommandEvent( wx.wxEVT_COMMAND_LIST_ITEM_SELECTED, self.list.GetId()) #self.GetEventHandler().ProcessEvent( event ) self.OnLCtrl(None)
def isuserp(self, user, pw): db = Server("http://localhost:8888/")['unit_tasks'] if len( list( db.view('_design/users/isvalid', key=[user, self.hash(pw)]))) == 1: return "1" return "0"
def OnAttachments( self, event): bl = Server(self.URL)[BLOG] view = "attachments" attachmentsview= bl.view("all/{0}".format(view)) attachments = [] attachment_doc_ids = [] for doc in attachmentsview: attachments.append("{0} - {1}".format(doc.key, doc.value[1])) attachment_doc_ids.append( doc.value[0]) if len(attachments) > 0: dialog = wx.SingleChoiceDialog(None, "Choose an attachment", "Attachments", attachments) attachment = "" if dialog.ShowModal() == wx.ID_OK: attachment = dialog.GetStringSelection() docid = attachment_doc_ids[dialog.GetSelection()] dialog.Destroy()
def BuildListCtrl(self): """ Getting information from a couchdb database using a view and populating a wx.ListCtrl """ if not self.user.username: return try: self.list self.list.ClearAll() except: pass title = "BlogId Date Author Subject" for i, colTitle in enumerate(title.split(" ")): self.list.InsertColumn(i, colTitle) bl = Server(self.URL)[BLOG] posts = [] view = "by_date" bg1 = wx.Colour(239,235,239) bg2 = wx.Colour(255, 207,99) bg3 = wx.Colour(0xCC,0xFF,0xFF) blogview = bl.view("all/{0}".format(view), descending = True) for doc in blogview: index = self.list.InsertStringItem(sys.maxint, doc.value["_id"]) bgcolor = bg1 if index % 2 == 0: bgcolor = bg2 try: if self.tag != "GENERAL" and self.tag in doc.value["tags"]: bgcolor = bg3 except: pass self.list.SetItemBackgroundColour( index , bgcolor ) self.list.SetStringItem( index, 1, doc.value["date"]) self.list.SetStringItem( index, 2, doc.value["author"]) self.list.SetStringItem( index, 3, doc.value["subject"]) for i in range(4): self.list.SetColumnWidth(i, wx.LIST_AUTOSIZE) self.Refresh()
def OnTags( self, event): bl = Server(self.URL)[BLOG] tags = [ x.key for x in bl.view("all/tags", group = True)] if tags: default_value = "GENERAL" try: default_value = self.tag except: pass dialog = wx.SingleChoiceDialog(None, "Choose a Tag", "Tags", tags) try: dialog.SetSelection(tags.index( default_value )) except: pass if dialog.ShowModal() == wx.ID_OK: self.tag = dialog.GetStringSelection() self.BuildListCtrl() dialog.Destroy()
def OnAuthors( self, event): bl = Server(self.URL)[BLOG] view = "by_author" by_author_view = bl.view("all/{0}".format(view)) authors = [] for doc in by_author_view: authors.append( doc.key ) authors = list(set(authors)) authors.sort() if len(authors) > 0: dialog = wx.SingleChoiceDialog(None, "Choose an author", "Authors", authors) author = "" if dialog.ShowModal() == wx.ID_OK: author = dialog.GetStringSelection() dialog.Destroy() try: self.author = author self.BuildListCtrl() except: pass
def isuserp(self, user, pw): db = Server("http://localhost:8888/")['unit_tasks'] if len(list(db.view('_design/users/isvalid', key=[user, self.hash(pw)]))) == 1: return "1" return "0"