コード例 #1
0
ファイル: pm.py プロジェクト: dalinhuang/demodemo
 def select(self, cls, where=None, vars=None, order=None, group=None, 
            limit=None, offset=None):
     
     cls = self.get_cls_type(cls)
     if cls._pm_where_ is not None:
         where += " and " + cls._pm_where_
     
     self.syslog.debug("Select SQL:" + web.select(cls._pm_db_table_, 
                         vars=vars, 
                         where=where, 
                         limit=limit,
                         order=order,
                         offset=offset,
                         group=group, _test=True))
     
     results = web.select(cls._pm_db_table_, 
                         vars=vars, 
                         where=where, 
                         limit=limit,
                         order=order,
                         offset=offset,
                         group=group)
     #print results
     
     return self._mapping_to_model(cls, results)
コード例 #2
0
 def testWrongQuery(self):
     # It should be possible to run a correct query after getting an error from a wrong query.
     try:
         web.select('wrong_table')
     except:
         pass
     web.select('person')
コード例 #3
0
ファイル: db.py プロジェクト: fidlej/jakybyt
 def testWrongQuery(self):
     # It should be possible to run a correct query after getting an error from a wrong query.
     try:
         web.select('wrong_table')
     except:
         pass
     web.select('person')
コード例 #4
0
    def get(self, id, providerName):
        ret = {}
        id = self._getLocalId(id, providerName)[0].id
        for i in web.select('places_description', where='id=%s' % id):
            ret[i.name] = i.value

        ret['ESTADO_ZAUBER']  = web.select('places', what='state', where='id=%s' % id)[0].state
        return ret
コード例 #5
0
ファイル: db.py プロジェクト: 10sr/jottit
def get_revision(page_id, revision=None):
    if revision:
        try:
            revision = int(revision)
        except ValueError:
            return None
    if revision is not None:
        d = web.select('revisions', where='page_id=$page_id AND revision=$revision', limit=1, vars=locals())
    else:
        d = web.select('revisions', where='page_id=$page_id and revision > 0', order='revision DESC', limit=1, vars=locals())
    return (d and d[0]) or None
コード例 #6
0
ファイル: main.py プロジェクト: antoine/metagenda
 def GET(self, comparison_name):
     """show a form to create a location"""
     if comparison_name == 'nomap':
         #showing a list of all locations withour a map
         events = web.select(tables='events', what='*', group='place', order='time_start', where='not cancelled and duplicateof is null and id_location is null' )
         print render.base(render.show_locations( events))
     elif comparison_name:
         #updating a specific location
         location = [l for l in web.select(tables='locations', where="comparison_name = '%s'" % comparison_name)]
         if len(location):
             print render.base(render.manage_location(location[0].longitude,location[0].latitude, location[0].originalmapurl, location[0].id, comparison_name))
         else:
             print render.base(render.manage_location(None, None, None, None, comparison_name))
     else:
         print "not implemented yet"
コード例 #7
0
ファイル: people.py プロジェクト: drew/seddit
def getperson(id):
    person = web.select("people", where="id=%s" % web.sqlquote(id), limit=1)

    if person:
        return person[0]
    else:
        return None
コード例 #8
0
 def view(self, found, model, providerName, id):
     lid = scrappers[providerName].local(id)
     comments = web.select('places_forum', where='idplace=%d' % lid, 
                          order='date asc')
     print render.header()
     print render.someplace(model, comments, providerName, id)
     print render.footer()
コード例 #9
0
ファイル: index.py プロジェクト: dsandler/shirtdb
 def GET(self, year):
     print render.year(
         G,
         year,
         web.select('shirts', 
             where='shirts.year = %s' % web.db.sqlify(year),
             order='college, variant'))
コード例 #10
0
ファイル: threads.py プロジェクト: drew/seddit
def getthread(id):
    thread = web.select('threads', where='id=%s' % web.sqlquote(id), limit=1)
    
    if thread:
        return thread[0]
    else:
        return None
コード例 #11
0
ファイル: db.py プロジェクト: antoine/metagenda
def get_events(**params):
    if not params.has_key("tables"):
        params["tables"] = "events left join locations on events.id_location = locations.id"
    if not params.has_key("what"):
        params[
            "what"
        ] = "events.*, locations.longitude as longitude, locations.latitude as latitude, locations.originalmapurl as mapurl, locations.id as loc_id"
    return web.select(**params)
