Exemplo n.º 1
0
def _count_articles(published_only=True):
    if published_only:
        return db.select_int(
            'select count(id) from articles where website_id=? and draft=?',
            ctx.website.id, False)
    return db.select_int('select count(id) from articles where website_id=?',
                         ctx.website.id)
Exemplo n.º 2
0
def featured_poems():
    total = db.select_int('select count(id) as num from poem where ilike>=100')
    s = set()
    while len(s)<5:
        s.add(random.randint(0, total-1))
    L = []
    for n in s:
        L.extend(db.select('select * from poem where ilike>=100 order by id limit ?,?', n, 1))
    total = db.select_int('select count(id) from poem where ilike<100')
    s = set()
    while len(s)<5:
        s.add(random.randint(0, total-1))
    for n in s:
        L.extend(db.select('select * from poem where ilike<100 order by id limit ?,?', n, 1))
    return dict(poems=L)
Exemplo n.º 3
0
def attachments():
    i = ctx.request.input(action='', page='1', size='20')
    if i.action == 'delete':
        delete_attachment(i.id)
        raise seeother('attachments')
    page = int(i.page)
    size = int(i.size)
    num = db.select_int('select count(id) from attachments where website_id=?',
                        ctx.website.id)
    if page < 1:
        raise APIValueError('page', 'page invalid.')
    if size < 1 or size > 100:
        raise APIValueError('size', 'size invalid.')
    offset = (page - 1) * size
    atts = db.select(
        'select * from attachments where website_id=? order by id desc limit ?,?',
        ctx.website.id, offset, size + 1)
    next = False
    if len(atts) > size:
        atts = atts[:-1]
        next = True
    return Template('templates/attachments.html',
                    attachments=atts,
                    page=page,
                    previous=page > 2,
                    next=next)
Exemplo n.º 4
0
 def count_by(cls, where, *args):
     '''
     Find by 'select count(pk) from table where ... ' and return int.
     '''
     return db.select_int(
         'select count(`%s`) from `%s` %s' %
         (cls.__primary_key__.name, cls.__table__, where), *args)
Exemplo n.º 5
0
def api_delete_wikipage():
    i = ctx.request.input(id="")
    if not i.id:
        raise APIValueError("id", "bad parameter: id")
    page = _get_wikipage(i.id)
    if db.select_int("select count(id) from wiki_pages where wiki_id=? and parent_id=?", page.wiki_id, page.id) > 0:
        raise APIPermissionError("cannot delete non empty page.")
    db.update("delete from wiki_pages where id=?", page.id)
    return True
Exemplo n.º 6
0
def api_delete_wiki():
    " delete a wiki by id. "
    i = ctx.request.input(id="")
    if not i.id:
        raise APIValueError("id", "id cannot be empty.")
    wiki = _get_wiki(i.id)
    count = db.select_int("select count(id) from wiki_pages where wiki_id=?", wiki.id)
    if count > 0:
        raise APIValueError("id", "cannot delete non-empty wiki.")
    db.update("delete from wikis where id=?", wiki.id)
    return True
Exemplo n.º 7
0
def api_delete_wikipage():
    i = ctx.request.input(id='')
    if not i.id:
        raise APIValueError('id', 'bad parameter: id')
    page = _get_wikipage(i.id)
    if db.select_int(
            'select count(id) from wiki_pages where wiki_id=? and parent_id=?',
            page.wiki_id, page.id) > 0:
        raise APIPermissionError('cannot delete non empty page.')
    db.update('delete from wiki_pages where id=?', page.id)
    return True
Exemplo n.º 8
0
def featured_poems():
    total = db.select_int('select count(id) as num from poem where ilike>=100')
    s = set()
    while len(s) < 5:
        s.add(random.randint(0, total - 1))
    L = []
    for n in s:
        L.extend(
            db.select(
                'select * from poem where ilike>=100 order by id limit ?,?', n,
                1))
    total = db.select_int('select count(id) from poem where ilike<100')
    s = set()
    while len(s) < 5:
        s.add(random.randint(0, total - 1))
    for n in s:
        L.extend(
            db.select(
                'select * from poem where ilike<100 order by id limit ?,?', n,
                1))
    return dict(poems=L)
