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
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
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))
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 )
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
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
def delete(self, session): obj = self.get_session(session.sid) if obj: obj.delete() db.commit()