Beispiel #1
0
def new_log():
    form = NewLogForm()
    
    if form.validate_on_submit():
        newlog = Log(subject=form.subject.data,
                     link=form.link.data,
                     notes=form.notes.data,
                     user_id=current_user.id)
        newlog.set_tags(form.tag.data)
        newlog.save()
        return redirect(url_for('log.index'))

    else:
        return render_template("log/newlog.html", form=form)
Beispiel #2
0
def load_seed_data():
    users = [
        ['Daniel Crockford', '*****@*****.**', 'sweetlemon', ''],
        ['Marie Singer', '*****@*****.**', 'crazysale', '']
    ]

    for u in users:
        name, email, pw, pic = u
        user = User(name=name, email=email, password=pw, picture=pic)
        user.verified = True
        user.save()

    tags = ['sql','python','programming']

    for t in tags:
        tag = Tag(name=t)
        tag.save()

    logs = [
        ["sqlalchemy ORM tutorial", 
        "http://docs.sqlalchemy.org/en/rel_1_0/orm/tutorial.html#building-a-relationship",
        "ORM is built on top of expression language.",
        1,
        datetime.strptime('2015-01-02 11:33', '%Y-%m-%d %H:%M')],
        ["Python tutorial - looping",
        "https://docs.python.org/2/tutorial/datastructures.html#looping-techniques",
        "",
        2,
        datetime.strptime('2015-07-02 18:06', '%Y-%m-%d %H:%M')]
    ]

    for l in logs:
        subject, link, notes, user_id, date = l
        log = Log(subject=subject, link=link, notes=notes, user_id=user_id,
            create_date=date)
        t_ids = sample([1,2,3], 2)
        for t in t_ids:
            tag = Tag.query.get(t)
            log.tag.append(tag)
        log.save()