コード例 #12
0
ファイル: auth2.py プロジェクト: yudun1989/blog
def guest():
    """ returns our default guest user for those that aren't logged in
    
        when you want to chat, you still need to create a new guest user, but just for
        browsing we'll use thi temp user. this allows use to program user names and id
        into the templates without having to worry about there not being a user present.
    """
    return web.select('people', where='email=%s' % web.sqlquote('*****@*****.**'))[0]
コード例 #13
0
ファイル: auth2.py プロジェクト: yudun1989/blog
def getuser(email, password):
    """ return a user object if the email and passwords match an entry in the db.
    """
    user = web.select('people', where='email=%s and password=%s' % (web.sqlquote(email), web.sqlquote(password)), limit=1)
    if user:
        return user[0]
    else:
        return None
コード例 #14
0
ファイル: threads.py プロジェクト: drew/seddit
def find(id):
    # TODO getthread has the same functionality. replace this with getthread.
    thread = web.select('threads', where='id=%s' % web.sqlquote(id), limit=1)
    
    if thread:
        return thread[0]
    else:
        return None
コード例 #15
0
ファイル: user.py プロジェクト: keizo/kulu
def _login_valid(form):
    pass_submitted = md5.new(form.password).hexdigest()
    try:
        user = web.select('users',where='email = $form.email',vars=locals())[0]
    except:
        return False
    if user.password == pass_submitted:
        return True
    return False
コード例 #16
0
ファイル: mro.py プロジェクト: benhoyt/mro
    def select(cls, _test=False, **kwargs):
        """ Select and return multiple rows from the database via the web.py
            SQL-like query given via kwargs. For example:

            >>> print UserTest.select(where='username LIKE $u', vars={'u': 'jo%'}, order='username', limit=5, _test=True)
            SELECT * FROM users WHERE username LIKE 'jo%' ORDER BY username LIMIT 5
        """
        select = web.select(cls._table, _test=_test, **kwargs)
        return select if _test else [cls(row, _fromdb=True) for row in select]
コード例 #17
0
ファイル: lecker.py プロジェクト: aviatorBeijing/ptpy
 def GET(self, tag):
     bookmarks = []
     bs = list(web.select("bookmarks", order="created desc"))
     for b in bs:
         b.tags = b.tags.split()
         if tag in b.tags:
             bookmarks.append(b)
     empty = (len(bookmarks) == 0)
     web.render('search.html')
コード例 #18
0
ファイル: lecker.py プロジェクト: zvonlearn/webpy-examples
 def GET(self, tag):
     bookmarks = []
     bs = list(web.select("bookmarks", order="created desc"))
     for b in bs:
         b.tags = b.tags.split()
         if tag in b.tags:
             bookmarks.append(b)
     empty = len(bookmarks) == 0
     web.render("search.html")
コード例 #19
0
ファイル: lecker.py プロジェクト: aviatorBeijing/ptpy
 def GET(self, id):
     try:
         bookmark = web.select("bookmarks", where="id = "+id)[0]
         web.render('edit.html')
     except IndexError:
         print "This bookmark doesn't exist."            
     def POST(self, id):
         i = web.input()
         web.update('bookmarks', 'id = '+id, title=i.title, url=i.url, tags=i.tags)
         web.seeother('../')
コード例 #20
0
ファイル: web_ui.py プロジェクト: hornc/openlibrary-1
def random_isbn():
    f = open(isbn_file)
    while True:
        f.seek(random.randrange(isbn_count) * 11)
        isbn = f.read(10)
        break
        found = list(web.select('isbn', where='value=$v', vars={'v':isbn}))
        if found > 1:
            break
    f.close()
    return isbn
コード例 #21
0
ファイル: threads.py プロジェクト: drew/seddit
def messageoffset(id, offset):
    messages = web.select('messages', where='thread_id = %s and id > %s' % (web.sqlquote(id), web.sqlquote(offset)))
    
    offsetmessages = []
    
    for message in messages:
        message['date_sent'] = web.datestr(message['date_sent'])
        message['author'] = people.getperson(message.author_id).name
        offsetmessages.append(message)
        
    return offsetmessages
