def input_edition_name(self, default=''): name = raw_input('\nbook edition? [%s] ' % default) or default self.edition = db.get_thing(name, db.get_type('type/edition')) if not self.edition: print '\nbook edition not found.' else: print '\nbook edition %s found.' % self.edition
def input_edition_name(self, default=''): name = raw_input('\nbook edition? [%s] ' % default) or default self.edition = db.get_thing(name, db.get_type('type/edition')) if not self.edition: print('\nbook edition not found.') else: print('\nbook edition %s found.' % self.edition)
def POST(self, site, user): form = forms.review_form() if form.validates(): edition = db.get_thing(form.d.edition, db.get_type('type/edition')) if not edition: return error() review = db.insert_book_review(edition, user, reviewsources.data.get('web'), form.d.text, title=form.d.title) return web.redirect('/' + edition.name + '#reviews') else: edition = db.get_thing(form.d.edition, db.get_type('type/edition')) if not edition: return error() return render.addreview(user, edition, form)
def GET(self, site, user): i = web.input('edition') edition = db.get_thing(i.edition, db.get_type('type/edition')) if not edition: return error() form = forms.review_form() form.fill(edition=edition.name) return render.addreview(user, edition, form)
def input_user_name(self, default=''): if not self.edition: raise quit() name = raw_input('\nreview author? [%s] ' % default) or default self.user = db.get_thing(utils.lpad(name, 'user/'), db.get_type('type/user')) if not self.user: print '\nreview author not found.' self.safety_lock('create a dummy user \'%s\'?' % name) self.user = create_dummy_user(name, password='******') print '\nok.' else: print '\nuser %s found.' % self.user
def input_user_name(self, default=''): if not self.edition: raise quit() name = raw_input('\nreview author? [%s] ' % default) or default self.user = db.get_thing(utils.lpad(name, 'user/'), db.get_type('type/user')) if not self.user: print('\nreview author not found.') self.safety_lock('create a dummy user \'%s\'?' % name) self.user = create_dummy_user(name, password='******') print('\nok.') else: print('\nuser %s found.' % self.user)
def GET(self, path): i = web.input(v=None, t=None) if not web.ctx.site.can_write(path): return render.permission_denied(path, "Permission denied to edit " + path + ".") if i.v is not None and safeint(i.v, None) is None: raise web.seeother(web.changequery(v=None)) p = db.get_version(path, i.v) or db.new_version(path, types.guess_type(path)) if i.t: type = db.get_type(i.t) if type is None: add_flash_message('error', 'Unknown type: ' + i.t) else: p.type = type return render.editpage(p)
def GET(self, path): i = web.input(v=None, t=None) if not web.ctx.site.can_write(path): return render.permission_denied(web.ctx.fullpath, "Permission denied to edit " + path + ".") if i.v is not None and safeint(i.v, None) is None: raise web.seeother(web.changequery(v=None)) p = db.get_version(path, i.v) or db.new_version(path, types.guess_type(path)) if i.t: type = db.get_type(i.t) if type is None: add_flash_message('error', 'Unknown type: ' + i.t) else: p.type = type return render.editpage(p)
def _new_version(name, typename, d): from infogami.core import db type = db.get_type(context.site, typename) db.new_version(context.site, name, type, d).save()
def list_latest_reviews(): for review in tdb.Things(type=db.get_type('type/bookreview'), limit=40): print '[%s] %s (%s)' % (review.author, review.book, review.source)
def list_latest_reviews(): for review in tdb.Things(type=db.get_type('type/bookreview'), limit=40): print('[%s] %s (%s)' % (review.author, review.book, review.source))
#!/usr/bin/python import os import cgi import cgitb cgitb.enable() import db con = db.connect() db.lock(con) try: type = db.get_type(con, os.environ['REMOTE_ADDR']) master = db.get_master(con) if type is None: if master: con.execute('INSERT INTO nodes (addr, type) VALUES (?,?)', (os.environ['REMOTE_ADDR'], "slave")) con.commit() type = "slave" else: con.execute('INSERT INTO nodes (addr, type) VALUES (?,?)', (os.environ['REMOTE_ADDR'], "master")) con.commit() type = "master" master = os.environ['REMOTE_ADDR'] finally: db.unlock(con)
#!/usr/bin/python import os import cgi import cgitb; cgitb.enable() import db con = db.connect() db.lock(con) try: type = db.get_type(con, os.environ['REMOTE_ADDR']) master = db.get_master(con) if type is None: if master: con.execute('INSERT INTO nodes (addr, type) VALUES (?,?)', (os.environ['REMOTE_ADDR'], "slave")) con.commit() type = "slave" else: con.execute('INSERT INTO nodes (addr, type) VALUES (?,?)', (os.environ['REMOTE_ADDR'], "master")) con.commit() type = "master" master = os.environ['REMOTE_ADDR'] finally: db.unlock(con) print "Content-Type: text/plain" print