Exemplo n.º 9
0
def api_delete_wiki():
    ' delete a wiki by id. '
    i = ctx.request.input(id='')
    if not i.id:
        raise APIValueError('id', 'id cannot be empty.')
    wiki = _get_wiki(i.id)
    count = db.select_int('select count(id) from wiki_pages where wiki_id=?',
                          wiki.id)
    if count > 0:
        raise APIValueError('id', 'cannot delete non-empty wiki.')
    db.update('delete from wikis where id=?', wiki.id)
    return True
Exemplo n.º 10
0
def api_create_wikipage():
    i = ctx.request.input(wiki_id="", name="", content="")
    if not "parent_id" in i:
        raise APIValueError("parent_id", "bad parameter: parent_id")
    if not i.wiki_id:
        raise APIValueError("wiki_id", "bad parameter: wiki_id")
    if not i.name.strip():
        raise APIValueError("name", "invalid name")
    if not i.content.strip():
        raise APIValueError("content", "invalid content")
    wiki = _get_wiki(i.wiki_id)
    if i.parent_id:
        p_page = _get_wikipage(i.parent_id, wiki.id)
    num = db.select_int("select count(id) from wiki_pages where wiki_id=? and parent_id=?", wiki.id, i.parent_id)
    return _create_wiki_page(wiki.id, i.parent_id, num, i.name.strip(), i.content)
Exemplo n.º 11
0
def api_create_wikipage():
    i = ctx.request.input(wiki_id='', name='', content='')
    if not 'parent_id' in i:
        raise APIValueError('parent_id', 'bad parameter: parent_id')
    if not i.wiki_id:
        raise APIValueError('wiki_id', 'bad parameter: wiki_id')
    if not i.name.strip():
        raise APIValueError('name', 'invalid name')
    if not i.content.strip():
        raise APIValueError('content', 'invalid content')
    wiki = _get_wiki(i.wiki_id)
    if i.parent_id:
        p_page = _get_wikipage(i.parent_id, wiki.id)
    num = db.select_int(
        'select count(id) from wiki_pages where wiki_id=? and parent_id=?',
        wiki.id, i.parent_id)
    return _create_wiki_page(wiki.id, i.parent_id, num, i.name.strip(),
                             i.content)
Exemplo n.º 12
0
def attachments():
    i = ctx.request.input(action='', page='1', size='20')
    if i.action=='delete':
        delete_attachment(i.id)
        raise seeother('attachments')
    page = int(i.page)
    size = int(i.size)
    num = db.select_int('select count(id) from attachments where website_id=?', ctx.website.id)
    if page < 1:
        raise APIValueError('page', 'page invalid.')
    if size < 1 or size > 100:
        raise APIValueError('size', 'size invalid.')
    offset = (page - 1) * size
    atts = db.select('select * from attachments where website_id=? order by id desc limit ?,?', ctx.website.id, offset, size+1)
    next = False
    if len(atts)>size:
        atts = atts[:-1]
        next = True
    return Template('templates/attachments.html', attachments=atts, page=page, previous=page>2, next=next)
