Exemple #1
0
def test_slug_normalizing():
    assert_equal(helpers.normalize(''), '')
    assert_equal(helpers.normalize('dadada'), 'dadada')
    assert_equal(helpers.normalize('DaDaDa'), 'dadada')
    assert_equal(helpers.normalize('The house'), 'the-house')
    assert_equal(helpers.normalize('The  house'), 'the-house')
    assert_equal(helpers.normalize(' 123-name '), '123-name')
    assert_equal(helpers.normalize('a?b&c>d<e=f/g'), 'a-b-c-d-e-f-g')
Exemple #2
0
def test_slug_normalizing():
    assert_equal(helpers.normalize(''), '')
    assert_equal(helpers.normalize('dadada'), 'dadada')
    assert_equal(helpers.normalize('DaDaDa'), 'dadada')
    assert_equal(helpers.normalize('The house'), 'the-house')
    assert_equal(helpers.normalize('The  house'), 'the-house')
    assert_equal(helpers.normalize(' 123-name '), '123-name')
    assert_equal(helpers.normalize('a?b&c>d<e=f/g'), 'a-b-c-d-e-f-g')
Exemple #3
0
 def _set_title(self, title):
     """Constrain title with slug so slug is never set directly"""
     self._title = title
     slug = normalize(title)
     # Make the slug unique
     while True:
         entry = Post.query.filter_by(slug=slug).first()
         if not entry or entry == self: break
         slug += "-2"
     self._slug = slug
Exemple #4
0
 def _set_title(self, title):
     """Constrain title with slug so slug is never set directly"""
     self._title = title
     slug = normalize(title)
     # Make the slug unique
     while True:
         entry = Post.query.filter_by(slug=slug).first()
         if not entry or entry == self: break
         slug += "-2"
     self._slug = slug
Exemple #5
0
def preview():
    """Returns a preview of a blog post. Use with an Ajax request"""
    args = request.form
    # Mimic post object
    post = dict(
        slug=normalize(args['title']), 
        title=args['title'],
        markup=args['markup'],
        visible=True,
        html=convert_markup(args['markup']),
        datetime=datetime.datetime.fromtimestamp(int(args['datetime'])),
        # Mimic the tag relationship field of post
        tags=[dict(name=tag) for tag in normalize_tags(args['tags'])],
        # Mimic the category relationship field of post
        categories=[dict(name=name) for name in 
            filter(lambda x: x != '', set(args['categories'].split(',')))],
    )
    return render_template('admin/_preview.html', post=post)
Exemple #6
0
def preview():
    """Returns a preview of a blog post. Use with an Ajax request"""
    args = request.form
    # Mimic post object
    post = dict(
        slug=normalize(args['title']),
        title=args['title'],
        markup=args['markup'],
        visible=True,
        html=convert_markup(args['markup']),
        datetime=datetime.datetime.fromtimestamp(int(args['datetime'])),
        # Mimic the tag relationship field of post
        tags=[dict(name=tag) for tag in normalize_tags(args['tags'])],
        # Mimic the category relationship field of post
        categories=[
            dict(name=name) for name in filter(
                lambda x: x != '', set(args['categories'].split(',')))
        ],
    )
    return render_template('admin/_preview.html', post=post)