コード例 #22
0
ファイル: lecker.py プロジェクト: zvonlearn/webpy-examples
 def POST(self, tag):
     i = web.input()
     tags = i.tags.split()
     bookmarks = []
     bs = list(web.select("bookmarks", order="created desc"))
     for b in bs:
         b.tags = b.tags.split()
         if every(lambda t: t in b.tags, tags):
             bookmarks.append(b)
     empty = len(bookmarks) == 0
     web.render("search.html")
コード例 #23
0
ファイル: web_ui.py プロジェクト: sribanta/openlibrary
def random_isbn():
    f = open(isbn_file)
    while 1:
        f.seek(random.randrange(isbn_count) * 11)
        isbn = f.read(10)
        break
        found = list(web.select("isbn", where="value=$v", vars={"v": isbn}))
        if found > 1:
            break
    f.close()
    return isbn
コード例 #24
0
ファイル: web_ui.py プロジェクト: Arpanray01/Open-Library
def random_isbn():
    f = open(isbn_file)
    while True:
        f.seek(random.randrange(isbn_count) * 11)
        isbn = f.read(10)
        break
        found = list(web.select('isbn', where='value=$v', vars={'v': isbn}))
        if found > 1:
            break
    f.close()
    return isbn
コード例 #25
0
ファイル: index.py プロジェクト: dsandler/shirtdb
 def GET(self, college):
     print render.college(
         G,
         college,
         COLLEGES[college] + " College", 
         web.select('shirts', 
             where='shirts.college = %s' % #' and shirts.face = \'front\'' %
                 web.db.sqlify(college),
             group='variant, year',
             order='year, variant')
     )
コード例 #26
0
ファイル: util.py プロジェクト: keizo/kulu
 def load(self):
     self.clear()
     try:
         table_iter = web.select(self.table) #returns iterbetter
         for row in table_iter: #where variable is a storage object
             key = row[self.key_field]
             value = row[self.value_field]
             dict.__setitem__(self,key,value)
         print 'Variable object loaded for', self.table
     except:
         raise
コード例 #27
0
ファイル: lecker.py プロジェクト: aviatorBeijing/ptpy
 def POST(self, tag):
     i = web.input()
     tags = i.tags.split()
     bookmarks = []
     bs = list(web.select("bookmarks", order="created desc"))
     for b in bs:
         b.tags = b.tags.split()
         if every(lambda t: t in b.tags, tags):
             bookmarks.append(b)
     empty = (len(bookmarks) == 0)
     web.render('search.html')
コード例 #28
0
ファイル: util.py プロジェクト: keizo/kulu
 def load(self):
     self.clear()
     try:
         table_iter = web.select(self.table) #returns iterbetter
         for row in table_iter: #where variable is a storage object
             index = row[self.index]
             #print index, row
             dict.__setitem__(self,index,row)
     except:
         raise
     print 'bin load function run for', self.table
コード例 #29
0
ファイル: session.py プロジェクト: jpsp1/mygames
    def retreive(self, id_):
        '''returns Storage'''
        try:
            tmp = web.select(web.config.handler_parameters.db_table,
                    what='*',
                    vars={
                            'id': id_,
                            'timeout': web.config.session_parameters.timeout
                        },
                    where='id = $id')

        except Exception, inst:
            raise inst
コード例 #30
0
ファイル: db.py プロジェクト: 10sr/jottit
def get_pages():
    site_id = jt.site.id
    pages = web.select('pages', where='site_id=$site_id AND deleted=false', vars=locals())
    pages_list = []
    for p in pages:
        p.title = utils.page_title(p.name)
        p.url = utils.page_url(p.name)
        pages_list.append(p)
    pages_list.sort(page_sort)
    out = web.utils.iterbetter(iter(pages_list))
    out.__len__ = len(pages_list)
    out.__list__ = pages_list
    return out
コード例 #31
0
ファイル: user.py プロジェクト: keizo/kulu
def login(email='',user='',remember_me=''):
    # TODO: implement login by username in addition to email
    r = '0'
    if remember_me:
        r = '1'
    login_time = int(time.time())
    user = web.select('users',where='email = $email',vars=locals())[0]
    #print user
    web.transact()
    web.query("UPDATE users SET login = $login_time, remember_me = $r \
        WHERE uid = $user.uid", vars=locals())
    #print user.uid
    inc.session.regenerate(uid=user.uid)
    web.commit()
