Exemple #1
0
  def from_metaweblog(cls,struct,post_type='post',is_edit=False):
    """Receive metaWeblog RPC struct and initialize a Post.
        Used both by migrate_from_wordpress and when receiving a new or
        edited post from MarsEdit.
    """
    title = struct.get('title','')
    meta_description = struct.get('mt_excerpt','')
    if len(meta_description) > 155:
      raise ValueError(
        "Description is %d chars, max 155" % len(meta_description))

    if 'mt_keywords' in struct:
      tags = [
        tag.strip() for tag in struct['mt_keywords'].split(',')
        if tag.strip()]
    else:
      tags = None

    slug = (
      slugify.slugify(struct['wp_slug'])
      if struct.get('wp_slug')
      else slugify.slugify(title))

    print struct.get('wp_slug') , slugify.slugify(title)

    description = struct.get('description','')
    status = (struct.get('post_status')
        or struct.get('page_status')
        or 'publish')

    if 'date_modified_gmt' in struct:
      tup = struct['date_modified_gmt'].timetuple()
      mod = utc_tz.localize(datetime.datetime(*tup[0:6]))
    else:
      mod = datetime.datetime.utcnow()

    body = markup.markup(description)

    rv = cls(
      title=title,
      #Format for display
      body=body,
      plain=plain.plain(body),
      summary=summarize.summarize(body,200),
      original=description,
      meta_description=meta_description,
      tags=tags,
      slug=slug,
      type=post_type,
      status=status,
      wordpress_id=struct.get('postid'),
      mod=mod
      )

    if not is_edit and 'date_created_gmt' in struct:
      #TODO: can fail if two posts created in same second,add random suffix to ObjectId
      date_created = datetime.datetime.strptime(
        struct['date_created_gmt'].value,'%Y%m%dT%H:%M:%S')
      rv.id = ObjectId.from_datetime(date_created)

    return rv
Exemple #2
0
  def _from_rpc(cls,struct,name):
    _id = ObjectId(struct['categoryId']) if 'categoryId' in struct else None

    return cls(name=name,slug=slugify.slugify(name),id=_id)