def _populateServerEntry(self, zserverBlogEntry, zblog, zblogDocument,
                             zxhtmlDocument, zpubinfo):
        # Populate a ZServerBlogEntry given raven pubmeta data and post content.
        # Note: zpubinfo is valid only when updating existing post. It is None when posting new entry.
        pubmetadata = self._getPubMetaData(zblog, zblogDocument)
        title = zblogDocument.getTitle()
        content = self._transformContentForPublishing(zblog, zxhtmlDocument)

        zserverBlogEntry.setTitle(title)
        zserverBlogEntry.setContent(content)
        pubSchemaDT = pubmetadata.getPublishTime()

        # set pub time.
        if pubSchemaDT:
            # if user has specified a pub datetime, then use it.
            zserverBlogEntry.setUtcDateTime(
                pubSchemaDT.getDateTime())  # getDateTime
        elif zpubinfo:
            # if updating existing post, then use the previouslty published time
            publishedSchemaDt = zpubinfo.getPublishedTime()
            zserverBlogEntry.setUtcDateTime(publishedSchemaDt.getDateTime())
        else:
            # default to current time.
            nowDT = getCurrentUtcDateTime()
            zserverBlogEntry.setUtcDateTime(nowDT)

        zserverBlogEntry.setDraft(pubmetadata.isPublishAsDraft())
        for ravenCat in pubmetadata.getCategories():
            serverCatId = self._getServerId(ravenCat.getId())
            serverCat = ZServerBlogCategory(serverCatId, ravenCat.getName())
            self._copyAttrsFromRavenToServer(ravenCat, serverCat)
            zserverBlogEntry.addCategory(serverCat)

        # zblogDocument::getTagwordsList() -> list of ZTagwords (a ZTagwords is a list of words per site e.g. Technorati)
        listOfWords = getWordListFromZTagwords(zblogDocument.getTagwordsList())
        zserverBlogEntry.setTagwords(listOfWords)

        # custom meta data. (WP slug, password and post status
        slug = getCustomWPMetaDataAttribute(pubmetadata,
                                            u"wp_slug")  #$NON-NLS-1$
        if slug is not None:
            zserverBlogEntry.setAttribute(
                u"wp_slug", slug,
                IZBlogPubAttrNamespaces.WP_ATTR_NAMESPACE)  #$NON-NLS-1$
        status = getNoneString(
            getCustomWPMetaDataAttribute(pubmetadata,
                                         u"post_status"))  #$NON-NLS-1$
        if status:
            zserverBlogEntry.setAttribute(
                u"post_status", status,
                IZBlogPubAttrNamespaces.WP_ATTR_NAMESPACE)  #$NON-NLS-1$
        pw = getSafeString(
            getCustomWPMetaDataAttribute(pubmetadata,
                                         u"wp_password"))  #$NON-NLS-1$
        zserverBlogEntry.setAttribute(
            u"wp_password", pw,
            IZBlogPubAttrNamespaces.WP_ATTR_NAMESPACE)  #$NON-NLS-1$

        return zserverBlogEntry
Example #2
0
    def _fromRpcDateTime(self, rpcDateTimeStr):
        u"""Converts the xml rpc date time string to datetime.datetime object."""  #$NON-NLS-1$
        # eg: 20050417T09:57:06  (Wordpress - it does not have time zone though it returns zulu time)
        # eg: 2005-07-29T01:47:13Z (Typepad)
        # eg: 2005-03-25T01:21:54Z (another Typepad for 2005-03-24T20:21:54-05:00 local time))

        # FIXME (PJ) use params to figure out if the dateformat needs to be overridden and handle cases where incoming time is in local tz (eg LiveJournal)
        schemaDateTime = dateutil.getIso8601Date(toUnicode(rpcDateTimeStr))
        if schemaDateTime:
            return schemaDateTime.getDateTime()
        else:
            return getCurrentUtcDateTime()
Example #3
0
    def _fromRpcDateTime(self, rpcDateTimeStr):
        u"""Converts the xml rpc date time string to datetime.datetime object.""" #$NON-NLS-1$
        # eg: 20050417T09:57:06  (Wordpress - it does not have time zone though it returns zulu time)
        # eg: 2005-07-29T01:47:13Z (Typepad)
        # eg: 2005-03-25T01:21:54Z (another Typepad for 2005-03-24T20:21:54-05:00 local time))

        # FIXME (PJ) use params to figure out if the dateformat needs to be overridden and handle cases where incoming time is in local tz (eg LiveJournal)
        schemaDateTime = dateutil.getIso8601Date( toUnicode(rpcDateTimeStr) )
        if schemaDateTime:
            return schemaDateTime.getDateTime()
        else:
            return getCurrentUtcDateTime()
Example #4
0
    def __init__(self, date = None):
        param = date
        if not date:
            param = getCurrentUtcDateTime()

        if isinstance(param, str) or isinstance(param, unicode):
            self._initFromString(param)
        elif isinstance(param, long) or isinstance(param, int):
            self._initFromLongMs(param)
        elif isinstance(param, datetime):
            self.dateTime = convertToUtcDateTime(param)
        else:
            raise ZException(_extstr(u"schematypes.SchemaDateTimeFormatError")) #$NON-NLS-1$