コード例 #32
0
ファイル: mro.py プロジェクト: benhoyt/mro
    def __init__(self, _init=None, _fromdb=False, _test=False, **kwargs):
        """ Initialise a row object of this table from the given _init data.
            If _init is None, fields are taken from kwargs. If _init is a dict,
            fields are taken from it. Otherwise _init is assumed to be a
            primary key if it's an int or a secondary key if it's a non-int,
            and fields are loaded from the database (raising a KeyError if no
            rows match the given key).

            _fromdb is used internally to signal that these values have been
            loaded from the database.

            >>> UserTest()
            UserTest()
            >>> UserTest({'username': '******', 'hash': '4321'})
            UserTest(hash='4321', username='******')
            >>> u = UserTest(username='******', hash='1234')
            >>> u
            UserTest(hash='1234', username='******')
            >>> print u.save(_test=True)
            INSERT INTO users (username, hash) VALUES ('bob', '1234')

            >>> u = UserTest(5, _test=True)
            SELECT * FROM users WHERE id = 5
            >>> u = UserTest('bob', _test=True)
            SELECT * FROM users WHERE username = '******'

            >>> u = UserTest('baduser', _test=[{}, {}])
            Traceback (most recent call last):
              ...
            KeyError: "no users (or more than one) with username of 'baduser'"
        """
        self._changed = set()
        self._init_columns()
        if _init is None:
            _init = kwargs
        elif not isinstance(_init, dict):
            key_name = self._primary_key if isinstance(_init, int) else self._secondary_key
            select = web.select(self._table, where='%s = $key' % key_name, vars={'key': _init}, _test=_test)
            if _test:
                print select
                select = _test if not isinstance(_test, bool) else [{}]
            rows = list(select)
            if len(rows) != 1:
                raise KeyError('no %s (or more than one) with %s of %r' % (self._table, key_name, _init))
            _init = rows[0]
        self.setattrs(_init)
        if _fromdb:
            self._changed.clear()
コード例 #33
0
ファイル: db.py プロジェクト: 10sr/jottit
def new_site(content, scroll_pos, caret_pos, secret_url, public_url, partner):
    schemes = [('520000', 'fff', 'ffbfbf', 0, 214),
               ('523000', 'fff', 'ffe5bf', 25, 214),
               ('515200', 'fff', 'feffbf', 43, 214),
               ('2c5200', 'fff', 'e2ffbf', 62, 214),
               ('003452', 'fff', 'bfe8ff', 143, 214),
               ('001152', 'fff', 'bfcdff', 161, 214),
               ('4d0052', 'fff', 'fbbfff', 210, 214),
               ('520036', 'fff', 'ffbfe9', 227, 214),
               ('760000', 'fff', 'ffbfbf', 0, 196),
               ('764000', 'fff', 'ffe2bf', 23, 196),
               ('087600', 'fff', 'c4ffbf', 82, 196),
               ('004876', 'fff', 'bfe6ff', 144, 196),
               ('760043', 'fff', 'ffbfe3', 231, 196),
               ('92e600', '000', '3a5c00', 58, 140),
               ('d7ecff', '000', '003566', 148, 20),
               ('d8ffd7', '000', '026600', 84, 20),
               ('fcd7ff', '000', '5e0066', 209, 20),
               ('ffffd7', '000', '656600', 43, 20),
               ('ffd7d7', '000', '660000', 0, 20),
               ('d7fff9', '000', '006656', 121, 20),
               ('d7d7ff', '000', '000066', 170, 20)]

    def url_taken(url):
        return web.select('sites', where='public_url=$url or secret_url=$url', vars=locals())

    def create_url():
        def safe36(s):
            for c in '0o1li':
                if c in s:
                    return False
            return True
        s = '0'
        while not safe36(s):
            s = web.to36(random.randrange(50000, 60000000))
        return s

    if not secret_url:
        secret_url = create_url()
        while(url_taken(secret_url)):
            secret_url = create_url()

    header_color, title_color, subtitle_color, hue, brightness = schemes[random.randrange(0, len(schemes))]
    site_id = web.insert('sites', secret_url=secret_url, public_url=public_url, partner=partner)
    jt.site = web.select('sites', where='id=$site_id', vars=locals())[0]
    web.insert('designs', site_id=jt.site.id, title_font='Lucida_Grande', subtitle_font='Lucida_Grande', headings_font='Lucida_Grande', content_font='Lucida_Grande', header_color='#'+header_color, title_color='#'+title_color, subtitle_color='#'+subtitle_color, hue=hue, brightness=brightness)
    new_page('', content, scroll_pos, caret_pos)
    jt.site = get_site(id=site_id)
