コード例 #1
0
    def OnPublish(self, evt):
        # Publish the collection


        # Update the UI by disabling/hiding various panels, and swapping in a
        # new set of buttons
        self.mainPanel.Enable(False)
        self.buttonPanel.Hide()
        self.mySizer.Detach(self.buttonPanel)
        self.buttonPanel = self.resources.LoadPanel(self,
                                                    "PublishingButtonsPanel")
        self.mySizer.Add(self.buttonPanel, 0, wx.GROW|wx.ALL, 5)
        publishingButton = wx.xrc.XRCCTRL(self, "BUTTON_PUBLISHING")
        publishingButton.Enable(False)
        self.Bind(wx.EVT_BUTTON, self.OnPublishDone, id=wx.ID_CANCEL)

        self._clearStatus()
        self._resize()
        wx.Yield()

        try:

            # Populate the list of existing shares on the selected webdav server
            self.existing = self._getExistingFiles()
            suggestedName = self._suggestName()
            shareName = suggestedName
            shareNameSafe = urllib.quote_plus(shareName.encode('utf-8'))
            accountIndex = self.accountsControl.GetSelection()
            account = self.accountsControl.GetClientData(accountIndex)

            # Create the main share object
            shareXML = Sharing.newOutboundShare(self.view,
                                                self.collection,
                                                kinds=self.filterKinds,
                                                shareName=shareNameSafe,
                                                account=account)
            self.shareXML = shareXML
            shareXML.displayName = shareName
            self._saveAttributeFilterState(shareXML)

            # Create the secondary (.ics) share object
            iCalName = "%s.ics" % shareNameSafe
            shareICal = Sharing.newOutboundShare(self.view,
                                                 self.collection,
                                                 kinds=self.filterKinds,
                                                 shareName=iCalName,
                                                 account=account)
            self.shareICal = shareICal
            shareICal.displayName = "%s.ics" % shareName
            self._saveAttributeFilterState(shareICal)

            # For the .ics share, use ICalendarFormat instead
            format = ICalendar.ICalendarFormat(view=self.view)
            shareICal.mode = "put"
            shareICal.format = format
            shareICal.hidden = True

            self._showStatus("Wait for Sharing URLs...\n")
            if shareXML.exists():
                raise Sharing.SharingError("Share already exists")
            else:
                self._showStatus("Creating collection on server...")
                shareXML.create()
                self._showStatus(" done.\n")

            self._showStatus("Publishing collection to server...")
            shareXML.put()
            self._showStatus(" done.\n")

            self._showStatus("Publishing calendar file to server...")
            shareICal.put()
            self._showStatus(" done.\n")

        except (Sharing.SharingError, zanshin.error.Error), e:

            # Display the error
            # self._clearStatus()
            self._showStatus("\nSharing error:\n%s\n" % e.message)
            logger.exception("Failed to publish collection")
            # self._showStatus("Exception:\n%s" % traceback.format_exc(10))

            # Clean up all share objects we created
            try:
                shareXML.delete(True)
                shareICal.delete(True)
            except:
                pass

            # Re-enable the main panel and switch back to the "Share" button
            self.mainPanel.Enable(True)
            self.buttonPanel.Hide()
            self.mySizer.Detach(self.buttonPanel)
            self.buttonPanel = self.resources.LoadPanel(self,
                                                        "PublishButtonsPanel")
            self.mySizer.Add(self.buttonPanel, 0, wx.GROW|wx.ALL, 5)
            self.Bind(wx.EVT_BUTTON, self.OnPublish, id=wx.ID_OK)
            self.Bind(wx.EVT_BUTTON, self.OnCancel, id=wx.ID_CANCEL)
            self._resize()

            return
コード例 #2
0
    def onShareItemEvent (self, event):
        """
          Share an ItemCollection.
        """
        itemCollection = event.arguments ['item']

        # Make sure we have all the accounts; returns False if the user cancels
        # out and we don't.
        if not Sharing.ensureAccountSetUp(self.itsView):
            return
        webdavAccount = Sharing.getWebDAVAccount(self.itsView)

        # commit changes, since we'll be switching to Twisted thread
        # @@@DLD bug 1998 - update comment above and use refresh instead?
        self.RepositoryCommitWithStatus()

        # show status
        self.setStatusMessage (_("Sharing collection %s") % itemCollection.displayName)

        # Get or make a share for this item collection
        share = Sharing.getShare(itemCollection)
        isNewShare = share is None
        if isNewShare:
            share = Sharing.newOutboundShare(self.itsView,
                                             itemCollection,
                                             account=webdavAccount)

        # Copy the invitee list into the share's list. As we go, collect the 
        # addresses we'll notify.
        if len (itemCollection.invitees) == 0:
            self.setStatusMessage (_("No invitees!"))
            return
        inviteeList = []
        inviteeStringsList = []

        for invitee in itemCollection.invitees:
            inviteeList.append(invitee)
            inviteeStringsList.append(invitee.emailAddress)
            inviteeContact = Contact.getContactForEmailAddress(self.itsView, invitee.emailAddress)

            if not inviteeContact in share.sharees:
                share.sharees.append(inviteeContact)

        # Sync the collection with WebDAV
        self.setStatusMessage (_("accessing WebDAV server"))
        try:
            if not share.exists():
                share.create()
            share.put()

        except Sharing.SharingError, err:
            self.setStatusMessage (_("Sharing failed."))

            msg = "Couldn't share collection:\n%s" % err.message
            application.dialogs.Util.ok(wx.GetApp().mainFrame,
                                        "Error", msg)

            if isNewShare:
                share.conduit.delete()
                share.format.delete()
                share.delete()

            return