Ejemplo n.º 1
0
 def GET(self):
     """Add your own key in server config"""
     web.header('Content-Type', 'application/json')
     i = web.input(key="")
     if i.key == server['secret']:
         db = Db(server['paths']['db'])
         return db.get('analytics')
Ejemplo n.º 2
0
    def POST(self):
        if not session().logged:
            raise web.seeother('/register')

        i = web.input(authors="",
                      url=None,
                      title=None,
                      comments=[],
                      year=None,
                      enabled=True,
                      subtitle='',
                      time=datetime.utcnow(),
                      votes=1,
                      cite={
                          'mla': '',
                          'apa': '',
                          'chicago': ''
                      })
        db = Db('db/openjournal')

        def next_pid():
            papers = db.get('papers')
            return papers[-1]['pid'] + 1 if papers else 0

        i.submitter = session()['uname']
        if i.authors:
            i.authors = map(self.parse_author, i.authors.split(','))
        i.pid = next_pid()
        record_submission(i.submitter, i.pid)
        record_vote(i.submitter, i.submitter, i.pid)
        db.append('papers', dict(i))
        Search().index()
        raise web.seeother('/')
Ejemplo n.º 3
0
 def test_put(self):
     db = Db(DB_PATH)
     db.put(TEST_KEY, TEST_VAL)
     db_val = db.get(TEST_KEY)
     print("PUT: %s, GET: %s" % (TEST_ITEM, db_val))
     self.assertTrue(db_val.__dict__ == TEST_VAL.__dict__,
                     "Failed to 'put' TEST_ITEM %s "
                     "into %s" % (TEST_ITEM, DB_NAME))
Ejemplo n.º 4
0
 def GET(self):
     i = web.input(sort="popular", limit=30)
     db = Db('db/openjournal')
     papers = db.get('papers')
     try:
         papers = globals()[i.sort](papers)
     except:
         papers = popular(papers)
     return render().index(papers[:i.limit])
Ejemplo n.º 5
0
 def inner(*args, **kwargs):
     """Copy web context environment, clean it to avoid
     pickeling issues, and dump it to lazydb before returning
     the route
     """
     db = Db(server['paths']['db'])
     ctx = copy(web.ctx['env'])
     del ctx['wsgi.errors']
     del ctx['wsgi.input']
     db.append('analytics', ctx)
     return fn(*args, **kwargs)        
Ejemplo n.º 6
0
    def POST(self):
        i = web.input(authors=None, url=None, title=None, comments=[],
                      year=None, enabled=False, submitter='',
                      subtitle='', time=datetime.utcnow(),
                      cite={'mla': '', 'apa': '', 'chicago': ''})
        i.authors = map(parse_author, i.authors.split(','))

        # abstract db out of routes
        db = Db('db/openjournal')
        db.append('papers', dict(i))
        raise web.seeother('/')
Ejemplo n.º 7
0
 def test_get_keyerror(self):
     """Tests a db.get(key) on a key which doesn't exist"""
     db = Db(DB_PATH)
     v = None
     try:
         v = db.get(TEST_KEY + "KEYERROR", default={}, touch=False)
     except KeyError:
         self.assertTrue(v is None, "db.get() touched/create a table "
                         "and it shouldn't have (because touch=False).")
     v = db.get(TEST_KEY + "KEYERROR", default={}, touch=True)
     self.assertTrue(v == {}, "db.get() was supposed to touched/create "
                     "a table but it didn't (because touch=True).")
Ejemplo n.º 8
0
 def GET(self):
     """Research http://news.ycombinator.com/item?id=1781013 how
     hacker news voting works and emulate
     """
     msg = None
     i = web.input(pid=None)
     db = Db('db/openjournal')
     if i.pid:
         ps = db.get('papers')
         if not session().logged:
             msg = JS("Must be logged in to vote")
         else:
             try:
                 ps[int(i.pid)]['votes'] += 1
                 db.put('papers', ps)
             except IndexError:
                 return "No such items exists to vote on"
         return render().index(ps, msg=msg)
Ejemplo n.º 9
0
    def POST(self):
        if not session().logged:
            raise web.seeother('/register')

        i = web.input(authors="", url=None, title=None, comments=[],
                      year=None, enabled=False, subtitle='',
                      time=datetime.utcnow(), votes=1,
                      cite={'mla': '', 'apa': '', 'chicago': ''})
        db = Db('db/openjournal')

        def next_pid():
            papers = db.get('papers')
            return papers[-1]['pid'] + 1 if papers else 0

        i.submitter = session()['uname']
        if i.authors:
            i.authors = map(self.parse_author, i.authors.split(','))
        i.pid = next_pid()
        record_submission(i.submitter, i.pid)
        record_vote(i.submitter, i.submitter, i.pid)
        db.append('papers', dict(i))
        Search().index()
        raise web.seeother('/')
Ejemplo n.º 10
0
 def test_append(self):
     db = Db(DB_PATH)
     db.put(TEST_KEY, TEST_VAL)
     db.append(TEST_KEY, TEST_VAL)
     db_val = db.get(TEST_KEY)
     print("APPEND: %s, GET: %s" % (TEST_ITEM, db_val))
     self.assertTrue(map(lambda x: x.__class__, db_val) ==
                     map(lambda x: x.__class__, [TEST_VAL] * 2),
                     "Failed to 'append' TEST_ITEM %s "
                     "into %s" % (TEST_ITEM, DB_NAME))
Ejemplo n.º 11
0
 def GET(self):
     db = Db('db/openjournal')
     return render().index(db.get('papers'))
Ejemplo n.º 12
0
 def disable(cls, uid):
     db = Db('db/{}'.format(DBNAME))
     tickets = db.get(cls.KEY)
     tickets[int(uid)].enabled = False
     return db.put(cls.KEY, tickets)
Ejemplo n.º 13
0
 def getall(cls):
     db = Db('db/{}'.format(DBNAME))
     return db.get(cls.KEY)
Ejemplo n.º 14
0
 def insert(self):
     """Inserts this obj instance into lazydb and returns the
     index (its id) of the obj within in resultant list 
     """        
     db = Db('db/{}'.format(DBNAME))
     return db.append(self.key, self)
Ejemplo n.º 15
0
 def tearDown(self):
     db = Db(DB_PATH)
     db._destroy()
     self.assertTrue(not os.path.exists(DB_PATH),
                     "Database failed to destroy tmp db %s" % DB_PATH)