def test_slugify(self): slug = slugify(datetime(2013, 1, 20), u'Title!') self.assertEqual('2013/1/20/title', slug) slug = slugify(datetime(2011, 8, 12), u'Title Title') self.assertEqual('2011/8/12/title-title', slug) slug = slugify(datetime(2012, 10, 2), u' T1tl3! T1tl3! ') self.assertEqual('2012/10/2/t1tl3-t1tl3', slug)
def __init__(self, title, body, author_id): self.published = datetime.utcnow() self.edited = self.published self.title = title self.body = body self.slug = slugify(self.published, title) self.author_id = author_id
def __init__(self, title, markup, author_id, visible): self.created = datetime.utcnow() self.updated = self.created self.title = title self.markup = markup self.slug = slugify(self.created, title) self.author_id = author_id self.visible = visible
def tet_edit(self): # assert current title is set with correct slug q = Post.query.get(self.post.id) self.assertEqual(self.title, q.title) slug = slugify(datetime.utcnow(), self.title) self.assertEqual(slug, q.slug) # update database with new post title new_title = 'foo' q.edit(new_title, self.body) self.commit() # assert title and slug updated q = Post.query.get(self.post.id) self.assertEqual(new_title, q.title) slug = slugify(datetime.utcnow(), self.new_title) self.assertEqual(slug, q.slug) # assert edit date has also been updated self.assertGreater(q.edited, q.published)
def update(self, title, markup, visible): """Update post values. Handles title slug and last update tracking. """ self.updated = datetime.utcnow() self.title = title self.markup = markup self.slug = slugify(self.created, title) self.visible = visible
def test_create(self): # assert default post added self.assertEqual(1, len(Post.query.all())) # assert correct post values q = Post.query.get(self.post.id) self.assertEqual(self.title, q.title) self.assertEqual(self.body, q.body) slug = slugify(datetime.utcnow(), self.title) self.assertEqual(slug, q.slug) self.assertEqual(self.author_id, q.author_id) # assert unique for same date db.session.add(Post(self.title, self.body, self.author_id)) self.assertRaises(IntegrityError, db_commit) # assert not unique for diffrent date now = datetime.utcnow() latest_post = Post(self.title, self.body, self.author_id) latest_post.published = datetime(now.year - 1, now.month, now.day) latest_post.edit(self.title, self.body) db.session.add(latest_post) db.session.commit()
def test_slugify(self): assert slugify('My slug') == u'my-slug'
def test_slugify_with_different_separator(self): assert slugify('My slug','_') == u'my_slug'
#!/usr/bin/env python # -*- coding: utf-8 -*- import os from app import create_app from app.helpers import project_name, slugify application = create_app() if __name__ == '__main__': from app.factory import environment app_name = application.config['APP_NAME'] server = application.config['SERVER_NAME'].split(':') assert 1 <= len(server) <= 2, "SERVER_NAME in settings should be like 'example.com' or 'localhost:5000', not: {}".format(server) host = server[0] port = int(server[1]) if len(server) == 2 else 5000 env = environment() print(u"INFO Starting '{app}' ({env_var_prefix}) on {host}:{port} using environment '{env}'".format(**dict( app=app_name, env_var_prefix=slugify(project_name, '_').upper(), host=host, port=port, env=env, ))) application.run(host=host, port=port)
import os from app import create_app from app.helpers import project_name, slugify application = create_app() if __name__ == '__main__': from app.factory import environment app_name = application.config['APP_NAME'] server = application.config['SERVER_NAME'].split(':') assert 1 <= len( server ) <= 2, "SERVER_NAME in settings should be like 'example.com' or 'localhost:5000', not: {}".format( server) host = server[0] port = int(server[1]) if len(server) == 2 else 80 env = environment() print(( "INFO Starting '{app}' ({env_var_prefix}) on {host}:{port} using environment '{env}'" .format(**dict( app=app_name, env_var_prefix=slugify(project_name, '_').upper(), host=host, port=port, env=env, )))) application.run(host=host, port=port)
def post(self): themes = get_all_themes() default_theme = get_theme('default') args = parser_theme.parse_args() if 'identifier' not in args or args['identifier'] is None: args['identifier'] = slugify( args['name'].decode('utf-8'), delim=u'_') req_ident = [th for th in themes if th.identifier == args['identifier']] if not len(req_ident): path_theme = scafold_theme(args['identifier']) args['options'] = parser_theme_options.parse_args(req=args) # args['options']['styles'] = parser_theme_styles.parse_args(req=args['options']) # Pour le hash 'styles' on pioche dans le thème par défaut args['options']['styles'] = default_theme.options['styles'] # Liste des fichiers images default_img = get_img_files(default_theme) for img in default_img: f = img['path'].split('/')[-1:][0] src_path = os.path.join(default_theme.path, 'static/img', f) dest_path = os.path.join(path_theme, 'static/img', f) local('cp %s %s' % (src_path, dest_path)) preview = args['options']['preview'] = parser_theme_preview.parse_args(req=args['options']) args['options']['logo'] = parser_theme_logo.parse_args(req=args['options']) # nom du logo en dur, où mettre ca ? args['options']['logo']['path'] = os.path.join("/themes", args['identifier'], 'img', 'logo.png') info = write_json_file(args, path_theme) # FIXME # Copie du contenu des fichiers less du thème par défaut, VRAIMENT pas terrible # Procéder comme pour les .html plus bas avec des 'templates' less dans les statics de l'app ? less_styles_path = os.path.join(default_theme.path, 'less', 'styles.less') with open(less_styles_path, 'r') as o: content = o.read() with open(os.path.join(path_theme, 'less', 'styles.less'), 'w') as f: f.write(content) # autant styles ca peut encore passer, autant là on a un problème. less_base_path = os.path.join(default_theme.path, 'less', 'base.less') with open(less_base_path, 'r') as o: content = o.read() with open(os.path.join(path_theme, 'less', 'base.less'), 'w') as f: f.write(content) tpl_index_src, tpl_index_src_path, tpl_index_src_func = app.jinja_env.loader.get_source(app.jinja_env,'public/_index.html') with open(os.path.join(path_theme, 'templates', 'index.html'), 'w') as f: f.write(tpl_index_src) tpl_info_src, tpl_info_src_path, tpl_info_src_func = app.jinja_env.loader.get_source(app.jinja_env,'public/_info.html') with open(os.path.join(path_theme, 'templates', 'info.html'), 'w') as f: f.write(tpl_info_src) # refresh de la liste des thèmes app.theme_manager.refresh() # recup du thèmes nouvellement créé theme = get_theme(args['identifier']) # Liste des fichiers images (copiés plus haut) args['options']['files'] = get_img_files(theme) # création du fichier variables.less et compilation des fichiers less lessok = write_less_file(args['options']['styles'], theme) try: # FIXME # preview de ... la page de login :) # Puisque cette vue est en login_required (et le restera sans doute) # et que Phantom n'est pas authentifié (et ne devrait pas le devenir)... user = TW_Client.api.verify_credentials() return_call = make_preview("?theme=%s" % theme.identifier, theme, preview['width'], preview['height']) except TweepError: print "Aucune Race et pas de compte twitter" # theme.info['options']['files'] = get_img_files(theme) return marshal(theme.info, theme_info_fields) return marshal(args, theme_info_fields)
def filter_by_title_today(self, title): """Return post with slug generated from current time and title.""" slug = slugify(datetime.utcnow(), title) return self.slug(slug)
def edit(self, title, body): """Edit post columns.""" self.edited = datetime.utcnow() self.title = title self.body = body self.slug = slugify(self.published, title)
def tagged(self, query_tag): tagged_posts = self.all() self.posts = [post for post in tagged_posts if query_tag in [slugify(tag) for tag in post.tags]]
def test_slugify(self): assert slugify('My slug') == 'my-slug'
def test_slugify_with_different_separator(self): assert slugify('My slug', '_') == 'my_slug'