Exemple #1
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()
    user = User(name='demo', email='*****@*****.**', password='******', website='', location='', bio='')
    db.session.add(user)
    db.session.commit()
Exemple #2
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()

    # Init/reset data.

    role_user = UserRole(name=u'user')
    role_admin = UserRole(name=u'admin')
    db.session.add(role_user)
    db.session.add(role_admin)
    db.session.commit()

    inactivated = UserStatus(name=u'inactivated')
    activated = UserStatus(name=u'activated')
    frozen = UserStatus(name=u'frozen')
    deleted = UserStatus(name=u'deleted')
    db.session.add(inactivated)
    db.session.add(activated)
    db.session.add(frozen)
    db.session.add(deleted)
    db.session.commit()

    demo = User(
        name=u'demo',
        email=u'*****@*****.**',
        password=u'123456',
        role=role_user,
        status=activated,
        user_detail=UserDetail(
            real_name=u'Demo Guy',
            age=10,
            url=u'http://demo.example.com',
            deposit=100.00,
            location=u'Hangzhou',
            bio=u'Demo Guy is ... hmm ... just a demo guy.',
        ),
    )
    admin = User(
        name=u'admin',
        email=u'*****@*****.**',
        password=u'123456',
        role=role_admin,
        status=activated,
        user_detail=UserDetail(
            real_name=u'admin Guy',
            age=10,
            url=u'http://admin.example.com',
            deposit=100.00,
            location=u'Hangzhou',
            bio=u'admin Guy is ... hmm ... just a admin guy.',
        ),
    )
    db.session.add(demo)
    db.session.add(admin)
    db.session.commit()
Exemple #3
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()
    
    # Init/reset data.

    role_user = UserRole(name=u'user')
    role_admin = UserRole(name=u'admin')
    db.session.add(role_user)
    db.session.add(role_admin)
    db.session.commit()

    inactivated = UserStatus(name=u'inactivated')
    activated = UserStatus(name=u'activated')
    frozen = UserStatus(name=u'frozen')
    deleted = UserStatus(name=u'deleted')
    db.session.add(inactivated)
    db.session.add(activated)
    db.session.add(frozen)
    db.session.add(deleted)
    db.session.commit()
    
    demo = User(
            name = u'demo', 
            email = u'*****@*****.**', 
            password = u'123456', 
            role = role_user,
            status = activated,
            user_detail = UserDetail(
                real_name = u'Demo Guy',
                age = 10,
                url = u'http://demo.example.com', 
                deposit = 100.00,
                location = u'Hangzhou', 
                bio = u'Demo Guy is ... hmm ... just a demo guy.',
                ),
            )
    admin = User(
            name = u'admin', 
            email = u'*****@*****.**', 
            password = u'123456', 
            role = role_admin,
            status = activated,
            user_detail = UserDetail(
                real_name = u'admin Guy',
                age = 10,
                url = u'http://admin.example.com', 
                deposit = 100.00,
                location = u'Hangzhou', 
                bio = u'admin Guy is ... hmm ... just a admin guy.',
                ),
            )
    db.session.add(demo)
    db.session.add(admin)
    db.session.commit()
Exemple #4
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()

    admin = User(
            name=u'admin',
            email=u'*****@*****.**',
            password=u'123456',
            role_code=ADMIN,
            status_code=ACTIVE)
    db.session.add(admin)
    db.session.commit()
Exemple #5
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()

    admin = User(
        name=u'admin',
        fullname=u'Agador Spartacus',
        email=u'*****@*****.**',
        password=u'123456',
        role_code=ADMIN,
        status_code=ACTIVE,
        gender_code=MALE,
        bio=u'FSU Grad. Go Noles!')
    db.session.add(admin)
    db.session.commit()
Exemple #6
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()

    db.session.add(Role(
        name=u'admin',
        description='Administrator role'
    ))

    db.session.add(Role(
        name=u'staff',
        description='Staff role'
    ))

    db.session.add(Role(
        name=u'user',
        description='User role'
    ))
    db.session.commit()


    ds = app.security.datastore
    admin = ds.create_user(
	    email='admin',
	    name='Administrator',
	    password=u'123456',
	    roles=['admin', 'user'],
	    status_code=ACTIVE,
	    confirmed_at=datetime.utcnow(),
	    user_detail=UserDetail(
                sex_code=MALE,
                age=10,
                url=u'http://admin.example.com',
                deposit=100.00,
                location=u'Hangzhou',
                bio=u'admin Guy is ... hmm ... just a admin guy.')
    )

    db.session.add(admin)
    db.session.commit()
