Exemplo n.º 1
0
def do_add_link():
    req = request.form if request.method == 'POST' else request.args
    form = forms.AddLink(req, referer=get_referer())

    data = form.data
    data['userid'] = current_user.userid

    options = {
        'button_label':
        'Add Link',
        'post_view':
        req.get('post_view')
        if req.get('post_view') else url_for('do_add_link'),
    }

    link = Link(data)

    if request.method == 'POST' or request.args.get('submit') == '1 ':

        if link.already_exists():
            flash('This link already exists.  Try editing it instead.',
                  'error')
            return redirect(url_for('do_edit_link', linkid=link.linkid))

        taglist = form.tags.data.split(',') if form.tags.data else []
        link.set_tags(taglist)

        if form.validate():
            link.save()
            redir_target = link.url if form.redirect_to_target else get_referer(
            )
            return redirect(redir_target)
        flash('Invalid link submission', 'error')
        return str(form.errors)

    tags = Tag.get_by_user(current_user.userid)

    return render_template("link_add.html",
                           pageoptions=get_default_data(),
                           form=form,
                           link=link,
                           tags=tags,
                           options=options)
Exemplo n.º 2
0
Arquivo: db.py Projeto: 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()