コード例 #1
0
ファイル: database.py プロジェクト: lmorchard/Bookie
def db_init_bookmark():
    """install the initial bookmark in a new install"""
    require('hosts', provided_by=[sample])
    require('ini', provided_by=[sample])

    parse_ini(env["ini_file"])
    from datetime import datetime
    import transaction
    from bookie.models import initialize_sql
    from sqlalchemy import create_engine

    engine = create_engine(env.ini.get('app:bookie', 'sqlalchemy.url'))
    initialize_sql(engine)

    from bookie.models import DBSession
    from bookie.models import Bmark

    bmark_us = Bmark(u'http://bmark.us',
                     u'admin',
                     desc=u"Bookie Website",
                     ext= u"Bookie Documentation Home",
                     tags = u"bookmarks")

    bmark_us.stored = datetime.now()
    bmark_us.updated = datetime.now()
    DBSession.add(bmark_us)
    DBSession.flush()
    transaction.commit()
コード例 #2
0
    def test_unique_ct(self):
        """Verify that our unique count method is working"""
        ct = 5
        common = 'testing.com'
        users = []
        for i in range(ct):
            user = User()
            user.username = gen_random_word(10)
            DBSession.add(user)
            users.append(user)

        for i in range(ct - 2):
            b = Bmark(url=gen_random_word(12), username=users[i].username)
            DBSession.add(b)

        # Add in our dupes
        c = Bmark(url=common, username=users[3].username)
        DBSession.add(c)
        DBSession.flush()

        d = Bmark(url=common, username=users[4].username)
        DBSession.add(d)
        DBSession.flush()

        ct = BmarkMgr.count(distinct=True)
        eq_(4, ct, 'We should have a total of 4: ' + str(ct))
コード例 #3
0
    def test_per_user(self):
        """We should only get a pair of results for this single user"""
        ct = 5
        common = 'testing.com'
        user = User()
        user.username = gen_random_word(10)
        DBSession.add(user)

        usercommon = User()
        usercommon.username = common
        DBSession.add(usercommon)

        for i in range(ct - 2):
            b = Bmark(url=gen_random_word(12), username=user.username)
            DBSession.add(b)

        # add in our dupes
        c = Bmark(
            url=gen_random_word(10),
            username=usercommon.username,
        )
        DBSession.add(c)
        DBSession.flush()

        d = Bmark(
            url=gen_random_word(10),
            username=usercommon.username,
        )
        DBSession.add(d)
        DBSession.flush()

        ct = BmarkMgr.count(username=usercommon.username)
        eq_(2, ct, 'We should have a total of 2: ' + str(ct))
コード例 #4
0
def upgrade(migrate_engine):
    """By default start all installs out with a bookmark to bmark.us

    It's cheesy, but helps with testing to have some base data and is good for
    pubbing the links

    """
    from datetime import datetime
    import transaction
    from bookie.models import initialize_sql

    initialize_sql(migrate_engine)

    from bookie.models import DBSession
    from bookie.models import Bmark

    bmark_us = Bmark('http://bmark.us',
                     desc="Bookie Website",
                     ext= "Bookie Documentation Home",
                     tags = "bookmarks")

    bmark_us.stored = datetime.now()
    bmark_us.updated = datetime.now()
    DBSession.add(bmark_us)
    DBSession.flush()
    transaction.commit()
コード例 #5
0
def upgrade(migrate_engine):
    """By default start all installs out with a bookmark to bmark.us

    It's cheesy, but helps with testing to have some base data and is good for
    pubbing the links

    """
    from datetime import datetime
    import transaction
    from bookie.models import initialize_sql

    initialize_sql(migrate_engine)

    from bookie.models import DBSession
    from bookie.models import Bmark

    bmark_us = Bmark('http://bmark.us',
                     desc="Bookie Website",
                     ext="Bookie Documentation Home",
                     tags="bookmarks")

    bmark_us.stored = datetime.now()
    bmark_us.updated = datetime.now()
    DBSession.add(bmark_us)
    DBSession.flush()
    transaction.commit()
コード例 #6
0
ファイル: test_bcelery.py プロジェクト: wrestcody/Bookie
 def __create_bookmark(self, url, username):
     """Helper that creates a bookmark object with a random tag"""
     b = Bmark(
         url=url,
         username=username
     )
     tagname = gen_random_word(5)
     b.tags[tagname] = Tag(tagname)
     return b
