本文整理汇总了Python中pulsar.utils.slugify.slugify函数的典型用法代码示例。如果您正苦于以下问题:Python slugify函数的具体用法?Python slugify怎么用?Python slugify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了slugify函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, route, *routes, **params):
route = self.valid_route(route, params.pop('dir', None))
name = slugify(params.pop('name', None) or route or self.dir)
super(HtmlContent, self).__init__(route, *routes, name=name, **params)
# Add drafts index
if self.drafts:
self.add_child(Drafts(self.drafts,
name=self.childname('drafts'),
index_template=self.drafts_template))
self.meta = copy(self.meta) if self.meta else {}
# Add children routes
meta = copy(self.meta)
if self.meta_children:
meta.update(self.meta_children)
file = self.HtmlFileRouter(self.child_url, dir=self.dir,
name=self.childname('view'),
content=self.content,
html_body_template=self.html_body_template,
meta=meta,
uirouter=self.uirouter,
uimodules=self.uimodules)
self.add_child(file)
#
for url_path, file_path, ext in self.all_files(
include_subdirectories=False):
if url_path == 'index':
self.src = file_path
if self.src and self.index_template:
raise ImproperlyConfigured(
'Both index and index template specified')
开发者ID:SirZazu,项目名称:lux,代码行数:30,代码来源:routers.py
示例2: create_model
def create_model(self, request, data):
'''Create a new document
'''
model = self.model(request.app)
name = data.get('name') or data['title']
data['name'] = slugify(name, max_length=SLUG_LENGTH)
return model.write(request, request.cache.user, data, new=True)
开发者ID:pvanderlinden,项目名称:lux,代码行数:7,代码来源:views.py
示例3: __new__
def __new__(cls, name, bases, attrs):
attrs["can_register"] = not attrs.pop("abstract", False)
job_name = slugify(attrs.get("name", name), ".")
log_prefix = attrs.get("log_prefix") or "pulsar.queue"
attrs["name"] = job_name
logname = "%s.%s" % (log_prefix, job_name)
attrs["logger"] = logging.getLogger(logname)
return super(JobMetaClass, cls).__new__(cls, name, bases, attrs)
开发者ID:quantmind,项目名称:pulsar-queue,代码行数:8,代码来源:models.py
示例4: run
def run(self, options, **params):
api_client = self.app.api()
for api in self.app.apis:
res = api_client.get(api.spec_path)
filename = '%s.json' % slugify(api.spec_path)
with open(filename, 'w') as fp:
json.dump(res.json(), fp, indent=4)
self.logger.info('Saved %s', filename)
开发者ID:quantmind,项目名称:lux,代码行数:8,代码来源:apispec.py
示例5: __init__
def __init__(self, name=None, run_every=None, **attrs):
assert name, 'task requires a valid name'
self.class_name = slugify(name, '_')
self.attrs = attrs
base = Job
if run_every:
self.attrs['run_every'] = run_every
base = PeriodicJob
self.bases = (base,)
开发者ID:dejlek,项目名称:pulsar-queue,代码行数:9,代码来源:models.py
示例6: cms
def cms(self, app):
'''Obtain the cms handler for this Router
'''
key = ':'.join(b[1] for b in self.full_route.breadcrumbs[:-1])
if key:
return CMS(app, slugify(key))
else:
cms = app.cms
if not isinstance(cms, CMS):
app.cms = cms = CMS(app)
return cms
开发者ID:victor3rc,项目名称:lux,代码行数:11,代码来源:views.py
示例7: check_username
def check_username(request, username):
"""Default function for checking username validity
"""
correct = slugify(username)
if correct != username:
raise ValidationError('Username may only contain lowercase '
'alphanumeric characters or single hyphens, '
'cannot begin or end with a hyphen')
elif len(correct) < 2:
raise ValidationError('Too short')
return username
开发者ID:quantmind,项目名称:lux,代码行数:11,代码来源:__init__.py
示例8: __init__
def __init__(self, app, content, metadata, path, src=None, **params):
self._app = app
self._content = content
self._path = path
self._src = src
self._meta = AttributeDictionary(params)
self._update_meta(metadata)
if not self._meta.modified:
if src:
self._meta.modified = modified_datetime(src)
else:
self._meta.modified = datetime.now()
self._meta.name = slugify(self._path, separator='_')
开发者ID:pvanderlinden,项目名称:lux,代码行数:13,代码来源:contents.py
示例9: __init__
def __init__(self, app, content, metadata, src, path=None, context=None,
**params):
self._app = app
self._content = content
self._context_for = context
self._additional_context = {}
self._src = src
self._path = path or src
self._meta = AttributeDictionary(params)
if src:
self._meta.modified = modified_datetime(src)
else:
self._meta.modified = datetime.now()
# Get the site meta data dictionary.
# Used to render Content metadata
self._update_meta(metadata)
meta = self._meta
if self.is_html:
dir, slug = os.path.split(self._path)
if not slug:
slug = self._path
dir = None
if not meta.slug:
meta.slug = slugify(slug, separator='_')
if dir:
meta.slug = '%s/%s' % (dir, meta.slug)
else:
if self.suffix: # Any other file
suffix = '.%s' % self.suffix
if not self._path.endswith(suffix):
self._path = self._path + suffix
if not meta.slug:
meta.slug = self._path
meta.name = slugify(meta.slug, separator='_')
for name in self.mandatory_properties:
if not meta.get(name):
raise BuildError("Property '%s' not available in %s"
% (name, self))
开发者ID:tourist,项目名称:lux,代码行数:38,代码来源:contents.py
示例10: __call__
def __call__(self, callable):
if not self.class_name:
self.class_name = callable.__name__
self.class_name = slugify(self.class_name, "_")
self.attrs["__call__"] = callable
self.attrs["__doc__"] = callable.__doc__
cls = JobMetaClass(self.class_name, self.bases, self.attrs)
module = inspect.getmodule(callable)
job_list = getattr(module, JOB_LIST, None)
if not job_list:
job_list = []
setattr(module, JOB_LIST, job_list)
job_list.append(cls)
return cls
开发者ID:quantmind,项目名称:pulsar-queue,代码行数:14,代码来源:models.py
示例11: cache_key
def cache_key(self, arg):
key = self.key or ''
if hasattr(arg, 'environ'):
if not key:
key = arg.path
if self.user:
key = '%s-%s' % (key, arg.cache.user)
app = arg.app
base = self.callable.__name__
if self.instance:
base = '%s-%s' % (type(self.instance).__name__, base)
base = '%s-%s' % (app.config['APP_NAME'], base)
return slugify('%s-%s' % (base, key) if key else base)
开发者ID:quantmind,项目名称:lux,代码行数:16,代码来源:cache.py
示例12: addClass
def addClass(self, cn):
'''Add the specific class names to the class set and return ``self``.
'''
if cn:
if isinstance(cn, (tuple, list, set, frozenset)):
add = self.addClass
for c in cn:
add(c)
else:
classes = self._classes
if classes is None:
self._extra['classes'] = classes = set()
add = classes.add
for cn in cn.split():
add(slugify(cn))
return self
开发者ID:imclab,项目名称:pulsar,代码行数:16,代码来源:content.py
示例13: process_meta
def process_meta(meta, cfg):
as_list = MultiValue()
for key, values in mapping_iterator(meta):
key = slugify(key, separator='_')
if not isinstance(values, (list, tuple)):
values = (values,)
if key not in METADATA_PROCESSORS:
bits = key.split('_', 1)
values = guess(as_list(values, cfg))
if len(bits) > 1 and bits[0] == 'meta':
k = '_'.join(bits[1:])
yield k, values
else:
yield key, values
#
elif values:
process = METADATA_PROCESSORS[key]
yield key, process(values, cfg)
开发者ID:quantmind,项目名称:lux,代码行数:18,代码来源:contents.py
示例14: __init__
def __init__(self, *flags, help=None, nargs=None, **kwargs):
name = None
oflags = []
for flag in flags:
if not flag.startswith('-'):
name = flag
if not nargs:
nargs = '?'
oflags = None
else:
if oflags is None:
raise ImproperlyConfigured(
'cannot mix positional and keyed-valued arguments'
)
if flag.startswith('--') or not name:
name = slugify(flag, '_')
oflags.append(flag)
if not name:
raise ImproperlyConfigured('options with no name')
if help:
kwargs['desc'] = help
self.setting = Setting(name, oflags, nargs=nargs, **kwargs)
开发者ID:quantmind,项目名称:lux,代码行数:22,代码来源:__init__.py
示例15: __init__
def __init__(self, rule, *routes, **parameters):
Router._creation_count += 1
self._creation_count = Router._creation_count
if not isinstance(rule, Route):
rule = Route(rule)
self._route = rule
self._name = parameters.pop('name', rule.name)
self.routes = []
# add routes specified via the initialiser first
for router in routes:
self.add_child(router)
# copy parameters
self.parameters = AttributeDictionary(self.parameters)
for name, rule_method in self.rule_methods.items():
rule, method, params, _, _ = rule_method
rparameters = params.copy()
handler = getattr(self, name)
router = self.add_child(self.make_router(rule, **rparameters))
setattr(router, method, handler)
for name, value in parameters.items():
if name in self.parameters:
self.parameters[name] = value
else:
setattr(self, slugify(name, separator='_'), value)
开发者ID:imclab,项目名称:pulsar,代码行数:24,代码来源:routers.py
示例16: __init__
def __init__(self, name=None, cls=None):
self.name = slugify(name, separator='_') if name else ''
self.cls = cls or identity
开发者ID:victor3rc,项目名称:lux,代码行数:3,代码来源:urlwrappers.py
示例17: _set_params
def _set_params(self, parameters):
for name, value in parameters.items():
if name not in self.defaults:
name = slugify(name, separator='_')
setattr(self, name, value)
开发者ID:juanignaciocatalano,项目名称:pulsar,代码行数:5,代码来源:routers.py
示例18: __init__
def __init__(self, label, name=None, **attrs):
self.attrs = attrs
self.attrs['label'] = label
self.attrs['name'] = slugify(name or label, separator='')
if not self.attrs.get('type'):
self.attrs['type'] = self.type
开发者ID:tazo90,项目名称:lux,代码行数:6,代码来源:serialise.py
示例19: name
def name(self):
'''A nice name for the route.
Derived from :attr:`rule` replacing underscores and dashes.
'''
return slugify(self.rule, separator='_')
开发者ID:Danzeer,项目名称:pulsar,代码行数:6,代码来源:route.py
示例20: username
def username(self, user_data):
return slugify('%s.%s' % (user_data['firstName'],
user_data['lastName']))
开发者ID:quantmind,项目名称:lux,代码行数:3,代码来源:__init__.py
注:本文中的pulsar.utils.slugify.slugify函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论