コード例 #34
0
ファイル: filter.py プロジェクト: keizo/kulu
 def POST(self):
     page = self.page
     form = form_edit_filters()
     
     if form.validates():
         i = form.d
         query = web.select('filter')
         for input_format in query:
             if hasattr(i,input_format.name):
                 values = i[input_format.name].split(',')
                 values = [x.strip() for x in values]
                 glbl.filter[int(input_format.format)] = values
                 
         # clear the cache on updating filters
         # TODO: make this only clear the affected nodes, instead of all
         web.query('TRUNCATE TABLE  `cache_node`')
     
     web.redirect('/admin/filters')
コード例 #35
0
    def store(self, id, model, providerName,username=None):
        username = self.usernameProvider.get()
        thegeom = model['the_geom']
        del  model['the_geom']
        model['providerName'] = providerName
        model['originalId'] = str(id)
        web.transact() 
        ret = web.query(self.SQL_PLACE  %
                       (thegeom.encode('latin1'), providerName, id))
        appid = web.select("currval('places_id_seq')")[0].currval

        for k,v in model.iteritems():
            sql = self.SQL_DESCR % (appid, web.db.sqlquote(k.encode('latin1')),
                                    web.db.sqlquote(v.encode('latin1')))
            sql = sql.replace('$','S')
            web.query(sql)
        web.query(self.SQL_ACTION % (web.db.sqlquote(username),
            web.db.sqlquote('importo la propiedad %s-%s' % (providerName,id))));
        web.commit()
コード例 #36
0
ファイル: lecker.py プロジェクト: zvonlearn/webpy-examples
 def GET(self, id):
     try:
         bookmark = web.select("bookmarks", where="id = " + id)[0]
         web.render("edit.html")
     except IndexError:
         print("This bookmark doesn't exist.")
コード例 #37
0
ファイル: lecker.py プロジェクト: zvonlearn/webpy-examples
 def GET(self):
     bookmarks = web.select("bookmarks", order="title")
     web.render("delete.html")
コード例 #38
0
 def testUnicode(self):
     """Bug#177265: unicode queries throw errors"""
     web.select('person', where='name=$name', vars={'name': u'\xf4'})
コード例 #39
0
ファイル: test.py プロジェクト: yaminglu/lantern-detection
def getrow(value):
    d = web.select('test', where='value=$value', vars=locals())
    a = (d and d[0].value) or None
    return a
コード例 #40
0
 def GET(self):
     print render.header()
     print render.history(web.select('action_log',
                          order='date desc', limit=100))
     print render.footer()
コード例 #41
0
ファイル: rename.py プロジェクト: yzou/openlibrary
        make_redirect(merge_with, author)
    else:
        new_key = merge_with['key']
        print "copy fields from author to", new_key
        new = copy_fields(merge_with, author, new_name)
        update_author(new_key, new)
        switch_author(author, merge_with)
        #        print "delete author"
        make_redirect(author, merge_with)
    print


print 'running query'
# limit for test runs
for thing_row in web.select('thing',
                            what='id, key',
                            where='type=' + ` author_type_id `,
                            limit=10000):
    id = thing_row.id
    author = get_thing(id)

    if 'personal_name' not in author \
            or author['personal_name'] != author['name']:
        continue
    if author['name'].find(', ') == -1:
        continue
    if author['name'].lower().replace('.', '') in east:
        continue

    key = author['key']
    name = flip_name(author['name'])
コード例 #42
0
def user_by_description(description):
    return web.select("users",
                      where="description=$description",
                      vars=dict(description=description))
