Esempio n. 1
0
def create_note(uid):
  is_logged_in_as(uid)

  text = req.json.get('text', u'')
  note = Note(text, parent=req.user)

  tags = req.json.get('tags', [])
  for tag_str in tags:
    tag = req.user.tags.by_tag(tag_str)
    if not tag:
      tag = Tag(tag_str, parent=req.user)
    note.tags.add(tag)

  return note.json()
Esempio n. 2
0
def notes(request, year=None, month=None):
    db = default_storage()
    notes = Note.objects(db).order_by('date', reverse=True)
    if year:
        notes = notes.where(date__year=year)
        if month:
            notes = notes.where(date__month=month)
    return {'notes': notes}
Esempio n. 3
0
def ls(args):
    "Lists all existing notes."
    db = default_storage()
    notes = Note.objects(db).order_by(['date', 'text'], reverse=True)
    notes_cnt = notes.count()
    if notes_cnt:
        print('There are {0} notes:'.format(notes_cnt))
        print('---')
        for num, note in enumerate(notes):
            print(u'#{num} {date} {text}'.format(num=num, **note))
    else:
        print('There are no notes in the database.')
Esempio n. 4
0
def update_note(uid, nid, text=None, tags=None):
  is_logged_in_as(uid)

  note = Note.by_guid(nid)
  if text:
    note.value = text

  if tags:
    add_tags = set(tags)

    for tag in note.tags(nodes=True):
      if tag.value not in add_tags:
        note.tags.remove(tag)
      else:
        add_tags.remove(tag)

    for tag in add_tags:
      note.tags.add(Tag(tag))

  note.save()
  return 
Esempio n. 5
0
def drop(args):
    """Deletes given notes from the database. If note number is not specified,
    deletes all notes.
    """
    db = default_storage()
    notes = Note.objects(db).order_by(['date', 'text'], reverse=True)
    if args.number:
        choices = dict(enumerate(notes))
        try:
            note = choices[args.number]
        except KeyError:
            print('There is no note #{0}'.format(args.number))
        else:
            note.delete()
            print('Note "{text}" ({date}) has been deleted.'.format(**note))
    elif args.all:
        notes.delete()
        print('All notes have been deleted.')
    else:
        print args
        print('Please specify either --number or --all.')