Exemple #7
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()
    
    # Init/reset data.
    role_user = Role(name=u'user')
    role_admin = Role(name=u'admin')
    db.session.add(role_user)
    db.session.add(role_admin)
    db.session.commit()
    
    demo = User(
            name = u'demo', 
            email = u'*****@*****.**', 
            password = u'123456', 
            role = role_user,
            user_detail = UserDetail(
                real_name = u'Demo Guy',
                age = 10,
                url = u'http://demo.example.com', 
                location = u'Hangzhou', 
                bio = u'Demo Guy is ... hmm ... just a demo guy.',
                ),
            )
    admin = User(
            name = u'admin', 
            email = u'*****@*****.**', 
            password = u'123456', 
            role = role_admin,
            user_detail = UserDetail(
                real_name = u'admin Guy',
                age = 10,
                url = u'http://admin.example.com', 
                location = u'Hangzhou', 
                bio = u'admin Guy is ... hmm ... just a admin guy.',
                ),
            )
    db.session.add(demo)
    db.session.add(admin)
    db.session.commit()
Exemple #8
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()

    admin = User(name=u'admin',
                 email=u'*****@*****.**',
                 password=u'123456',
                 role_code=ADMIN,
                 status_code=ACTIVE,
                 user_detail=UserDetail(
                     sex_code=MALE,
                     age=10,
                     url=u'http://admin.example.com',
                     deposit=100.00,
                     location=u'Hangzhou',
                     bio=u'admin Guy is ... hmm ... just a admin guy.'))
    db.session.add(admin)
    db.session.commit()
Exemple #9
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()

    admin = User(
            name=u'admin',
            email=u'*****@*****.**',
            password=u'123456',
            role_code=ADMIN,
            status_code=ACTIVE,
            user_detail=UserDetail(
                sex_code=MALE,
                age=10,
                url=u'http://admin.example.com',
                deposit=100.00,
                location=u'Tallahassee',
                bio=u'admin Guy is ... hmm ... just a admin guy.'))
    db.session.add(admin)
    db.session.commit()
Exemple #10
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()

    #create admin
    u = User(
            username = '******',
            email = '*****@*****.**',
            first_name = 'admin',
            last_name = 'admin',
            avatar = '',
            gender = 'm',
            created = datetime.datetime.now(),
            last_login = datetime.datetime.now(),
            activated = True,
            admin = True
        )
    u.set_password('admin')
    u.save()
Exemple #11
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()

    calum = User(
            name=u'calum',
            email=u'*****@*****.**',
            password=u'password',
            role_code=ADMIN,
            status_code=ACTIVE,
            user_detail=UserDetail(
                sex_code=MALE,
                age=10,
                url=u'http://www.calumjeadie.com',
                deposit=100.00,
                location=u'UK',
                bio=u''))

    db.session.add(calum)
    db.session.commit()
Exemple #12
0
def initdb():
    """Init/reset database."""

    try:
        db.drop_all()
    except sqlalchemy.exc.OperationalError:
        URI = app.config['SQLALCHEMY_DATABASE_URI'][:app.config['SQLALCHEMY_DATABASE_URI'].rfind('/')]
        engine = sqlalchemy.create_engine(URI)
        engine.execute("CREATE DATABASE fbone")

    db.create_all()

    admin = User(
        name=u'admin',
        fullname=u'Agador Spartacus',
        email=u'*****@*****.**',
        password=u'123456',
        role_code=ADMIN,
        status_code=ACTIVE,
        gender_code=MALE,
        bio=u'FSU Grad. Go Noles!')
    db.session.add(admin)
    db.session.commit()
