Generate a slug based on the main model key.
160187
public function generateIdSlug()
    {
        $slug = Slug::fromId($this->getKey());

        // Ensure slug is unique (since the fromId() algorithm doesn't produce unique slugs)
        $attempts = 10;
        while ($this->isExistingSlug($slug)) {
            if ($attempts <= 0) {
                throw new UnableToCreateSlugException(
                    "Unable to find unique slug for record '{$this->getKey()}', tried 10 times..."
                );
            }

            $slug = Slug::random();
            $attempts--;
        }

        $this->setSlugValue($slug);
    }
702030
def get_category_for_slug(slug, language_code=None):
    
    Category = get_category_model()
    if issubclass(Category, TranslatableModel):
        return Category.objects.active_translations(language_code, slug=slug).get()
    else:
        return Category.objects.get(slug=slug)
64392
def auto_slug_on_insert(mapper, connection, target):
    """"""
    if target.slug is None and target.name:
        target.slug = target.auto_slug
388075
public function generateModel()
    {
        app('Luthfi\CrudGenerator\Generators\ModelGenerator', ['command' => $this])->generate();
        app('Luthfi\CrudGenerator\Generators\MigrationGenerator', ['command' => $this])->generate();
        app('Luthfi\CrudGenerator\Generators\ModelPolicyGenerator', ['command' => $this])->generate();
        app('Luthfi\CrudGenerator\Generators\ModelFactoryGenerator', ['command' => $this])->generate();
    }
631110
def cache_data(self):
        
        # Set Slug if not set
        if not self.slug_name:
            self.slug_name = slugify(self.name).strip()
            if len(self.slug_name) > 255:
                self.slug_name = self.slug_name[0:254]
902110
protected function _canonicalizeSlug()
    {
        $table = $this->getTable();

        //If the slug needs to be unique and it already exists, make it unique
        $query = $this->getObject('lib:database.query.select');
        $query->where('slug = :slug')->bind(array('slug' => $this->slug));

        if (!$this->isNew())
        {
            $query->where($table->getIdentityColumn().' <> :id')
                ->bind(array('id' => $this->id));
        }

        if($table->count($query))
        {
            $length = $this->_length ? $this->_length : $table->getColumn('slug')->length;

            // Cut 4 characters to make space for slug-1 slug-23 etc
            if ($length && strlen($this->slug) > $length-4) {
                $this->slug = substr($this->slug, 0, $length-4);
            }

            $query = $this->getObject('lib:database.query.select')
                ->columns('slug')
                ->where('slug LIKE :slug')
                ->bind(array('slug' => $this->slug . '-%'));

            $slugs = $table->select($query, Database::FETCH_FIELD_LIST);

            $i = 1;
            while(in_array($this->slug.'-'.$i, $slugs)) {
                $i++;
            }

            $this->slug = $this->slug.'-'.$i;
        }
    }
830109
def create_slug(self):
        
        name = self.slug_source
        counter = 0
        # loops until slug is unique
        while True:
            if counter == 0:
                slug = slugify(name)
            else:
                # using the counter var to bump the slug name
                slug = slugify('{0} {1}'.format(name, str(counter)))
            try:
                # does the slug already exist, excluding the current object
                self.__class__.objects.exclude(pk=self.pk).get(slug=slug)
                # if slug exists increment counter and loop
                counter += 1
            except ObjectDoesNotExist:
                # the slug does not exist
                # we can break from the loop
                break
        return slug
284490
def save_model(self, request, obj, form, change):
        
        if change and obj._old_slug != obj.slug:
            # _old_slug was set in PageAdminForm.clean_slug().
            new_slug = obj.slug or obj.generate_unique_slug()
            obj.slug = obj._old_slug
            obj.set_slug(new_slug)

        # Force parent to be saved to trigger handling of ordering and slugs.
        parent = request.GET.get("parent")
        if parent is not None and not change:
            obj.parent_id = parent
            obj.save()
        super(PageAdmin, self).save_model(request, obj, form, change)
1047972
def get_primary_key(model):
    """"""
    model = get_model(model)
    return (field.name for field in model._meta.fields if field.primary_key).next()
852276
public static function slug()
    {
        $timestamp = Cuid::timestamp(Cuid::SMALL_BLOCK);
        $count = Cuid::count(Cuid::SMALL_BLOCK);
        $fingerprint = Cuid::fingerprint(Cuid::SMALL_BLOCK);
        $random = Cuid::random(Cuid::SMALL_BLOCK);

        return $timestamp .
            $count .
            $fingerprint .
            $random;
    }
168461
def generate(engine, database, models, **kwargs):
    '''
    
    '''
    validate_args(engine, database, models)
    generator = Generator(engine, database, models)
    generator.run()
152897
def get(self, request, slug):
        
        matching_datasets = self.generate_matching_datasets(slug)

        if matching_datasets is None:
            raise Http404("Datasets meeting these criteria do not exist.")

        base_context = {
            'datasets': matching_datasets,
            'num_datasets': matching_datasets.count(),
            'page_title': self.generate_page_title(slug),
        }

        additional_context = self.generate_additional_context(
            matching_datasets
        )

        base_context.update(additional_context)
        context = base_context

        return render(
            request,
            self.template_path,
            context
        )
783245
def slug(self):
        
        identifier = ""
        # use a truncated timestamp
        millis = int(time.time() * 1000)
        millis_string = _to_base36(millis)
        identifier += millis_string[-2:]
        # use a truncated counter
        count = _pad(_to_base36(self.counter), 1)
        identifier += count
        # use a truncated fingerprint
        identifier += self.fingerprint[0]
        identifier += self.fingerprint[-1]
        # use some truncated random data
        random_data = _random_block()
        identifier += random_data[-2:]

        return identifier
891560
def generate_key(self):
        
        sql = self.sql()
        key, created = self.get_or_create_model_key()
        if created:
            db_table = self.model._meta.db_table
            logger.debug('created new key {0} for model {1}'.format(key, db_table))
            model_cache_info = ModelCacheInfo(db_table, key)
            model_cache_backend.share_model_cache_info(model_cache_info)
        query_key = u'{model_key}{qs}{db}'.format(model_key=key,
                                                  qs=sql,
                                                  db=self.db)
        key = hashlib.md5(query_key.encode('utf-8')).hexdigest()
        return key
849349
protected function generateSlugOnUpdate()
    {
        $this->slugOptions = $this->getSlugOptions();

        if (!$this->slugOptions->generateSlugOnUpdate) {
            return;
        }

        // check updating
        $slugNew = $this->generateNonUniqueSlug();
        $slugCurrent = $this->attributes[$this->slugOptions->slugField];

        // if new base slug is in string as old slug (the slug source's value did not change)
        // see if the slug is still unique in database
        if (strpos($slugCurrent, $slugNew) === 0) {
            $slugUpdate = $this->checkUpdatingSlug($slugCurrent);
            // no need to update slug (slug is still unique)
            if ($slugUpdate !== false) {
                return;
            }
        }

        $this->createSlug();
    }
123014
def slugify(mapping, bind, values):
    
    for value in values:
        if isinstance(value, six.string_types):
            value = transliterate(value)
            value = normality.slugify(value)
        yield value
808931
def create_definition(self, block_type, slug=None):
        """"""
        prefix = "d"
        if slug:
            prefix += "_" + slug
        def_id = self._next_id(prefix)
        self._definitions[def_id] = block_type
        return def_id