本文整理汇总了Python中slugify.slugify方法的典型用法代码示例。如果您正苦于以下问题:Python slugify.slugify方法的具体用法?Python slugify.slugify怎么用?Python slugify.slugify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类slugify
的用法示例。
在下文中一共展示了slugify.slugify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: secure_path
# 需要导入模块: import slugify [as 别名]
# 或者: from slugify import slugify [as 别名]
def secure_path(path):
dirname = os.path.dirname(path)
filename = os.path.basename(path)
file_base, file_ext = os.path.splitext(path)
dirname = secure_filename(slugify(dirname, only_ascii=True))
file_base = secure_filename(slugify(file_base, only_ascii=True)) or 'unnamed'
file_ext = secure_filename(slugify(file_ext, only_ascii=True))
if file_ext:
filename = '.'.join([file_base, file_ext])
else:
filename = file_base
if len(filename) > 200:
filename = '%s__%s' % (filename[:99], filename[-99:])
if dirname:
return os.path.join(dirname, filename)
return filename
示例2: import_row
# 需要导入模块: import slugify [as 别名]
# 或者: from slugify import slugify [as 别名]
def import_row(self, row, project_id):
asset_key = slugify("%s%s" % (row["Asset Type"], row["Asset"]))
target_key = slugify(
"%s%s%s" % (row["Episode"], row["Parent"], row["Name"])
)
occurences = 1
if len(row["Occurences"]) > 0:
occurences = int(row["Occurences"])
label = slugify(row["Label"])
asset_id = self.asset_map.get(asset_key, None)
target_id = self.shot_map.get(target_key, None)
if target_id is None:
target_id = self.asset_map.get(target_key, None)
if asset_id is not None and target_id is not None:
breakdown_service.create_casting_link(
target_id, asset_id, occurences, label
)
示例3: get
# 需要导入模块: import slugify [as 别名]
# 或者: from slugify import slugify [as 别名]
def get(self, project_id):
self.task_type_map = tasks_service.get_task_type_map()
self.task_status_map = tasks_service.get_task_status_map()
project = projects_service.get_project(project_id)
self.check_permissions(project["id"])
csv_content = []
results = self.get_assets_data(project_id)
metadata_infos = self.get_metadata_infos(project_id)
validation_columns = self.get_validation_columns(results)
headers = self.build_headers(metadata_infos, validation_columns)
csv_content.append(headers)
for result in results:
result["project_name"] = project["name"]
csv_content.append(
self.build_row(result, metadata_infos, validation_columns)
)
file_name = "%s assets" % project["name"]
return csv_utils.build_csv_response(csv_content, slugify(file_name))
示例4: get
# 需要导入模块: import slugify [as 别名]
# 或者: from slugify import slugify [as 别名]
def get(self, project_id):
project = projects_service.get_project(project_id)
self.check_permissions(project["id"])
self.task_status_map = tasks_service.get_task_status_map()
self.task_type_map = tasks_service.get_task_type_map()
csv_content = []
results = self.get_shots_data(project_id)
metadata_infos = self.get_metadata_infos(project_id)
validation_columns = self.get_validation_columns(results)
headers = self.build_headers(metadata_infos, validation_columns)
csv_content.append(headers)
for result in results:
result["project_name"] = project["name"]
csv_content.append(
self.build_row(result, metadata_infos, validation_columns)
)
file_name = "%s shots" % project["name"]
return csv_utils.build_csv_response(csv_content, slugify(file_name))
示例5: update_metadata_descriptor
# 需要导入模块: import slugify [as 别名]
# 或者: from slugify import slugify [as 别名]
def update_metadata_descriptor(metadata_descriptor_id, changes):
"""
Update metadata descriptor information for given id.
"""
descriptor = get_metadata_descriptor_raw(metadata_descriptor_id)
entities = Entity.get_all_by(project_id=descriptor.project_id)
if "name" in changes and len(changes["name"]) > 0:
changes["field_name"] = slugify.slugify(changes["name"])
for entity in entities:
metadata = fields.serialize_value(entity.data) or {}
value = metadata.pop(descriptor.field_name, None)
if value is not None:
metadata[changes["field_name"]] = value
entity.update({"data": metadata})
descriptor.update(changes)
events.emit(
"metadata-descriptor:update",
{"metadata_descriptor_id": str(descriptor.id)},
)
clear_project_cache(str(descriptor.project_id))
return descriptor.serialize()
示例6: write_playlist_tracks
# 需要导入模块: import slugify [as 别名]
# 或者: from slugify import slugify [as 别名]
def write_playlist_tracks(self, playlist, target_path=None):
"""
Writes playlist track URIs to file.
Parameters
----------
playlist: `dict`
Spotify API response object for the playlist endpoint.
target_path: `str`
Write Spotify track URIs to this file.
"""
tracks = playlist["tracks"]
if not target_path:
target_path = u"{0}.txt".format(slugify(playlist["name"], ok="-_()[]{}"))
return self.write_tracks(tracks, target_path)
示例7: write_album_tracks
# 需要导入模块: import slugify [as 别名]
# 或者: from slugify import slugify [as 别名]
def write_album_tracks(self, album, target_path=None):
"""
Writes album track URIs to file.
Parameters
----------
album: `dict`
Spotify API response object for the album endpoint.
target_path: `str`
Write Spotify track URIs to this file.
"""
tracks = self.spotify.album_tracks(album["id"])
if not target_path:
target_path = u"{0}.txt".format(slugify(album["name"], ok="-_()[]{}"))
return self.write_tracks(tracks, target_path)
示例8: __new__
# 需要导入模块: import slugify [as 别名]
# 或者: from slugify import slugify [as 别名]
def __new__(mcs, name, bases, attrs):
def _test_function(data_test):
def _function(self):
validator = JSONSchemaValidator(data_test.schema or self.schema)
assert validator.validate(data_test.data) == (
data_test.valid,
data_test.expected_errors,
)
return _function
cls = super(SchemaTestCaseMetaclass, mcs).__new__(mcs, name, bases, attrs)
for dt in getattr(cls, "data_tests", []):
function_name = "test_%s" % slugify(dt.name, separator="_").lower()
setattr(cls, function_name, _test_function(dt))
return cls
示例9: __new__
# 需要导入模块: import slugify [as 别名]
# 或者: from slugify import slugify [as 别名]
def __new__(mcs, name, bases, attrs):
def _test_function(data_test):
def _function(self):
crawler = get_crawler(settings_dict=data_test.settings)
pipe = ItemValidationPipeline.from_crawler(crawler)
pipe.process_item(data_test.item, None)
kwargs = {"stats": "pipe.stats.stats.get_stats()"}
cases = data_test.cases
for case in cases if type(cases) in [list, tuple] else [cases]:
assert eval(case.format(**kwargs))
return _function
cls = super(PipelineTestCaseMetaclass, mcs).__new__(mcs, name, bases, attrs)
for dt in getattr(cls, "data_tests", []):
function_name = "test_%s" % slugify(dt.name, separator="_").lower()
setattr(cls, function_name, _test_function(dt))
return cls
示例10: topic_exists
# 需要导入模块: import slugify [as 别名]
# 或者: from slugify import slugify [as 别名]
def topic_exists(map_identifier):
topic_store = get_topic_store()
topic_map = topic_store.get_topic_map(map_identifier, current_user.id)
if topic_map is None:
abort(404)
normalised_topic_identifier = slugify(str(request.args.get("q").lower()))
normalised_topic_name = " ".join([word.capitalize() for word in normalised_topic_identifier.split("-")])
exists = topic_store.topic_exists(map_identifier, normalised_topic_identifier)
if exists:
result = {"topicExists": True}
else:
result = {
"topicExists": False,
"normalisedTopicIdentifier": normalised_topic_identifier,
"normalisedTopicName": normalised_topic_name,
}
return jsonify(result)
示例11: on_new_website
# 需要导入模块: import slugify [as 别名]
# 或者: from slugify import slugify [as 别名]
def on_new_website(self):
self.binder.update()
name = self.find('new-website-name').value
self.find('new-website-name').value = ''
if not name:
name = '_'
slug = slugify(name)
slugs = [x.slug for x in self.manager.config.websites]
while slug in slugs:
slug += '_'
w = Website.create(name)
w.slug = slug
w.owner = self.context.session.identity
self.manager.config.websites.append(w)
self.manager.save()
self.binder.populate()
示例12: encode_surname
# 需要导入模块: import slugify [as 别名]
# 或者: from slugify import slugify [as 别名]
def encode_surname(surname):
"""
Encode surname to the code used in italian fiscal code.
:param surname: The surname
:type surname: string
:returns: The code used in italian fiscal code
:rtype: string
"""
surname_slug = slugify(surname)
surname_consonants = _get_consonants(surname_slug)
surname_vowels = _get_vowels(surname_slug)
surname_code = _get_consonants_and_vowels(
surname_consonants, surname_vowels)
return surname_code
示例13: encode_name
# 需要导入模块: import slugify [as 别名]
# 或者: from slugify import slugify [as 别名]
def encode_name(name):
"""
Encodes name to the code used in italian fiscal code.
:param name: The name
:type name: string
:returns: The code used in italian fiscal code
:rtype: string
"""
name_slug = slugify(name)
name_consonants = _get_consonants(name_slug)
if len(name_consonants) > 3:
del name_consonants[1]
name_vowels = _get_vowels(name_slug)
name_code = _get_consonants_and_vowels(
name_consonants, name_vowels)
return name_code
示例14: save
# 需要导入模块: import slugify [as 别名]
# 或者: from slugify import slugify [as 别名]
def save(self, *args, **kwargs):
"""Update slug on save."""
self.board_slug = slugify(self.board_title, max_length=SLUG_MAX_LENGTH)
return super().save(*args, **kwargs)
示例15: get_unique_slug
# 需要导入模块: import slugify [as 别名]
# 或者: from slugify import slugify [as 别名]
def get_unique_slug(self, string):
string = slugify(string, max_length=25, separator="_", lowercase=False)
if string == '':
string = 'none'
test_string = string
i = 0
while test_string in self.list_unique_slugs:
i += 1
test_string = string + '_' + str(i)
self.list_unique_slugs.append(test_string)
return test_string