Exemple #1
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}
Exemple #2
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.')
Exemple #3
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.')