コード例 #43
0
from catalog.read_rc import read_rc
import web, sys
rc = read_rc()
web.config.db_parameters = dict(dbn='mysql', db='archive', user=rc['ia_db_user'], pw=rc['ia_db_pass'], host=rc['ia_db_host'])
web.load()

iter = web.select('metadata', where="scanner != 'google' and noindex is null and mediatype='texts'")

for row in iter:
    print row.identifier
コード例 #44
0
from __future__ import print_function
from catalog.read_rc import read_rc
import web, sys

rc = read_rc()
web.config.db_parameters = dict(dbn='postgres',
                                db=rc['db'],
                                user=rc['user'],
                                pw=rc['pw'],
                                host=rc['host'])
web.load()

iter = web.select('version',
                  what='machine_comment',
                  where="machine_comment like 'ia:%%'")

for row in iter:
    print(row.machine_comment[3:])
コード例 #45
0
 def assertRows(self, n):
     result = web.select('person')
     self.assertEquals(len(list(result)), n)
コード例 #46
0
 def GET(self, id):
     r = web.select('places', what='provider, providerid',
                      where='id=%d' % int(id))[0]
     web.seeother('/places/%s/%s/' % (r.provider, r.providerid))
コード例 #47
0
 def _getLocalId(self, id, provider):
     return web.select('places', what='id',
                where="providerid=%s and provider=%s" % \
                (web.db.sqlquote(id), web.db.sqlquote(provider)))
コード例 #48
0
        make_redirect(merge_with, author)
    else:
        new_key = merge_with['key']
        print("copy fields from author to", new_key)
        new = copy_fields(merge_with, author, new_name)
        update_author(new_key, new)
        switch_author(author, merge_with)
        #        print "delete author"
        make_redirect(author, merge_with)
    print()


print('running query')
# limit for test runs
for thing_row in web.select('thing',
                            what='id, key',
                            where='type=' + repr(author_type_id),
                            limit=10000):
    id = thing_row.id
    author = get_thing(id)

    if 'personal_name' not in author \
            or author['personal_name'] != author['name']:
        continue
    if author['name'].find(', ') == -1:
        continue
    if author['name'].lower().replace('.', '') in east:
        continue

    key = author['key']
    name = flip_name(author['name'])
    other = get_other_authors(name)
コード例 #49
0
ファイル: lecker.py プロジェクト: zvonlearn/webpy-examples
 def GET(self):
     bookmarks = list(web.select("bookmarks", order="created desc"))
     for b in bookmarks:
         b.tags = b.tags.split()
     web.render("view.html")
コード例 #50
0
def user_by_id(id):
    return web.select("users", where="id=$id", vars=dict(id=id))
コード例 #51
0
def sources():
    return ((i.id, i.archive_id, i.name) for i in web.select('marc_source'))
コード例 #52
0
def user_by_username(username):
    return web.select("users",
                      where="upper(username)=upper($username)",
                      vars=dict(username=username))
コード例 #53
0
from __future__ import print_function
from catalog.read_rc import read_rc
import web
import sys
rc = read_rc()
web.config.db_parameters = dict(dbn='mysql',
                                db='archive',
                                user=rc['ia_db_user'],
                                pw=rc['ia_db_pass'],
                                host=rc['ia_db_host'])
web.load()

row = list(
    web.select(
        'metadata',
        what='count(*) as num',
        where="scanner = 'google' and mediatype='texts' and noindex is null"))
print('Image PDFs:', row[0].num)

row = list(
    web.select(
        'metadata',
        what='count(*) as num',
        where="scanner != 'google' and noindex is null and mediatype='texts'"))
print('Scanned books:', row[0].num)

sys.exit(0)

for row in web.select('metadata', scanner='google'):
    print(row.identifier)
コード例 #54
0
 def GET(self):
     print render.header()
     print render.places(web.select('places', order='id desc'))
     print render.footer()
コード例 #55
0
def get_type_id(type):
    w = "key='" + type + "' and site_id=1"
    return web.select('thing', what='id', where=w)[0].id
コード例 #56
0
 def getlocal(self, id):
     ret = {}
     for i in web.select('places_description', where='id=%d' % id):
         ret[i.name] = i.value
     return ret