示例#1
0
 def delete_note(self, note_id, modifier_id):
     note = Note.get_by_key(int(note_id))
     if note.is_trashed:
         tag.delete_tagmodels(modifier_id, model_nk=(Note.get_modelname(), note.uid), modifier_id=modifier_id)
         filex.delete_files(note.creator_id, model_nk=(Note.get_modelname(), note.uid), modifier_id=modifier_id)
         note.delete(modifier_id)
     else:
         if note.creator_id != modifier_id:
             raise Error("note_error_deletesharednote")
         self.trash_notes([note.uid], True, modifier_id)
     return True
示例#2
0
 def fetch_notes(self, user_id, filters=None, limit=20, offset=0):
     
     def append_filters(query):
         for ft in filters:
             for (key, value) in ft.items():
                 for nr in NOTERESOLVERS:
                     nrinst = nr(key, value)
                     query.extend(nrinst)
                 
     query = Note.all(alias="a")
     query.select("DISTINCT")
     query.order("-a.uid")
     
     notebook_ids = self.fetch_my_notebooks(user_id, onlyrtnids=True)
     if len(notebook_ids) > 0:
         query.filter("a.notebook_id in", notebook_ids, parenthesis="(")
         query.filter("a.creator_id =", user_id, logic="or", parenthesis=")")
     else:
         query.filter("a.creator_id =", user_id)
     
     if filters is not None:
         append_filters(query)
         
     if not query.has_filter("a.is_trashed"):
         query = query.filter("a.is_trashed =", False)
         
     def note_proc(note):
         ''''''
     
     return query.fetch(limit, offset, paging=True, model_proc=note_proc)
 def get(self):
   template_values={}
   template_values["notetemplate"]=file(os.path.join(os.path.dirname(__file__),'note.tmpl')).read()
   template_values["notes"]=Note.gql("")
   template_values["emptynote"]={"id":"notetemplate","title":"","content":""}
   path = os.path.join(os.path.dirname(__file__), 'index.html')
   logging.info(template_values["notetemplate"])
   self.response.out.write(template.render(path, template_values))
示例#4
0
 def update_note(self, note, modifier_id):
     nt = Note.get_by_key(note.uid)
     if note.creator_id != modifier_id and nt.notebook_id != note.notebook_id:
         raise Error("note_error_movesharednote")
     if nt.is_trashed : 
         raise Error("note_error_trashed_update")
     note.put(modifier_id)
     return note
示例#5
0
 def delete_notebook(self, notebook_id, modifier_id):
     notebook = Notebook.get_by_key(notebook_id)
     notebook.delete(modifier_id)
     query = Note.all()
     query.filter("notebook_id =", notebook_id)
     query.set("notebook_id", EMPTY_UID)
     query.set("is_trashed", True)
     query.update(modifier_id)
     query = Notebook.all()
     return True
 def get(self):
     template_values = {}
     template_values["notetemplate"] = file(
         os.path.join(os.path.dirname(__file__), 'note.tmpl')).read()
     template_values["notes"] = Note.gql("")
     template_values["emptynote"] = {
         "id": "notetemplate",
         "title": "",
         "content": ""
     }
     path = os.path.join(os.path.dirname(__file__), 'index.html')
     logging.info(template_values["notetemplate"])
     self.response.out.write(template.render(path, template_values))
示例#7
0
 def get_notecount(self, is_trashed, user_id, notebook_id=None):
     query = Note.all()
     query.filter("is_trashed =", is_trashed)
     if notebook_id != None and notebook_id != model.EMPTY_UID:
         query.filter("notebook_id =", notebook_id)
     elif notebook_id == model.EMPTY_UID:
         query.filter("notebook_id =", notebook_id)
         query.filter("creator_id =", user_id)
     else:
         query.filter("creator_id =", user_id)
     if notebook_id != None:
         query.filter("notebook_id =", notebook_id)
     return query.count()
示例#8
0
 def recover_note(self, note_id, notebook_id, modifier_id):
     note = Note.get_by_key(note_id)
     note.is_trashed = False
     note.notebook_id = notebook_id
     note.put(modifier_id)
     return note
示例#9
0
 def empty_trash(self, user_id, modifier_id):
     query = Note.all()
     query.filter("is_trashed =", True)
     query.filter("creator_id =", user_id)
     status = query.delete(modifier_id)
     return status
示例#10
0
 def trash_notes(self, note_ids, is_trashed, modifier_id):
     for note_id in note_ids:
         note = Note.get_by_key(note_id)
         note.is_trashed = is_trashed
         note.put(modifier_id)
     return True
示例#11
0
 def get_note(self, note_id):
     note = Note.get_by_key(note_id)
     return note
示例#12
0
 def move_note(self, note_id, notebook_id, modifier_id):
     note = Note.get_by_key(note_id)
     note.notebook_id = int(notebook_id)
     note.put(modifier_id)
     return note