Beispiel #1
0
def do_add_user():
    if not app.config['ALLOW_REGISTRATION']:
        abort(403)

    form = forms.AddUser(request.form)
    if form.validate_on_submit():
        usr = User()
        usr.username = request.form['username']
        usr.set_password(request.form['password'])
        usr.signup_ip = request.remote_addr
        usr.save()
        return redirect(url_for('show_index'))
    return render_template("new_user.html",
                           form=form,
                           pageoptions=get_default_data())
Beispiel #2
0
Datei: db.py Projekt: pageer/lnto
def create_test_data():
    link_data = [
        {
            'name': 'Foo',
            'userid': 1,
            'url': 'http://www.example.com/',
            'shortname': 'foo',
            'added': datetime(2013, 2, 1, 12, 13, 14),
            'description': 'This is a test',
            'tags': 'test1, test2'
        },
        {
            'name': 'Foo2',
            'userid': 1,
            'url': 'http://www.example.com/test',
            'shortname': 'foo2',
            'added': datetime(2013, 2, 2, 12, 13, 14),
            'description': 'This is a test again',
            'tags': 'test1, blah'
        },
        {
            'name': 'Foo3',
            'userid': 1,
            'url': 'http://www.example.com/test3',
            'description': 'This is a test again',
            'added': datetime(2013, 2, 3, 12, 13, 14),
            'tags': 'test1, blah',
            'is_public': False
        },
        {
            'name': 'User2Foo',
            'userid': 2,
            'url': 'http://www.example.com/test4',
            'description': 'This is a test again',
            'added': datetime(2013, 2, 3, 15, 16, 17),
            'tags': 'test1',
        },
        {
            'name': 'User2Foo2',
            'userid': 2,
            'url': 'http://www.example.com/test5',
            'description': 'This is a test again',
            'added': datetime(2013, 1, 2, 12, 13, 14),
            'tags': 'privatetag',
            'is_public': False
        },
        {
            'name': 'User3Foo3',
            'userid': 3,
            'url': 'http://www.example.com/test6',
            'description': 'This is a test again',
            'added': datetime(2013, 1, 2, 12, 13, 14),
            'tags': '',
            'is_public': False
        },
        {
            'name': 'User4Foo4',
            'userid': 4,
            'url': 'http://www.example.com/test7',
            'description': 'This is a test again',
            'added': datetime(2013, 1, 2, 12, 13, 14),
            'tags': '',
            'is_public': True
        },
        {
            'name': 'User3Foo3',
            'userid': 3,
            'url': 'http://www.example.com/test6',
            'description': 'This is a test again',
            'added': datetime(2013, 1, 2, 12, 13, 14),
            'tags': 'userid3',
            'is_public': False
        },
        {
            'name': 'User4Foo4',
            'userid': 4,
            'url': 'http://www.example.com/test7',
            'description': 'This is a test again',
            'added': datetime(2013, 1, 2, 12, 13, 14),
            'tags': 'userid4',
            'is_public': True
        },
    ]
    user_data = [{
        'username': '******',
        'password': '******'
    }, {
        'username': '******',
        'password': '******'
    }, {
        'username': '******',
        'password': '******'
    }, {
        'username': '******',
        'password': '******'
    }]
    hit_data = [{
        'linkid': 1,
        'userid': 1,
        'ts': datetime(2013, 1, 2, 12, 13, 14)
    }, {
        'linkid': 1,
        'userid': 2,
        'ts': datetime(2013, 3, 4, 17, 18, 19)
    }, {
        'linkid': 2,
        'userid': 2,
        'ts': datetime(2013, 3, 4, 17, 18, 10)
    }, {
        'linkid': 4,
        'userid': 1,
        'ts': datetime(2013, 2, 3, 16, 17, 18)
    }]

    for user in user_data:
        user_obj = User(user)
        user_obj.set_password(user['password'])
        user_obj.save()

    for link in link_data:
        link_obj = Link(link)
        link_obj.save()

    for hit in hit_data:
        hit_obj = LinkHit(hit)
        lnto.appdb.session.add(hit_obj)
        lnto.appdb.session.commit()