Beispiel #1
0
 def _on_root_selected(self):
     notes = list(Note.select().order_by(self.header_panel.sort_option))
     self.header_panel.set_title('所有笔记')
     self.header_panel.set_count(len(notes))
     self._load(notes)
     self._notebook = None
     self.header_panel.reset_search_bar()
Beispiel #2
0
def note_list():
    user_token = auth_verify(dict(request.headers))
    collection = []
    list_notes = Note.select().where(Note.owner_id == user_token["id"])
    for note in list_notes:
        owner = note.owner.to_dict()
        note = note.to_dict()
        note.update({"owner": owner})
        collection.append(note)
    return parse_response(collection)
Beispiel #3
0
 def _on_note_searching(self, keyword, is_global_search):
     if keyword:
         if is_global_search or not self._notebook:
             notebook_id = None
         else:
             notebook_id = self._notebook.id
         note_ids = self.searcher.search(keyword, notebook_id=notebook_id)
         if note_ids:
             notes = list(Note.select().where(
                 Note.id.in_(note_ids)).order_by(
                     self.header_panel.sort_option))
         else:
             notes = []
         self._load(notes)
         self.header_panel.set_count(len(notes))
     else:
         if self._notebook:
             self._on_notebook_selected(self._notebook)
         else:
             self._on_root_selected()
Beispiel #4
0
 def _on_note_sorting(self, sort_param):
     notes = list(Note.select().where(Note.id.in_(
         self._note_ids)).order_by(sort_param))
     self._load(notes, True)
def get_all_notes(id=None):

  response.headers['Content-Type'] = 'application/json'
  if request.method == "OPTIONS":
    return response

  else:
    
    queries = ""

    ## TODO : Check documentation to find another way, maybe use keys instead of len
    if len(request.query) > 0:
      queries = QueryComposer.computeRequestQueries(Note,request.query.decode())

    if not id:

      schema = NoteSchema(many=True)

      if queries:

        notes = Note()

        if queries.get('selection',False):
          notes = Note.select(*queries['selection'][0])
          showOnSerializer = addSerializerParameters(queries['selection'][1], 'links')
          schema.only = showOnSerializer

        else:
          notes = notes.select()

        if queries.get('sort', False):
          notes = notes.order_by(*queries['sort'])
        else:
          notes = notes.order_by(Note.id)

        notes = notes.paginate(queries['pagination'][0],queries['pagination'][1])

        if queries.get('search',False):
          notes = notes.where(queries['search'])
        
        # schema = NoteSchema(many=True)

      else:

        notes = Note.select()
        #notes = notes.paginate(1,5)

      searchCount = notes.count()

      # TDO : Refactor this section, maybe put link generation on Links class
      links = Links()
      links.setLinks(request,searchCount)
      lschema = LinkSchema()
      lschema.only = links._getVisibleFields()
      jsonLinks = lschema.dumps(links)

      jsonNotes = schema.dumps(notes)
      jsonComplete = mergeJson(jsonLinks, jsonNotes)

      return jsonComplete
 
    else:

      notes = Note.get(Note.id == id)
      schema = NoteSchema()

      jsonNotes = schema.dumps(notes)

      return jsonNotes.data