Example #1
0
 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
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
    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)
Example #6
0
 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)
Example #7
0
 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
Example #8
0
 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)
Example #9
0
    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)
Example #10
0
    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)
Example #11
0
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()
Example #12
0
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)
Example #13
0
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))
Example #14
0
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()
Example #15
0
#!/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)
Example #16
0
#!/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