예제 #1
0
파일: importer.py 프로젝트: pageer/lnto
 def __init__(self, markup, import_type=None, user=None):
     self.data = markup
     self.import_type = import_type
     self.make_soup()
     self.user = user
     if self.user is None:
         self.user = User.get_logged_in()
예제 #2
0
def show_user_tag_list(username):
    if username is None:
        username = current_user.username
        user = current_user
    elif current_user and username == current_user.username:
        user = current_user
    else:
        user = User.get_by_username(username)

    user_owned = current_user and current_user.username == username

    if user_owned:
        tags = Tag.get_cloud_by_user(user.userid)
        title = "My Tags"
    else:
        tags = Tag.get_public_by_user(user.userid)
        title = 'Tags for %s' % username

    return render_template('tag_index.html',
                           pageoptions=get_default_data(),
                           tags=tags,
                           curr_user=current_user,
                           page_title=title,
                           section_title=title,
                           user_owned=user_owned,
                           user=user)
예제 #3
0
def show_user(username):
    usr = User.get_by_username(username)
    links = Link.get_public_by_most_recent(usr.userid, 30)
    tags = Tag.get_public_by_user(usr.userid)
    return render_template('public_dashboard.html',
                           pageoptions=get_default_data(),
                           tags=tags,
                           links=links,
                           user=usr,
                           curr_user=current_user)
예제 #4
0
def show_all_user_tagged(name, username):
    user = User.get_by_username(username)
    links = Link.get_public_by_tag(name, user.userid)
    title = 'Links for tag "%s" by %s' % (name, user.username)
    return render_template('link_index.html',
                           pageoptions=get_default_data(),
                           user=user,
                           curr_user=current_user,
                           links=links,
                           section_title=title,
                           page_title=title)
예제 #5
0
파일: api.py 프로젝트: pageer/lnto
def api_remove_module():
    usr = User.get_logged_in()
    dash = Dashboard(usr.userid)
    modid = request.form.get('moduleid')

    if not modid:
        return json_error('No moduleid given')

    if dash.remove_module(modid):
        return json_success()
    return json_error('Failed to remove module')
예제 #6
0
파일: api.py 프로젝트: pageer/lnto
def validate_link(link, user=None):
    if not user:
        user = User.get_logged_in()

    if not link:
        return json_error('That link does not exist.')

    if not link.is_owner(user):
        return json_error('You do not have permission to delete this link.')

    return None
예제 #7
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())
예제 #8
0
def do_login():
    #if current_user:
    #return redirect(url_for('show_index'))
    if request.method == 'POST':
        valid = False
        curr_user = User.get_by_username(request.form.get('username'))
        if curr_user:
            valid = curr_user.check_password(request.form.get('password'))
        if valid:
            login_user(curr_user)
            return make_response(
                redirect(request.form.get('referer') or url_for('show_index')))
        error = 'Either your username or password is wrong'
        return render_template('login.html',
                               pageoptions=get_default_data(),
                               error=error)
    return render_template('login.html', pageoptions=get_default_data())
예제 #9
0
def show_user_index(username):
    if username is None:
        usr = current_user
    else:
        usr = User.get_by_username(username)

    if not usr:
        abort(404)

    if usr is current_user:
        links = Link.get_by_user(current_user.userid)
    else:
        links = Link.get_public_by_user(usr.userid)
    return render_template('link_index.html',
                           pageoptions=get_default_data(),
                           links=links,
                           user=current_user)
예제 #10
0
파일: api.py 프로젝트: pageer/lnto
def api_save_positions():
    usr = User.get_logged_in()
    dash = Dashboard(usr.userid)
    modids = request.form.getlist('moduleid')
    saved_mods = dash.get_modules_by_id()

    i = 0

    for mod in modids:
        saved_mods[int(mod)].position = i
        appdb.session.add(saved_mods[int(mod)])
        i += 1

    try:
        appdb.session.commit()
        return json_success()
    except Exception as ex:
        return json_error(str(ex))
예제 #11
0
 def test_get_by_username_nonexistent(self):
     usr = User.get_by_username('thisuserdoesnotexist')
     self.assertEqual(usr, None)
예제 #12
0
 def test_get_by_username_exists(self):
     usr = User.get_by_username('testuser')
     self.assertEqual(usr.username, 'testuser')
예제 #13
0
 def make_user(self, userid):
     usr = User()
     usr.userid = userid
     return usr
예제 #14
0
파일: db.py 프로젝트: 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()