コード例 #7
0
ファイル: __init__.py プロジェクト: Cfhansen/Bookie
 def __create_bookmark(self, url, username):
     """Helper that creates a bookmark object with a random tag"""
     b = Bmark(
         url=url,
         username=username
     )
     tagname = gen_random_word(5)
     b.tags[tagname] = Tag(tagname)
     return b
コード例 #8
0
ファイル: test_webviews.py プロジェクト: BraindeadCrew/Bookie
    def _add_bmark(self):
        # setup the default bookie bookmark
        bmark_us = Bmark(u'http://bmark.us',
                         username=u"admin",
                         desc=u"Bookie Website",
                         ext=u"Bookie Documentation Home",
                         tags=u"bookmarks")

        bmark_us.stored = datetime.now()
        bmark_us.updated = datetime.now()
        transaction.commit()
コード例 #9
0
ファイル: factory.py プロジェクト: vackup/Bookie
def make_bookmark(user=None):
    """Generate a fake bookmark for testing use."""
    bmark = Bmark(random_url(), username="******", desc=random_string(), ext=random_string(), tags=u"bookmarks")

    if user:
        bmark.username = user.username
        bmark.user = user

    DBSession.add(bmark)
    DBSession.flush()
    return bmark
コード例 #10
0
ファイル: test_webviews.py プロジェクト: wrestcody/Bookie
    def _add_bmark(self):
        # setup the default bookie bookmark
        bmark_us = Bmark(u'http://bmark.us',
                         username=u"admin",
                         desc=u"Bookie Website",
                         ext=u"Bookie Documentation Home",
                         tags=u"bookmarks")

        bmark_us.stored = datetime.now()
        bmark_us.updated = datetime.now()
        transaction.commit()
コード例 #11
0
ファイル: test_webviews.py プロジェクト: BraindeadCrew/Bookie
    def _add_bmark_wt_desc(self):
        #setup the default google bookmark
        bmark_us = Bmark(u'http://google.com',
                         username=u"admin",
                         desc=u"",
                         ext=u"Google Search Engine",
                         tags=u"bookmarks")

        bmark_us.stored = datetime.now()
        bmark_us.updated = datetime.now()
        DBSession.add(bmark_us)
        transaction.commit()
コード例 #12
0
ファイル: test_webviews.py プロジェクト: wrestcody/Bookie
    def _add_bmark_wt_desc(self):
        #setup the default google bookmark
        bmark_us = Bmark(u'http://google.com',
                         username=u"admin",
                         desc=u"",
                         ext=u"Google Search Engine",
                         tags=u"bookmarks")

        bmark_us.stored = datetime.now()
        bmark_us.updated = datetime.now()
        DBSession.add(bmark_us)
        transaction.commit()
コード例 #13
0
    def test_total_ct(self):
        """Verify that our total count method is working"""
        ct = 5
        user = User()
        user.username = gen_random_word(10)
        DBSession.add(user)
        for i in range(ct):
            b = Bmark(url=gen_random_word(12), username=user.username)
            b.hash_id = gen_random_word(3)
            DBSession.add(b)

        ct = BmarkMgr.count()
        eq_(5, ct, 'We should have a total of 5: ' + str(ct))
コード例 #14
0
    def _add_bmark(self):
        # setup the default bookie bookmark
        import logging
        log = logging.getLogger(__name__)
        log.error('called to add bmark')
        bmark_us = Bmark('http://bmark.us',
                         desc="Bookie Website",
                         ext="Bookie Documentation Home",
                         tags="bookmarks")

        bmark_us.stored = datetime.now()
        bmark_us.updated = datetime.now()
        DBSession.add(bmark_us)
        transaction.commit()
コード例 #15
0
ファイル: __init__.py プロジェクト: akn/Bookie
    def _add_bmark(self):
        # setup the default bookie bookmark
        import logging
        log = logging.getLogger(__name__)
        log.error('called to add bmark')
        bmark_us = Bmark('http://bmark.us',
                         desc="Bookie Website",
                         ext= "Bookie Documentation Home",
                         tags = "bookmarks")

        bmark_us.stored = datetime.now()
        bmark_us.updated = datetime.now()
        DBSession.add(bmark_us)
        transaction.commit()