Exemple #13
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()
    # Init/reset data.

    demo = User(
        name=u'demo',
        email=u'*****@*****.**',
        password=u'123456',
        role_id=USER,
        status_id=ACTIVE,
        user_detail=UserDetail(
            age=10,
            url=u'http://demo.example.com',
            deposit=100.00,
            location=u'Hangzhou',
            bio=u'Demo Guy is ... hmm ... just a demo guy.'),
    )
    admin = User(
        name=u'admin',
        email=u'*****@*****.**',
        password=u'123456',
        role_id=ADMIN,
        status_id=ACTIVE,
        user_detail=UserDetail(
            age=10,
            url=u'http://admin.example.com',
            deposit=100.00,
            location=u'Hangzhou',
            bio=u'admin Guy is ... hmm ... just a admin guy.'),
    )
    db.session.add(demo)
    db.session.add(admin)
    db.session.commit()
Exemple #14
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()
    # Init/reset data.

    demo = User(
            name=u'demo', 
            email=u'*****@*****.**', 
            password=u'123456', 
            role_id=USER,
            status_id=ACTIVE,
            user_detail=UserDetail(
                age=10,
                url=u'http://demo.example.com', 
                deposit=100.00,
                location=u'Hangzhou', 
                bio=u'Demo Guy is ... hmm ... just a demo guy.'),
            )
    admin = User(
            name=u'admin', 
            email=u'*****@*****.**', 
            password=u'123456', 
            role_id=ADMIN,
            status_id=ACTIVE,
            user_detail=UserDetail(
                age=10,
                url=u'http://admin.example.com', 
                deposit=100.00,
                location=u'Hangzhou', 
                bio=u'admin Guy is ... hmm ... just a admin guy.'),
            )
    db.session.add(demo)
    db.session.add(admin)
    db.session.commit()
Exemple #15
0
def initdb():
    """Init/reset database."""

    try:
        db.drop_all()
    except sqlalchemy.exc.OperationalError:
        URI = app.config['SQLALCHEMY_DATABASE_URI'][:app.config['SQLALCHEMY_DATABASE_URI'].rfind('/')]
        engine = sqlalchemy.create_engine(URI)
        engine.execute("CREATE DATABASE fbone")

    db.create_all()

    # code from original script.py
    #
    # get document from listings page
    url = 'https://tallahassee.craigslist.org/search/jjj?employment_type=2'
    web_page = urlopen(url).read()
    soup = BeautifulSoup(web_page, 'lxml')

    # run through each posting on listings page
    for post in soup.find_all('a', class_='hdrlnk')[:10]:

        # url extension for specific posting page
        link = post['href']

        # get document from individual posting's page
        # open individual posting page
        post_page = urlopen("https://tallahassee.craigslist.org" + link).read()
        # souped posting page
        post_soup = BeautifulSoup(post_page, 'lxml')

        # variables for the data - to be sent through the model
        # id is second appearance of class, read as 'posting id: #########'
        uid = post_soup.find_all(class_='postinginfo')[1].text.split(': ', 1)[1]
        uri = "https://tallahassee.craigslist.org" + link
        created = getCreated(post_soup)
        description = post_soup.find(id='postingbody').text
        title = post_soup.find(id='titletextonly').text
        compensation = getComp(post_soup)
        employment_type = getEmp(post_soup)
        meta = getMeta(post_soup)

        # individual posting instance through the model
        posting = Posting(
            uid=uid,
            uri=uri,
            created=created,
            description=description,
            title=title,
            compensation=compensation,
            employment_type=employment_type,
            meta=meta
        )

        # go through each category for individual posting
        categories = getCategories(post_soup)
        for category_name in categories:

            category = Category().first(name=category_name)
            if not category:
                category = Category(name=category_name)
                # save category using base.py method save
                Category().save(category)

        # save posting using base.py method save
        Posting().save(posting)
Exemple #16
0
    def setUp(self):
        """Reset all tables before testing."""

        db.create_all()
        self.init_data()
