Exemplo n.º 1
0
def motivation():
    with db:
        stories = Story.listing()
        stories_by_tags = Story.tags_mapping()
    return render_template('motivation.html',
                           nav_active='motivation',
                           subnav_tabs=HANDBOOK_SUBNAV_TABS,
                           subnav_active='motivation',
                           stories=stories,
                           stories_by_tags=stories_by_tags,
                           thumbnail=thumbnail(title='Proč se učit programování'))
Exemplo n.º 2
0
def create_story(**kwargs):
    return Story.create(
        url=kwargs.get('url',
                       'https://blog.example.com/how-i-learned-to-code/'),
        date=kwargs.get('date', datetime(2019, 12, 19, 0, 0, 0)),
        title=kwargs.get('title', 'How I Learned to Code'),
    )
Exemplo n.º 3
0
def create_story(**kwargs):
    return Story.create(
        url=kwargs.get('url', 'https://blog.example.com/how-i-learned-to-code/'),
        date=kwargs.get('date', datetime(2019, 12, 19, 0, 0, 0)),
        title=kwargs.get('title', 'How I Learned to Code'),
        image_path=kwargs.get('image', 'images/stories/somebody-something.jpg'),
    )
Exemplo n.º 4
0
def index():
    with db:
        metrics = Job.aggregate_metrics()
    return render_template('index.html',
                           nav_tabs=None,
                           metrics=metrics,
                           stories=Story.listing())
Exemplo n.º 5
0
def learn():
    return render_template('learn.html',
                           nav_active='motivation',
                           subnav_tabs=HANDBOOK_SUBNAV_TABS,
                           subnav_active='learn',
                           stories_count=len(Story.listing()),
                           thumbnail=thumbnail(title='Jak se naučit programovat'))
Exemplo n.º 6
0
def index():
    with db:
        jobs_count = Job.count()
        companies_count = Job.companies_count()
    return render_template('index.html',
                           jobs_count=jobs_count,
                           companies_count=companies_count,
                           stories=Story.listing())
Exemplo n.º 7
0
def motivation():
    return render_template(
        'motivation.html',
        nav_active='motivation',
        subnav_tabs=HANDBOOK_SUBNAV_TABS,
        subnav_active='motivation',
        stories_count=len(Story.listing()),
        thumbnail=thumbnail(title='Proč se učit programování'))
Exemplo n.º 8
0
def test_tags_mapping(db_connection):
    story1 = create_story(date=date(2010, 7, 6), tags=['science', 'age'])
    story2 = create_story(date=date(2019, 7, 6), tags=['science', 'careerswitch'])
    story3 = create_story(date=date(2014, 7, 6), tags=['age', 'careerswitch'])
    mapping = Story.tags_mapping()

    assert set(mapping.keys()) == {'age', 'science', 'careerswitch'}
    assert mapping['age'] == [story3, story1]
    assert mapping['science'] == [story2, story1]
    assert mapping['careerswitch'] == [story2, story3]
Exemplo n.º 9
0
def db():
    db = SqliteDatabase(':memory:')
    with db:
        Story.bind(db)
        Story.create_table()
        yield db
        Story.drop_table()
Exemplo n.º 10
0
def main():
    path = Path(__file__).parent.parent / 'data' / 'stories.yml'
    records = [record.data for record in load(path.read_text(), schema)]

    with db:
        Story.drop_table()
        Story.create_table()

        for record in records:
            Story.create(**record)
Exemplo n.º 11
0
def learn():
    return render_template(
        'learn.html',
        stories_count=len(Story.listing()),
        thumbnail=thumbnail(title='Jak se naučit programovat'))
Exemplo n.º 12
0
def test_listing_sorts_by_date_desc(db):
    story1 = create_story(date=datetime(2010, 7, 6, 20, 24, 3))
    story2 = create_story(date=datetime(2019, 7, 6, 20, 24, 3))
    story3 = create_story(date=datetime(2014, 7, 6, 20, 24, 3))

    assert list(Story.listing()) == [story2, story3, story1]
Exemplo n.º 13
0
def test_tag_listing(db_connection):
    story1 = create_story(tags=['science', 'age'])
    story2 = create_story(tags=['science', 'careerswitch'])  # noqa
    story3 = create_story(tags=['age', 'careerswitch'])

    assert set(Story.tag_listing('age')) == {story1, story3}
Exemplo n.º 14
0
def test_listing_sorts_by_date_desc(db_connection):
    story1 = create_story(date=date(2010, 7, 6))
    story2 = create_story(date=date(2019, 7, 6))
    story3 = create_story(date=date(2014, 7, 6))

    assert list(Story.listing()) == [story2, story3, story1]