A copy of spectator.core.models.SluggedModelMixin._generate_slug()
775659
def generate_slug(value):
    ""
    alphabet = 'abcdefghijkmnopqrstuvwxyz23456789'
    salt = 'Django Spectator'

    if hasattr(settings, 'SPECTATOR_SLUG_ALPHABET'):
        alphabet = settings.SPECTATOR_SLUG_ALPHABET

    if hasattr(settings, 'SPECTATOR_SLUG_SALT'):
        salt = settings.SPECTATOR_SLUG_SALT

    hashids = Hashids(alphabet=alphabet, salt=salt, min_length=5)

    return hashids.encode(value)
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
        )
1003725
def auto_slug_after_insert(mapper, connection, target):
    """"""
    if target.slug is None:
        target.slug = "{name}{sep}{id}".format(
            name=target.entity_class.lower(), sep=target.SLUG_SEPARATOR, id=target.id
        )
613563
def set_slug(apps, schema_editor):
    
    Event = apps.get_model('spectator_events', 'Event')

    for e in Event.objects.all():
        e.slug = generate_slug(e.pk)
        e.save(update_fields=['slug'])
610274
public function generateSlug()
    {
        $strategy = $this->slugStrategy();

        if ($strategy == 'uuid') {
            $this->generateIdSlug();
        } elseif ($strategy != 'id') {
            $this->generateTitleSlug((array) $strategy);
        }
    }
891018
private function add_slugify_helper() {
		$this->engine->addHelper(
			'slugify',
			function ( $template, $context, $args ) {
					$arg = $context->get( $args );
					return slugify( $arg );
			}
		);
	}
318904
def generate_form(model, only=None, meta=None):
    
    fields = OrderedDict()
    if meta:
        fields['Meta'] = meta

    for name, column in model.__dict__['columns'].items():
        if only:
            if not name in only:
                continue
        if not isinstance(column, Column):
            continue
        fields[name] = TYPE_MAP[column.type.__class__](
            name, render_kw={'placeholder': name}
        )
    form = type(
        'Add{}Form'.format(model.name.capitalize()),
        (Form,),
        fields
    )
    return form
1365387
def populate_slug(instance, field):
    '''
    
    '''
    value = getattr(instance, field.db_field)

    try:
        previous = instance.__class__.objects.get(id=instance.id)
    except Exception:
        previous = None

    # Field value has changed
    changed = field.db_field in instance._get_changed_fields()
    # Field initial value has been manually set
    manual = not previous and value or changed

    if not manual and field.populate_from:
        # value to slugify is extracted from populate_from parameter
        value = getattr(instance, field.populate_from)
        if previous and value == getattr(previous, field.populate_from):
            return value

    if previous and getattr(previous, field.db_field) == value:
        # value is unchanged from DB
        return value

    if previous and not changed and not field.update:
        # Field is not manually set and slug should not update on change
        return value

    slug = field.slugify(value)

    # This can happen when serializing an object which does not contain
    # the properties used to generate the slug. Typically, when such
    # an object is passed to one of the Celery workers (see issue #20).
    if slug is None:
        return

    old_slug = getattr(previous, field.db_field, None)

    if slug == old_slug:
        return slug

    # Ensure uniqueness
    if field.unique:
        base_slug = slug
        index = 1
        qs = instance.__class__.objects
        if previous:
            qs = qs(id__ne=previous.id)

        def exists(s):
            return qs(
                class_check=False, **{field.db_field: s}
            ).limit(1).count(True) > 0

        while exists(slug):
            slug = '{0}-{1}'.format(base_slug, index)
            index += 1

    # Track old slugs for this class
    if field.follow and old_slug != slug:
        ns = instance.__class__.__name__
        # Destroy redirections from this new slug
        SlugFollow.objects(namespace=ns, old_slug=slug).delete()

        if old_slug:
            # Create a redirect for previous slug
            slug_follower, created = SlugFollow.objects.get_or_create(
                namespace=ns,
                old_slug=old_slug,
                auto_save=False,
            )
            slug_follower.new_slug = slug
            slug_follower.save()

            # Maintain previous redirects
            SlugFollow.objects(namespace=ns, new_slug=old_slug).update(new_slug=slug)

    setattr(instance, field.db_field, slug)
    return slug
883531
def generate(self, step, params):
        """"""
        # Recurse into a DictFactory: allows users to have some params depending
        # on others.
        params = step.recurse(base.DictFactory, params, force_sequence=step.sequence)
        filename, content = self._make_content(params)
        return django_files.File(content.file, filename)
1177830
def set_slug(apps, schema_editor):
    
    Creator = apps.get_model('spectator_core', 'Creator')

    for c in Creator.objects.all():
        c.slug = generate_slug(c.pk)
        c.save(update_fields=['slug'])
1154388
public function regenerateSlug()
    {
        $this->slugWorkingRecord->{$this->slugDbField} = $this->encrypt();
        $salt = $this->slugSalt;

        if ($this->mustBeUnique && !$this->hasUniqueSlug()) {
            $generator = new RandomGenerator();

            while (!$this->hasUniqueSlug()) {
                $salt = $generator->randomToken();
                $this->slugWorkingRecord->{$this->slugDbField} = $this->encrypt(null, $salt);
            }
        }

        $this->slugWorkingRecord->{$this->slugDbFieldForSalt} = $salt;
    }
471560
function (instance, sourceFields) {
        var slugParts = sourceFields.map(function (slugSourceField) {
            return instance[slugSourceField];
        });

        var options = (slugOptions && slugOptions.slugOptions) || { lower: true};
        return slug(slugParts.join(' '), options);
    }
79902
def save(self, *args, **kwargs):
        
        if self.slug is None or self.slug == "":
            self.slug = slugify(self.name)

        feature_type = super(FeatureType, self).save(*args, **kwargs)

        if self.instant_article_is_dirty:
            index_feature_type_content.delay(self.pk)

        self._db_instant_article = self.instant_article

        # Run all behaviors for `create`
        if self.is_new:
            update_feature_type_rates.delay(self.pk)

        return feature_type
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
989983
def _slugify_internal_collection_name(self, json_repr):
        """"""
        collection = self._coerce_json_to_collection(json_repr)
        if collection is None:
            return None
        internal_name = collection['name']
        return slugify(internal_name)
338443
protected function createSlug()
    {
        $slug = $this->generateNonUniqueSlug();

        if ($this->slugOptions->generateUniqueSlug) {
            $slug = $this->makeSlugUnique($slug);
        }

        $this->attributes[$this->slugOptions->slugField] = $slug;
    }
1225309
protected function generateSlugOnCreate()
    {
        $this->slugOptions = $this->getSlugOptions();

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

        $this->createSlug();
    }