コード例 #16
0
ファイル: factory.py プロジェクト: xuanhan863/Bookie
def make_bookmark(user=None):
    """Generate a fake bookmark for testing use."""
    bmark = Bmark(random_url(),
                  username="******",
                  desc=random_string(),
                  ext=random_string(),
                  tags=u"bookmarks")

    if user:
        bmark.username = user.username
        bmark.user = user

    DBSession.add(bmark)
    DBSession.flush()
    return bmark
コード例 #17
0
ファイル: test_bmarkmgr.py プロジェクト: cambot/Bookie
    def test_total_ct(self):
        """Verify that our total count method is working"""
        ct = 5
        user = User()
        user.username = gen_random_word(10)
        DBSession.add(user)
        for i in range(ct):
            b = Bmark(
                url=gen_random_word(12),
                username=user.username
            )
            b.hash_id = gen_random_word(3)
            DBSession.add(b)

        ct = BmarkMgr.count()
        eq_(5, ct, 'We should have a total of 5: ' + str(ct))
コード例 #18
0
def edit_error(request):
    rdict = request.matchdict
    params = request.params
    post = request.POST

    with ReqAuthorize(request, username=rdict['username']):
        if 'new' in request.url:
            try:
                bmark = BmarkMgr.store(post['url'], request.user.username,
                                       post['description'], post['extended'],
                                       post['tags'])

                # Assign a task to fetch this pages content and parse it out
                # for storage and indexing.
                DBSession.flush()
                tasks.fetch_bmark_content.delay(bmark.bid)

            except InvalidBookmark, exc:
                # There was an issue using the supplied data to create a new
                # bookmark. Send the data back to the user with the error
                # message.
                bmark = Bmark(post['url'],
                              request.user.username,
                              desc=post['description'],
                              ext=post['extended'],
                              tags=post['tags'])

                return {
                    'new': True,
                    'bmark': bmark,
                    'message': exc.message,
                    'user': request.user,
                }

        else:
コード例 #19
0
ファイル: bmarks.py プロジェクト: wrestcody/Bookie
def edit(request):
    """Manual add a bookmark to the user account

    Can pass in params (say from a magic bookmarklet later)
    url
    description
    extended
    tags

    """
    rdict = request.matchdict
    params = request.params
    new = False

    with ReqAuthorize(request, username=rdict['username']):

        if 'hash_id' in rdict:
            hash_id = rdict['hash_id']
        elif 'hash_id' in params:
            hash_id = params['hash_id']
        else:
            hash_id = None

        if hash_id:
            bmark = BmarkMgr.get_by_hash(hash_id, request.user.username)

            if bmark is None:
                return HTTPNotFound()
        else:
            # hash the url and make sure that it doesn't exist
            url = params.get('url', u"")
            if url != u"":
                new_url_hash = generate_hash(url)

                test_exists = BmarkMgr.get_by_hash(new_url_hash,
                                                   request.user.username)

                if test_exists:
                    location = request.route_url(
                        'user_bmark_edit',
                        hash_id=new_url_hash,
                        username=request.user.username)
                    return HTTPFound(location)

            new = True
            desc = params.get('description', None)
            bmark = Bmark(url, request.user.username, desc=desc)

        tag_suggest = TagMgr.suggestions(
            url=bmark.hashed.url,
            username=request.user.username
        )

        return {
            'new': new,
            'bmark': bmark,
            'user': request.user,
            'tag_suggest': tag_suggest,
        }
コード例 #20
0
from datetime import datetime
from ConfigParser import ConfigParser
from os import path

from bookie.models import initialize_sql


if __name__ == "__main__":
    ini = ConfigParser()
    ini_path = path.join(path.dirname(path.dirname(path.dirname(__file__))),
        'bookie.ini')

    ini.readfp(open(ini_path))
    initialize_sql(dict(ini.items("app:bookie")))

    from bookie.models import DBSession
    from bookie.models import Bmark

    bmark_us = Bmark(u'http://bmark.us',
                     u'admin',
                     desc=u'Bookie Website',
                     ext= u'Bookie Documentation Home',
                     tags = u'bookmarks')

    bmark_us.stored = datetime.now()
    bmark_us.updated = datetime.now()
    DBSession.add(bmark_us)
    DBSession.flush()
    transaction.commit()