Ejemplo n.º 1
0
def gen_timestamped_slug(slug, content_type, pub_date=None):
    """Generate a timestamped slug, suitable for use as final URL path."""
    from rezine.application import get_application
    from rezine.i18n import to_blog_timezone
    cfg = get_application().cfg
    if pub_date is None:
        pub_date = datetime.utcnow()
    pub_date = to_blog_timezone(pub_date)

    prefix = cfg['blog_url_prefix'].strip(u'/')
    if prefix:
        prefix += u'/'

    if content_type == 'entry':
        fixed = cfg['fixed_url_date_digits']

        def handle_match(match):
            handler = _slug_parts.get(match.group(1))
            if handler is None:
                return match.group(0)
            return handler(pub_date, slug, fixed)

        full_slug = prefix + _placeholder_re.sub(handle_match,
                                                 cfg['post_url_format'])
    else:
        full_slug = u'%s%s' % (prefix, slug)
    return full_slug
Ejemplo n.º 2
0
def gen_timestamped_slug(slug, content_type, pub_date=None):
    """Generate a timestamped slug, suitable for use as final URL path."""
    from rezine.application import get_application
    from rezine.i18n import to_blog_timezone
    cfg = get_application().cfg
    if pub_date is None:
        pub_date = datetime.utcnow()
    pub_date = to_blog_timezone(pub_date)

    prefix = cfg['blog_url_prefix'].strip(u'/')
    if prefix:
        prefix += u'/'

    if content_type == 'entry':
        fixed = cfg['fixed_url_date_digits']
        def handle_match(match):
            handler = _slug_parts.get(match.group(1))
            if handler is None:
                return match.group(0)
            return handler(pub_date, slug, fixed)

        full_slug = prefix + _placeholder_re.sub(
            handle_match, cfg['post_url_format'])
    else:
        full_slug = u'%s%s' % (prefix, slug)
    return full_slug
Ejemplo n.º 3
0
    def set_auto_slug(self):
        """Generate a slug for this post."""
        #cfg = get_application().cfg
        slug = gen_slug(self.title)
        if not slug:
            slug = to_blog_timezone(self.pub_date).strftime('%H%M')

        full_slug = gen_timestamped_slug(slug, self.content_type, self.pub_date)

        if full_slug != self.slug:
            while Post.query.autoflush(False).filter_by(slug=full_slug) \
                      .limit(1).count():
                full_slug = increment_string(full_slug)
            self.slug = full_slug
Ejemplo n.º 4
0
    def set_auto_slug(self):
        """Generate a slug for this post."""
        #cfg = get_application().cfg
        slug = gen_slug(self.title)
        if not slug:
            slug = to_blog_timezone(self.pub_date).strftime('%H%M')

        full_slug = gen_timestamped_slug(slug, self.content_type,
                                         self.pub_date)

        if full_slug != self.slug:
            while Post.query.autoflush(False).filter_by(slug=full_slug) \
                      .limit(1).count():
                full_slug = increment_string(full_slug)
            self.slug = full_slug