How to use the shortuuid.ShortUUID function in shortuuid

To help you get started, we’ve selected a few shortuuid examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github F0RE1GNERS / eoj3 / polygon / contest / views.py View on Github external
def post(self, request, pk):
        namelist = list(filter(lambda x: x, map(lambda x: x.strip(), request.POST['list'].split('\n'))))
        user_id = 1
        contest = Contest.objects.get(pk=pk)
        for name in namelist:
            if name.startswith('*'):
                comment = name[1:].strip()
                star = True
            else:
                comment = name
                star = False
            password_gen = shortuuid.ShortUUID("23456789ABCDEF")
            password = password_gen.random(8)
            while True:
                try:
                    username = self._get_username(pk, user_id)
                    email = '%s@fake.ecnu.edu.cn' % username
                    user = User.objects.create(username=username, email=email)
                    user.set_password(password)
                    user.save()
                    user.avatar.save('generated.png', Identicon(user.email).get_bytes())
                    ContestParticipant.objects.create(user=user, comment=comment, hidden_comment=password,
                                                      star=star, contest=contest)
                    break
                except IntegrityError:
                    pass
                user_id += 1
        invalidate_contest(contest)
github F0RE1GNERS / eoj3 / polygon / contest / views.py View on Github external
    @staticmethod
    def _create(contest, comments):
        random_gen = shortuuid.ShortUUID()
        ContestInvitation.objects.bulk_create(
            [ContestInvitation(contest=contest, code=random_gen.random(12), comment=comment) for comment in comments])
github F0RE1GNERS / eoj3 / polygon / contest / views.py View on Github external
def _create(contest, comments):
    random_gen = shortuuid.ShortUUID()
    ContestInvitation.objects.bulk_create(
      [ContestInvitation(contest=contest, code=random_gen.random(12), comment=comment) for comment in comments])
github simo97 / PushBack / core / models.py View on Github external
def set_current_id(self):
        self.current_connection_id = shortuuid.ShortUUID().random(100)
        self.save()
github EuroPython / epcon / conference / models.py View on Github external
def random_shortuuid():
    return shortuuid.ShortUUID().random(length=7)
github wandb / client / wandb / kubeflow / arena.py View on Github external
def _short_id(length=8):
    uuid = shortuuid.ShortUUID(alphabet=list(
        "0123456789abcdefghijklmnopqrstuvwxyz"))
    return uuid.random(length)
github gouthambs / Flask-Blogging / flask_blogging / dynamodbstorage.py View on Github external
def __init__(self, table_prefix="", region_name=None,
                 endpoint_url=None):
        self._client = boto3.client('dynamodb',
                                    region_name=region_name,
                                    endpoint_url=endpoint_url)
        self._db = boto3.resource("dynamodb",
                                  region_name=region_name,
                                  endpoint_url=endpoint_url)
        self._table_prefix = table_prefix
        self._create_all_tables()
        self._uuid = ShortUUID()
        self._uuid.set_alphabet('23456789abcdefghijkmnopqrstuvwxyz')
github PGPerfFarm / pgperffarm / web / apps / users / models.py View on Github external
def approve_machine(self):
        "Approve Machine(Modify the state to active, generate machine_sn, machine_secret, and assign an alias)"
        alias = Alias.objects.filter(is_used=False).order_by('?').first()
        if not alias:
            return {"is_success": False, "alias": '', "secret": '', "email":''}
        from django.db import transaction
        with transaction.atomic():
            alias.is_used=True
            alias.save()

            self.alias = alias
            self.state = 1
            if not self.machine_sn:
                self.machine_sn = shortuuid.ShortUUID().random(length=16)

            if not self.machine_secret:
                machine_str = self.alias.name + self.os_name + self.os_version + self.comp_name + self.comp_version + self.machine_sn

                m = hashlib.md5()
                m.update(make_password(str(machine_str), 'pg_perf_farm'))
                self.machine_secret = m.hexdigest()

            self.save()


        # serializer = JWTUserProfileSerializer(user)
        print(self.machine_owner.email)
        user_email = self.machine_owner.email
        system = self.os_name + ' ' + self.os_version
        compiler = self.comp_name + ' ' + self.comp_version
github apache / incubator-ariatosca / aria / utils / uuid.py View on Github external
# limitations under the License.

"""
UUID generation utilities.
"""

from __future__ import absolute_import  # so we can import standard 'uuid'

from random import randrange
from uuid import uuid4

from shortuuid import ShortUUID


# Alphanumeric without visually ambiguous characters; default length is 22
UUID_BASE57 = ShortUUID()

# Lower-case alphanumeric; default length is 25
UUID_LOWERCASE_ALPHANUMERIC = ShortUUID(alphabet='abcdefghijklmnopqrstuvwxyz0123456789')


def generate_uuid(length=None, variant='base57'):
    """
    A random string with varying degrees of guarantee of universal uniqueness.

    :param variant:
     * ``base57`` (the default) uses a mix of upper and lowercase alphanumerics ensuring no visually
       ambiguous characters; default length 22
     * ``alphanumeric`` uses lowercase alphanumeric; default length 25
     * ``uuid`` uses lowercase hexadecimal in the classic UUID format, including dashes; length is
       always 36
     * ``hex`` uses lowercase hexadecimal characters but has no guarantee of uniqueness; default