How to use summer - 10 common examples

To help you get started, we’ve selected a few summer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gaowhen / summer / summer / model / entry.py View on Github external
def get_page(cls, page=1):
        entries = []
        perpage = 5
        start = (page - 1) * 5

        db = get_db()
        cur = db.execute('select title, id, content, create_time, '
                         'status, slug from entries '
                         'order by create_time desc limit ? offset ?',
                         (perpage, start,))

        for _entry in cur.fetchall():
            _content = _entry['content'].split('')[0]
            content = markdown(_content)
            date = _entry['create_time']
            status = _entry['status']
            slug = _entry['slug']

            entry = dict(
                title=_entry['title'],
                id=_entry['id'],
                content=content,
github gaowhen / summer / summer / model / entry.py View on Github external
def update(cls, title, content, id):
        db = get_db()
        db.execute('update entries set title=?, content=? where id=?',
                   (title, content, id))
        db.commit()

        entry = cls.get(id)

        return entry
github gaowhen / summer / summer / model / entry.py View on Github external
def save_draft(cls, title, content, date, slug):
        db = get_db()
        db.execute('insert into entries '
                   '(title, content, create_time, slug, status) '
                   'values (?, ?, ?, ?, ?)',
                   (title, content, date, slug, 'draft'))
        db.commit()

        entry = cls.get_by_slug(slug)

        return entry
github gaowhen / summer / summer / model / entry.py View on Github external
def get_all_published(cls, is_need_summary=False):
        entries = []

        db = get_db()
        cur = db.execute('select title, content, slug, status, create_time'
                         ' from entries where status is not ? '
                         'order by create_time desc', ('draft',))

        for row in cur.fetchall():
            status = row['status']
            title = row['title']
            date = row['create_time']
            id = row['slug']
            status = row['status']

            if is_need_summary:
                _content = row['content'].split('')[0]
            else:
                _content = row['content']
github gaowhen / summer / summer / model / entry.py View on Github external
def delete(cls, id):
        entry = cls.get(id)
        db = get_db()
        db.execute('delete from entries where id=?', (id,))
        db.commit()
        return entry
github gaowhen / summer / summer / model / entry.py View on Github external
def update_status(cls, id, status):
        db = get_db()
        db.execute('update entries set status=? where id=?', (status, id))
        db.commit()

        entry = cls.get(id)

        return entry
github gaowhen / summer / summer / model / entry.py View on Github external
def get_published_page(cls, page=1):
        perpage = 5
        start = (page - 1) * 5
        entries = []

        db = get_db()
        cur = db.execute('select title, content, status, create_time, id, '
                         'slug from entries where status is not ? '
                         'order by create_time desc limit ? offset ?',
                         ('draft', perpage, start,))

        for row in cur.fetchall():
            status = row['status']
            title = row['title']
            date = row['create_time']
            id = row['slug']
            status = row['status']
            _content = row['content'].split('')[0]
            content = markdown(_content)

            entry = dict(
                title=title,
github gaowhen / summer / tool / fillup.py View on Github external
with open(name) as f:
                print name
                _file = f.read().decode('utf-8')
                if _file:
                    meta = _file.split('---')[0]
                    content = _file.split('---')[1]

                    title = yaml.load(meta)['title']
                    slug = os.path.splitext(ntpath.basename(f.name))[0]
                    create_time = yaml.load(meta)['date']
                    category = (','.join(yaml.load(meta)['categories'])
                                if yaml.load(meta)['categories'] else '')
                    tag = (','.join(yaml.load(meta)['tags'])
                           if yaml.load(meta)['tags'] else '')

                    with closing(connect_db()) as db:
                        db.execute('insert into entries (title, slug, '
                                   'content, create_time, category, tag, '
                                   'status) values '
                                   '(?, ?, ?, ?, ?, ?, "draft")',
                                   (title, slug, content, create_time,
                                    category, tag))
                        db.commit()

        except IOError as exc:
            if exc.errno != errno.EISDIR:
                raise
github gaowhen / summer / tool / fillup.py View on Github external
with open(name) as f:
                print name
                _file = f.read().decode('utf-8')
                if _file:
                    meta = _file.split('---')[0]
                    content = _file.split('---')[1]

                    title = yaml.load(meta)['title']
                    slug = os.path.splitext(ntpath.basename(f.name))[0]
                    create_time = yaml.load(meta)['date']
                    category = (','.join(yaml.load(meta)['categories'])
                                if yaml.load(meta)['categories'] else '')
                    tag = (','.join(yaml.load(meta)['tags'])
                           if yaml.load(meta)['tags'] else '')

                    with closing(connect_db()) as db:
                        db.execute('insert into entries '
                                   '(title, slug, content, '
                                   'create_time, category, tag) '
                                   'values '
                                   '(?, ?, ?, ?, ?, ?)',
                                   [title, slug, content, create_time,
                                    category, tag])
                        db.commit()

        except IOError as exc:
            if exc.errno != errno.EISDIR:
                raise
github gaowhen / summer / tool / initdb.py View on Github external
def init_db():
    app = create_app('product')
    _context = app.app_context()
    _context.push()
    with closing(connect_db()) as db:
        with open('./summer/schema.sql', mode='r') as f:
            db.cursor().executescript(f.read())
            db.commit()