Exemple #17
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()

    admin = User(
        name=u"admin",
        email=u"*****@*****.**",
        password=u"123456",
        role_code=ADMIN,
        status_code=ACTIVE,
        user_detail=UserDetail(
            sex_code=MALE,
            age=10,
            url=u"http://admin.example.com",
            deposit=100.00,
            location=u"Hangzhou",
            bio=u"admin Guy is ... hmm ... just a admin guy.",
        ),
    )

    test_user = User(
        name=u"test",
        email=u"*****@*****.**",
        password=u"123456",
        role_code=USER,
        status_code=ACTIVE,
        user_detail=UserDetail(
            sex_code=MALE,
            age=29,
            url=u"http://test.example.com",
            deposit=100.00,
            location=u"Hangzhou",
            bio=u"test user guy..",
        ),
    )

    db.session.add(admin)
    db.session.add(test_user)
    db.session.commit()

    admin = db.session.query(User).filter_by(name="admin").one()

    erkki = db.session.query(User).filter_by(name="test").one()

    body = """
           Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.
           """
    for i in range(1, 10):
        post = BlogPost(headline="Admin's Blog Post#{i}", body=body, user_id=admin.id)
        db.session.add(post)

    for i in range(1, 10):
        post = BlogPost(headline="Erkki's Blog Post #{ i }", body=body, user_id=erkki.id)
        db.session.add(post)

    db.session.commit()

    tag1 = Tag(tag_name="tag1", user_id=admin.id)
    tag2 = Tag(tag_name="tag2", user_id=admin.id)

    tag3 = Tag(tag_name="tag3", user_id=erkki.id)

    tag4 = Tag(tag_name="tag4", user_id=admin.id)

    db.session.add(tag1)
    db.session.add(tag2)
    db.session.add(tag3)
    db.session.add(tag4)
    db.session.commit()

    tags = [tag1, tag2]
    tags2 = [tag3]
    tags3 = [tag4]

    post1 = db.session.query(BlogPost).filter_by(id=1).one()

    post2 = db.session.query(BlogPost).filter_by(id=10).one()

    post3 = db.session.query(BlogPost).filter_by(id=2).one()

    post1.tags = tags
    post2.tags = tags2
    post3.tags = tags3

    db.session.add(post1)
    db.session.add(post2)
    db.session.add(post3)

    db.session.commit()
Exemple #18
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()

    admin = User(name=u'admin',
                 email=u'*****@*****.**',
                 password=u'123456',
                 role_code=ADMIN,
                 status_code=ACTIVE,
                 user_detail=UserDetail(
                     sex_code=MALE,
                     age=10,
                     url=u'http://admin.example.com',
                     deposit=100.00,
                     location=u'Hangzhou',
                     bio=u'admin Guy is ... hmm ... just a admin guy.'))

    test_user = User(name=u'test',
                     email=u'*****@*****.**',
                     password=u'123456',
                     role_code=USER,
                     status_code=ACTIVE,
                     user_detail=UserDetail(sex_code=MALE,
                                            age=29,
                                            url=u'http://test.example.com',
                                            deposit=100.00,
                                            location=u'Hangzhou',
                                            bio=u'test user guy..'))

    db.session.add(admin)
    db.session.add(test_user)
    db.session.commit()

    admin = db.session.query(User).\
        filter_by(name='admin').\
        one()

    erkki = db.session.query(User).\
        filter_by(name='test').\
        one()

    body = """
           Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica, quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum.
           """
    for i in range(1, 10):
        post = BlogPost(headline="Admin's Blog Post#{i}",
                        body=body,
                        user_id=admin.id)
        db.session.add(post)

    for i in range(1, 10):
        post = BlogPost(headline="Erkki's Blog Post #{ i }",
                        body=body,
                        user_id=erkki.id)
        db.session.add(post)

    db.session.commit()

    tag1 = Tag(tag_name='tag1', user_id=admin.id)
    tag2 = Tag(tag_name='tag2', user_id=admin.id)

    tag3 = Tag(tag_name='tag3', user_id=erkki.id)

    tag4 = Tag(tag_name='tag4', user_id=admin.id)

    db.session.add(tag1)
    db.session.add(tag2)
    db.session.add(tag3)
    db.session.add(tag4)
    db.session.commit()

    tags = [tag1, tag2]
    tags2 = [tag3]
    tags3 = [tag4]

    post1 = db.session.query(BlogPost).\
        filter_by(id=1).\
        one()

    post2 = db.session.query(BlogPost).\
        filter_by(id=10).\
        one()

    post3 = db.session.query(BlogPost).\
        filter_by(id=2).\
        one()

    post1.tags = tags
    post2.tags = tags2
    post3.tags = tags3

    db.session.add(post1)
    db.session.add(post2)
    db.session.add(post3)

    db.session.commit()
Exemple #19
0
def initdb():
    """Init/reset database."""

    db.drop_all()
    db.create_all()
    def setUp(self):
        """Reset all tables before testing."""

        db.create_all()
        self.init_data()