Exemplo n.º 1
0
def category_add():
    error_fields = []

    if request.method == 'POST':
        name = request.form['name'].strip()
        if len(name) <= 0:
            error_fields.append('name')

        published = request.form.get('published', False)
        if published is not False:
            published = True

        if len(error_fields) <= 0:
            slug = slugify(name)

            # ensure slug is unique, add - until it is
            while Category.query.filter_by(slug=slug).count() > 0:
                slug += '-'

            db.session.add(Category(name, slug, published))
            db.session.commit()

            cache.set('blog_categories', list_categories())

            flash("Category added.")
            return redirect(url_for('admin.categories'))

    return render_template('admin/category_add.html',
                           error_fields=error_fields)
Exemplo n.º 2
0
def initdb(username, password):
    db.create_all()

    cats = [
        Category("Events", "events", True),
        Category("Music Adds", "music-adds", True),
        Category("Programming", "programming", True),
        Category("Updates", "station-updates", True),
        Category("Woove", "woove", True)
    ]
    for cat in cats:
        db.session.add(cat)

    # Create the first account
    user = User(str(username), str(username), "{0}@localhost".format(username))
    user.set_password(str(password))
    db.session.add(user)
Exemplo n.º 3
0
def initdb(username, password):
    """Initialize the database."""
    click.echo("Initialize the database...")

    db.create_all()

    dj = DJ(u"Automation", u"Automation", False)
    db.session.add(dj)
    db.session.commit()

    cats = [
        Category(u"Events", u"events", True),
        Category(u"Music Adds", u"music-adds", True),
        Category(u"Programming", u"programming", True),
        Category(u"Updates", u"station-updates", True),
        Category(u"Woove", u"woove", True)
    ]
    for cat in cats:
        db.session.add(cat)

    # Create the first account
    click.echo("Create {0} user...".format(username))
    user = User(unicode(username), unicode(username),
                u"{0}@localhost".format(username))
    user.set_password(unicode(password))
    db.session.add(user)

    # The first Rotation is always the default
    db.session.add(Rotation(u"None"))
    map(
        db.session.add,
        map(Rotation,
            [u"Metal", u"New Music", u"Jazz", u"Rock", u"Americana"]))

    db.session.commit()

    click.echo("Database initialized.")
Exemplo n.º 4
0
#!/usr/bin/env python2

from wuvt import db
from wuvt.blog.models import Category
from wuvt.trackman.models import DJ, Rotation
from wuvt.models import User

db.create_all()

dj = DJ(u"Automation", u"Automation", False)
db.session.add(dj)
db.session.commit()

cats = [
    Category(u"Events", u"events", True),
    Category(u"Music Adds", u"music-adds", True),
    Category(u"Programming", u"programming", True),
    Category(u"Updates", u"station-updates", True),
    Category(u"Woove", u"woove", True)
]
for cat in cats:
    db.session.add(cat)

# There must be a user called 'admin'. This is hardcoded in everything to be the superuser.
user = User(u"admin", u"admin", u"*****@*****.**")
user.set_password(u"Password1!")
db.session.add(user)

# The first Rotation is always the default
db.session.add(Rotation(u"None"))
map(db.session.add,