示例#1
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('/')
示例#2
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))
示例#3
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)        
示例#4
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('/')
示例#5
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('/')
示例#6
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)