Merge pull request #196 from ZeusWPI/eight-character-slug
Make slug eight characters
This commit is contained in:
commit
f3911b377d
2 changed files with 5 additions and 5 deletions
|
@ -17,7 +17,7 @@ from sqlalchemy.sql import text
|
||||||
def upgrade():
|
def upgrade():
|
||||||
op.add_column('order', sa.Column(
|
op.add_column('order', sa.Column(
|
||||||
'slug',
|
'slug',
|
||||||
sa.String(length=7),
|
sa.String(length=8),
|
||||||
nullable=False,
|
nullable=False,
|
||||||
# Default: random alphanumerical string
|
# Default: random alphanumerical string
|
||||||
server_default=text('SUBSTRING(MD5(RAND()) FROM 1 FOR 7)')
|
server_default=text('SUBSTRING(MD5(RAND()) FROM 1 FOR 7)')
|
||||||
|
|
|
@ -11,12 +11,12 @@ from utils import first
|
||||||
from .database import db
|
from .database import db
|
||||||
from .user import User
|
from .user import User
|
||||||
|
|
||||||
BASE58_ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
BASE31_ALPHABET = '23456789abcdefghjkmnpqrstuvwxyz'
|
||||||
|
|
||||||
def generate_slug():
|
def generate_slug():
|
||||||
secret = ''.join(secrets.choice(BASE58_ALPHABET) for i in range(7))
|
secret = ''.join(secrets.choice(BASE31_ALPHABET) for i in range(8))
|
||||||
while Order.query.filter(Order.slug == secret).first() is not None:
|
while Order.query.filter(Order.slug == secret).first() is not None:
|
||||||
secret = ''.join(secrets.choice(BASE58_ALPHABET) for i in range(7))
|
secret = ''.join(secrets.choice(BASE31_ALPHABET) for i in range(8))
|
||||||
return secret
|
return secret
|
||||||
|
|
||||||
class Order(db.Model):
|
class Order(db.Model):
|
||||||
|
@ -28,7 +28,7 @@ class Order(db.Model):
|
||||||
starttime = db.Column(db.DateTime)
|
starttime = db.Column(db.DateTime)
|
||||||
stoptime = db.Column(db.DateTime)
|
stoptime = db.Column(db.DateTime)
|
||||||
public = db.Column(db.Boolean, default=True)
|
public = db.Column(db.Boolean, default=True)
|
||||||
slug = db.Column(db.String(7), default=generate_slug, unique=True)
|
slug = db.Column(db.String(8), default=generate_slug, unique=True)
|
||||||
association = db.Column(db.String(120), nullable=False, server_default="")
|
association = db.Column(db.String(120), nullable=False, server_default="")
|
||||||
|
|
||||||
items = db.relationship("OrderItem", backref="order", lazy="dynamic")
|
items = db.relationship("OrderItem", backref="order", lazy="dynamic")
|
||||||
|
|
Loading…
Reference in a new issue