Example #5
0
 def __init__(self, id = None):
     ZServerBase.__init__(self, id)
     self.url = None
     self.title = None
     self.rawContent = None
     self.content = None
     self.summary = None
     self.utcDateTime = getCurrentUtcDateTime() # utc date time.
     self.draft = False
     self.categories = []
     self.tagwords = []
     self.tagspaceUrl = None
     self.author = None
     self.convertNewLines = False
Example #6
0
    def __init__(self, date=None):
        param = date
        if not date:
            param = getCurrentUtcDateTime()

        if isinstance(param, str) or isinstance(param, unicode):
            self._initFromString(param)
        elif isinstance(param, long) or isinstance(param, int):
            self._initFromLongMs(param)
        elif isinstance(param, datetime):
            self.dateTime = convertToUtcDateTime(param)
        else:
            raise ZException(_extstr(
                u"schematypes.SchemaDateTimeFormatError"))  #$NON-NLS-1$
    def _populateServerEntry(self, zserverBlogEntry, zblog, zblogDocument, zxhtmlDocument, zpubinfo):
        # Populate a ZServerBlogEntry given raven pubmeta data and post content.
        # Note: zpubinfo is valid only when updating existing post. It is None when posting new entry.
        pubmetadata = self._getPubMetaData(zblog, zblogDocument)
        title = zblogDocument.getTitle()
        content = self._transformContentForPublishing(zblog, zxhtmlDocument)
        # ----
        # print "DEBUG (blogpublisher:_populateServerEntry): ", content    # DEBUG: ChuahTC 2013-Sep-2
        # ----

        zserverBlogEntry.setTitle(title)
        zserverBlogEntry.setContent(content)
        pubSchemaDT = pubmetadata.getPublishTime()
        
        # set pub time.
        if pubSchemaDT:
            # if user has specified a pub datetime, then use it.
            zserverBlogEntry.setUtcDateTime( pubSchemaDT.getDateTime() ) # getDateTime
        elif zpubinfo:
            # if updating existing post, then use the previouslty published time
            publishedSchemaDt = zpubinfo.getPublishedTime()
            zserverBlogEntry.setUtcDateTime( publishedSchemaDt.getDateTime() )
        else:
            # default to current time.
            nowDT = getCurrentUtcDateTime()
            zserverBlogEntry.setUtcDateTime(nowDT)
        
        zserverBlogEntry.setDraft( pubmetadata.isPublishAsDraft() )
        for ravenCat in pubmetadata.getCategories():
            serverCatId = self._getServerId( ravenCat.getId() )
            serverCat = ZServerBlogCategory(serverCatId, ravenCat.getName())
            self._copyAttrsFromRavenToServer(ravenCat, serverCat)
            zserverBlogEntry.addCategory(serverCat)

        # zblogDocument::getTagwordsList() -> list of ZTagwords (a ZTagwords is a list of words per site e.g. Technorati)
        listOfWords = getWordListFromZTagwords(zblogDocument.getTagwordsList() )
        zserverBlogEntry.setTagwords(listOfWords)

        # custom meta data. (WP slug, password and post status
        slug = getCustomWPMetaDataAttribute(pubmetadata, u"wp_slug") #$NON-NLS-1$
        if slug is not None:
            zserverBlogEntry.setAttribute(u"wp_slug", slug, IZBlogPubAttrNamespaces.WP_ATTR_NAMESPACE) #$NON-NLS-1$
        status = getNoneString( getCustomWPMetaDataAttribute(pubmetadata, u"post_status") ) #$NON-NLS-1$
        if status:
            zserverBlogEntry.setAttribute(u"post_status", status, IZBlogPubAttrNamespaces.WP_ATTR_NAMESPACE) #$NON-NLS-1$
        pw = getSafeString( getCustomWPMetaDataAttribute(pubmetadata, u"wp_password") ) #$NON-NLS-1$
        zserverBlogEntry.setAttribute(u"wp_password", pw, IZBlogPubAttrNamespaces.WP_ATTR_NAMESPACE) #$NON-NLS-1$
            
        return zserverBlogEntry
Example #8
0
 def _parseISO8601Date(self, dateStr, dflt = None):
     u"Parses a date string formatted in extended ISO8601 date-time format (aka xsd:dateTime format)." #$NON-NLS-1$
     if dateStr:
         dateStr = dateStr.strip(u"\r\n")  #$NON-NLS-1$
         dateStr = dateStr.strip(u"\r")  #$NON-NLS-1$
         dateStr = dateStr.strip(u"\n")  #$NON-NLS-1$
     schemaDt = getIso8601Date(dateStr)
     rval = None
     if schemaDt:
         rval = schemaDt.getDateTime()
     if not schemaDt and dflt:
         rval = dflt
     elif not schemaDt:
         rval = getCurrentUtcDateTime()
     return rval
Example #9
0
 def setDate(self, dateTime = None):
     if not dateTime:
         dateTime = getCurrentUtcDateTime()
     schemaDt = ZSchemaDateTime(dateTime)
     dateTimeStr = str(schemaDt)
     self._setDateStr(dateTimeStr)