Python shortuuid.ShortUUID() Examples

The following are 10 code examples of shortuuid.ShortUUID(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module shortuuid , or try the search function .
Example #1
Source File: views.py    From tushe with MIT License 6 votes vote down vote up
def drop():
    file = request.files['file']
    i = Image()
    i.title = file.filename
    i.image = file
    uuid = shortuuid.ShortUUID().random(length=6)
    while Image.objects(iid=uuid):
        uuid = shortuuid.ShortUUID().random(length=6)
    i.iid = uuid
    if login.current_user.is_active():
        i.user = login.current_user._get_current_object()
    else:
        i.user = system_user
    i.description = ''
    i.tags = []
    i.save()
    return jsonify(id=uuid) 
Example #2
Source File: views.py    From tushe with MIT License 6 votes vote down vote up
def create_gallery():
    if not login.current_user.is_active():
        flash('请登录后再搞相册哦~')
        return redirect(url_for('light-cms.user_login'))
    if request.method == 'GET':
        return render_template('create_gallery.html', title='创建相册')
    if request.method == 'POST':
        uuid = shortuuid.ShortUUID().random(length=6)
        while Gallery.objects(gid=uuid):
            uuid = shortuuid.ShortUUID().random(length=6)
        title = request.form['title']
        g = Gallery()
        g.user = login.current_user._get_current_object()
        g.gid = uuid
        g.title = title
        g.save()
        return redirect(url_for('light-cms.add_image_to_gallery', gid=g.gid)) 
Example #3
Source File: views.py    From tushe with MIT License 6 votes vote down vote up
def gallery_drop(gid):
    if not login.current_user.is_active():
        flash('请登录后再搞相册哦~')
        return redirect(url_for('light-cms.user_login'))
    g = Gallery.objects.get_or_404(gid=gid)
    file = request.files['file']
    i = Image()
    i.gallery.append(g)
    i.title = file.filename
    i.image = file
    uuid = shortuuid.ShortUUID().random(length=6)
    while Image.objects(iid=uuid):
        uuid = shortuuid.ShortUUID().random(length=6)
    i.iid = uuid
    i.user = login.current_user._get_current_object()
    i.description = ''
    i.tags = []
    i.save()
    return jsonify(id=uuid) 
Example #4
Source File: wc.py    From tushe with MIT License 6 votes vote down vote up
def receive():
    data = request.data
    data = xmltodict.parse(data)['xml']
    if data['MsgType'] == 'text':
        return send_text(data['FromUserName'], 'hi')
    if data['MsgType'] == 'image':
        token = current_access_token()
        file_url = 'https://api.weixin.qq.com/cgi-bin/media/get?access_token=%s&media_id=%s' % (token, data['MediaId'])
        file = requests.get(file_url, stream=True).raw
        i = Image()
        i.image = file
        uuid = shortuuid.ShortUUID().random(length=6)
        while Image.objects(iid=uuid):
            uuid = shortuuid.ShortUUID().random(length=6)
        i.iid = uuid
        i.title = data['MediaId']
        i.user = system_user
        i.description = ''
        i.tags = []
        i.save()
        return send_text(
            data['FromUserName'], '上传成功!图片地址:%s%s' % (
                request.url_root[:-1], url_for('light-cms.image', iid=i.iid)
            )
        ) 
Example #5
Source File: user_service.py    From crestify with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def regenerate_api_key(id):
    user = User.query.get(id)
    user.api_key = shortuuid.ShortUUID().random(length=32)
    db.session.commit() 
Example #6
Source File: dynamodbstorage.py    From Flask-Blogging with MIT License 5 votes vote down vote up
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') 
Example #7
Source File: kpi_uid.py    From kpi with GNU Affero General Public License v3.0 5 votes vote down vote up
def generate_uid(self):
        return self.uid_prefix + ShortUUID().random(UUID_LENGTH)
        # When UID_LENGTH is 22, that should be changed to:
        # return self.uid_prefix + shortuuid.uuid() 
Example #8
Source File: views.py    From eoj3 with MIT License 5 votes vote down vote up
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]) 
Example #9
Source File: views.py    From eoj3 with MIT License 5 votes vote down vote up
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)
    return HttpResponseRedirect(request.POST['next']) 
Example #10
Source File: models.py    From eoj3 with MIT License 5 votes vote down vote up
def get_invitation_code():
  return shortuuid.ShortUUID().random(12)