def delete(self, *args): if self.params.key: item = Dictionary.get(self.params.key) if item: item.delete() self.status ='Dictionary is deleted!' else: self.status='Dictionary does not exist' else: self.status = 'Key was not Provided!' self.redirect(DictionaryController.get_url())
def index(self, *args): results =None index = 0; count=1000 try: index = int(self.params.index) count = int(self.params.count) except: pass result = {'DictionaryList': Dictionary.all().fetch(limit=count, offset=index)} result.update(locals()) self.respond(result)
def edit(self, *agrs): if self.params.key: item = Dictionary.get(self.params.key) if item: return {'op':'update', 'DictionaryForm': DictionaryForm(instance=item)} else: self.status = 'Dictionary does not exists' self.redirect(DictionaryController.get_url()) else: self.status = 'Key not provided' return {'op':'insert' ,'DictionaryForm':DictionaryForm()}
def save(self, *args): instance = None form = None if self.params.key: instance = Dictionary.get(self.params.key) if instance: form=DictionaryForm(data=self.request.POST, instance=instance) else: form = DictionaryForm(self.request.POST) else: form = DictionaryForm(self.request.POST) if form.is_valid(): result=form.save(commit=False) result.put() self.status = 'Dictionary is saved' self.redirect(DictionaryController.get_url()) else: self.SetTemplate(templateName = 'Dictionary_edit.html') self.status = 'Form is not Valid' return {'op':'update', 'DictionaryForm': form}