當前位置: 首頁>>代碼示例>>Python>>正文


Python slugify.slugify方法代碼示例

本文整理匯總了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 
開發者ID:pcbje,項目名稱:gransk,代碼行數:23,代碼來源:document.py

示例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
            ) 
開發者ID:cgwire,項目名稱:zou,代碼行數:21,代碼來源:casting.py

示例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)) 
開發者ID:cgwire,項目名稱:zou,代碼行數:24,代碼來源:assets.py

示例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)) 
開發者ID:cgwire,項目名稱:zou,代碼行數:24,代碼來源:shots.py

示例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() 
開發者ID:cgwire,項目名稱:zou,代碼行數:23,代碼來源:projects_service.py

示例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) 
開發者ID:ritiek,項目名稱:spotify-downloader,代碼行數:18,代碼來源:spotify.py

示例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) 
開發者ID:ritiek,項目名稱:spotify-downloader,代碼行數:18,代碼來源:spotify.py

示例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 
開發者ID:scrapinghub,項目名稱:spidermon,代碼行數:18,代碼來源:test_validators_jsonschema.py

示例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 
開發者ID:scrapinghub,項目名稱:spidermon,代碼行數:20,代碼來源:test_pipelines.py

示例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) 
開發者ID:brettkromkamp,項目名稱:contextualise,代碼行數:21,代碼來源:api.py

示例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() 
開發者ID:niiknow,項目名稱:ajenticp,代碼行數:20,代碼來源:main.py

示例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 
開發者ID:fabiocaccamo,項目名稱:python-codicefiscale,代碼行數:18,代碼來源:codicefiscale.py

示例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 
開發者ID:fabiocaccamo,項目名稱:python-codicefiscale,代碼行數:22,代碼來源:codicefiscale.py

示例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) 
開發者ID:twschiller,項目名稱:open-synthesis,代碼行數:6,代碼來源:models.py

示例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 
開發者ID:dataiku,項目名稱:dataiku-contrib,代碼行數:13,代碼來源:connector.py


注:本文中的slugify.slugify方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。