Exemplo n.º 13
0
def main():
    if raw_input('To install iTranswarp, type Y and press ENTER: ') != 'Y':
        print 'Install cancelled.'
        exit(1)
    print 'Prepare to install iTranswarp...'
    try:
        print 'Checking Python version...', _check_version()
        print 'Checking Python Imaging Library...', _check_pil()
        print 'Checking Redis...', _check_redis()
        host = raw_input('Database host (localhost): ')
        port = raw_input('Database port (3306): ')
        user = raw_input('Database user (root): ')
        dbpass = raw_input('Database password: '******'':
            port = '3306'
        db.init(db_type='mysql', db_schema='itrans', \
                db_host=host or 'localhost', db_port=int(port), \
                db_user=user or 'root', db_password=dbpass, \
                use_unicode=True, charset='utf8')
        print 'Creating tables . . .',
        for sql in CREATE_TABLES:
            if not sql.startswith('--'):
                db.update(sql)
                print '.',
        print '\nInit database ok.'
        email = raw_input('Super admin email: ').strip().lower()
        passwd = raw_input('Super admin password: '******'iTranswarp', 'localhost')
        if db.select_int('select count(*) from mysql.user where user=?',
                         'www-data') == 0:
            db.update(
                'create user \'www-data\'@\'localhost\' identified by \'www-data\''
            )
        db.update(
            'grant select,insert,update,delete on itrans.* to \'www-data\'@\'localhost\' identified by \'www-data\''
        )
        db.update('update users set role_id=0, passwd=? where email=?', passwd,
                  email)
        print 'Install successfully!'
    except Exception, e:
        print 'Install failed:', e.message
        raise
Exemplo n.º 14
0
def main():
    if raw_input('To install iTranswarp, type Y and press ENTER: ')!='Y':
        print 'Install cancelled.'
        exit(1)
    print 'Prepare to install iTranswarp...'
    try:
        print 'Checking Python version...', _check_version()
        print 'Checking Python Imaging Library...', _check_pil()
        print 'Checking Redis...', _check_redis()
        host = raw_input('Database host (localhost): ')
        port = raw_input('Database port (3306): ')
        user = raw_input('Database user (root): ')
        dbpass = raw_input('Database password: '******'':
            port = '3306'
        db.init(db_type='mysql', db_schema='itrans', \
                db_host=host or 'localhost', db_port=int(port), \
                db_user=user or 'root', db_password=dbpass, \
                use_unicode=True, charset='utf8')
        print 'Creating tables . . .',
        for sql in CREATE_TABLES:
            if not sql.startswith('--'):
                db.update(sql)
                print '.',
        print '\nInit database ok.'
        email = raw_input('Super admin email: ').strip().lower()
        passwd = raw_input('Super admin password: '******'iTranswarp', 'localhost')
        if db.select_int('select count(*) from mysql.user where user=?', 'www-data')==0:
            db.update('create user \'www-data\'@\'localhost\' identified by \'www-data\'')
        db.update('grant select,insert,update,delete on itrans.* to \'www-data\'@\'localhost\' identified by \'www-data\'')
        db.update('update users set role_id=0, passwd=? where email=?', passwd, email)
        print 'Install successfully!'
    except Exception, e:
        print 'Install failed:', e.message
        raise
Exemplo n.º 15
0
 def count_by(cls, where, *args):
     '''
     执行select count(pk) from table where...语句进行查询,返回一个数值
     '''
     return db.select_int('select count(`%s`) from `%s` %s' % (cls.__primary_key__.name, cls.__table__, where), *args)
Exemplo n.º 16
0
Arquivo: orm.py Projeto: ujfj1986/blog
	def count_all(cls):
   		'''
   		Get count of rows in table.
   		'''
   		return db.select_int('select count(`%s`) from `%s`' % (cls.__primary_key__.name, cls.__table__))
Exemplo n.º 17
0
 def count_all(cls):
     '''
     执行select count(pk) from table语句,返回一个数值
     '''
     return db.select_int('select count(`%s`) from `%s`' % (cls.__primary_key__.name, cls.__table__))
Exemplo n.º 18
0
Arquivo: orm.py Projeto: ujfj1986/blog
	def count_by(cls, where, *args):
   		'''
   		Get count of rows that find by where clause.
   		'''
   		return db.select_int('select count(`%s`) from `%s` where %s' % (cls.__primary_key__.name, cls.__table__, where), *args)
Exemplo n.º 19
0
 def count_all(cls):
     '''
     Find by 'select count(pk) from table' and return integer.
     '''
     return db.select_int('select count(`%s`) from `%s`' %
                          (cls.__primary_key__.name, cls.__table__))
Exemplo n.º 20
0
def _count_articles(published_only=True):
    if published_only:
        return db.select_int('select count(id) from articles where website_id=? and draft=?', ctx.website.id, False)
    return db.select_int('select count(id) from articles where website_id=?', ctx.website.id)
Exemplo n.º 21
0
 def count_by(cls, where, *args):
     '''
     Find by 'select count(pk) from table where ... ' and return int.
     '''
     return db.select_int('select count(`%s`) from `%s` %s' % (cls.__primary_key__.name, cls.__table__, where), *args)
Exemplo n.º 22
0
 def count_all(cls):
     '''
     Find by 'select count(pk) from table' and return integer.
     '''
     return db.select_int('select count(`%s`) from `%s`' % (cls.__primary_key__, cls.__table__))
Exemplo n.º 23
0
 def count_by(cls,where,*args):
     return db.select_int('select count(%s) from %s %s'%(cls.__primary_key__,cls.__table__,where),*args)
Exemplo n.º 24
0
 def count_all(cls):
     return db.select_int('select count(%s) from %s'%(cls.__primary_key__,cls.__table__))