예제 #1
0
 def save(self, session):
     obj = self.get_session(session.sid) or Session(sid=session.sid)
     try:
         obj.set_data(dict(session))
         obj.save()
         db.commit()
     except pickle.PickleError:
         pass
예제 #2
0
 def save(self, session):
     obj = self.get_session(session.sid) or Session(sid=session.sid)
     try:
         obj.set_data(dict(session))
         obj.save()
         db.commit()
     except pickle.PickleError:
         pass
예제 #3
0
 def reset(self,data):
     """
     Acceptable list structures:{
         name:name,
         value:reset to value
     }
     """
     counter=self.all().filter('name ==', data['name']).first()
     if counter is not None:
         counter.count=data['value']
         self.save()
         db.commit()
         return counter.key
예제 #4
0
def save(name):

    revision = Page.by_name(name)
    text = request.form.get('text')
    note = request.form.get('note')

    if request.form.get('cancel') or \
        revision and revision.text == text:
        return web.redirect(web.url_for('show', name=name))
    elif not text:
        error = _('You cannot save empty revisions.')
    else:
        note = request.form.get('note', '')
        page = revision.page if revision else Page(name=name)
        revision = Revision(text=text, page=page, note=note)
        revision.save()
        db.commit()

    return web.redirect(web.url_for('show', name=name))
예제 #5
0
def revert(name):
    """Revert an old revision."""
    rev_id = request.args.get('rev')
    try:
        rev_id = int(rev_id)
    except:
        pass

    old_revision = page = None
    error = _('No such revision')

    if request.method == 'POST' and request.form.get('cancel'):
        return web.redirect(web.url_for('show', name=page_name))

    if rev_id:
        old_revision = Page.by_revision(rev_id)
        if old_revision:
            new_revision = Page.by_name(name)
            if old_revision == new_revision:
                error = _('You tried to revert the current active ' \
                          'revision.')
            elif old_revision.text == new_revision.text:
                error = _('There are no changes between the current ' \
                          'revision and the revision you want to ' \
                          'restore.')
            else:
                error = ''
                page = old_revision.page
                if request.method == 'POST':
                    note = request.form.get('note', '')
                    note = 'revert' + (note and ': ' + note or '')
                    revision = Revision(page=page, text=old_revision.text,
                                         note=note)
                    revision.save()
                    db.commit()
                    return web.redirect(web.url_for('show', name=name))

    return web.render_template('revert.html',
        error=error,
        old_revision=old_revision,
        revision=page
    )
예제 #6
0
 def updateCount(self,data):
     """
     Acceptable list structures:{
         name:name,
         value:value to update,
         default:value if record dosen't exist
     }
     """
     counter=self.all().filter('name ==', data['name']).first()
     if counter is None:            
         self.count=abs(data['default'])
         self.name=data['name']
         self.save()
         db.commit()
         return self.key
     else:
         counter.count+=data['value']
         counter.save()
         db.commit()
         return counter.key
예제 #7
0
 def updateKeyWord(self,data):
     """
     Acceptable list structures:{
     keyWordList:[
             {
                 key:key,
                 keywords:[],
                 answers:[]
             }
         ] 
     }
     """
     keyWordMainList=data['keyWordList']
     
     for keyWordSubList in keyWordMainList:
         if keyWordSubList['key'] is not None:
             try:
                 keyWord=self.get(keyWordSubList['key'])
             except:
                 keyWord=None
                 
             if keyWord is None:
                 self.keyWordList=json.dumps(keyWordSubList['keywords'])
                 self.answerList=json.dumps(keyWordSubList['answers'])
                 keyWordKey=self.save()
                 counter=Counter()
                 counterData={'name':'KeyWord'}
                 counter.increase(counterData)
             else:
                 keyWord.keyWordList=json.dumps(keyWordSubList['keywords'])
                 keyWord.answerList=json.dumps(keyWordSubList['answers'])
                 keyWordKey=keyWord.save()
         else:
                 self.keyWordList=json.dumps(keyWordSubList['keywords'])
                 self.answerList=json.dumps(keyWordSubList['answers'])
                 keyWordKey=self.save()
                 counter=Counter()
                 counterData={'name':'KeyWord'}
                 counter.increase(counterData)
     db.commit()
     return keyWordKey
예제 #8
0
 def delete(self, session):
     obj = self.get_session(session.sid)
     if obj:
         obj.delete()
         db.commit()
예제 #9
0
 def delete(self, session):
     obj = self.get_session(session.sid)
     if obj:
         obj.delete()
         db.commit()