Exemple #1
0
def create_user(username, email, password):
    user = User(
        username=username,
        email=email,
        is_superuser=True,
        is_confirmed=True,
    )
    user.set_password(password)
    user.save()
Exemple #2
0
def create_user(username, email, password):
    if username is None:
        username = input('Username(default admin):') or 'admin'
    if email is None:
        email = input('Email:')
    if password is None:
        password = getpass('Password:')
    user = User(
        username=username, email=email, is_superuser=True, is_confirmed=True)
    user.set_password(password)
    user.save()
Exemple #3
0
def add_author(username):
    username = "******"
    email = "*****@*****.**"
    author = User.query.filter_by(username=username).first()
    if not author:
        author = User(
            username=username,
            email=email,
            is_superuser=True,
            is_confirmed=True,
        )
        author.set_password(getpass("Password: "))
        author.save()
    return author
Exemple #4
0
def write_to_blog(attr, file_type='org'):
    _author = attr['author']
    _category = attr['category']
    _tags = attr['tags'].split(',')
    _title = attr['title']
    _date = attr['date']
    _content = attr['content']

    user = User.query.filter_by(username=_author).first()
    if not user:
        user = User(username=_author, email='*****@*****.**')
        user.set_password('123123')
        user.save()

    category = Category.query.filter_by(name=_category).first()
    if not category:
        category = Category(name=_category)
        category.save()

    tags = []
    for _tag in _tags:
        tag = Tag.query.filter_by(name=_tag).first()
        if not tag:
            tag = Tag(name=_tag)
            tag.save()
        tags.append(tag)

    try:
        _date = datetime.strptime(_date, '%Y-%m-%d'),
    except ValueError:
        _date = datetime.strptime(_date, '%Y-%m-%d %H:%M:%S'),

    blog = Blog.query.filter_by(title=_title).first()
    if not blog:
        blog = Blog(
            title=_title,
            category_id=category.id,
            content=_content,
            created_at=_date,
            tags=tags,
            content_type='1' if file_type == 'org' else '0',
            user_id=user.id)
        blog.save()

    return blog