Example #1
0
File: note.py Project: pekrau/notes
 def get_tags(self):
     tags = set()
     for tag in self.rqh.get_arguments('existing_tags'):
         tags.add(utils.normalize(tag))
     for tag in self.rqh.get_argument('new_tags', '').split('\n'):
         tags.add(utils.normalize(tag))
     self['tags'] = [t for t in sorted(tags) if t]
Example #2
0
File: tag.py Project: pekrau/notes
 def get(self, tag):
     tag = utils.normalize(tag)
     count = self.get_tag_count(tag)
     paging = self.get_paging_parameters(count=count)
     view = self.db.view('tag/modified',
                         include_docs=True,
                         descending=True,
                         startkey=[tag, constants.CEILING],
                         endkey=[tag],
                         skip=paging['skip'],
                         limit=paging['limit'])
     notes = [r.doc for r in view]
     if count == 1:
         self.see_other('note', notes[0]['_id'])
         return
     if count == 0:
         error = "No such tag '{}'".format(tag)
     else:
         error = None
     self.render('tag.html', tag=tag, notes=notes, error=error, **paging)
Example #3
0
def create_user(db):
    "Get user information from command line."
    print('Provide information for the new user...')
    username = raw_input('username > ')
    if not username:
        raise ValueError('username is required')
    if not constants.NAME_RX.match(username):
        raise ValueError('invalid username')
    view = db.view('user/username')
    if len(view[username]) > 0:
        raise ValueError('username already in use')
    email = raw_input('email > ')
    if not email:
        raise ValueError('email is required')
    if not constants.EMAIL_RX.match(email):
        raise ValueError('invalid email')
    role = raw_input('role [admin] > ')
    if not role:
        role = 'admin'
    role = utils.normalize(role)
    if role not in constants.ROLES:
        raise ValueError('invalid role')
    password = getpass.getpass('password > ')
    if not password:
        raise ValueError('password is required')
    if len(password) < constants.MIN_PASSWORD_LENGTH:
        raise ValueError("too short password; must be at least {} characters".
                 format(constants.MIN_PASSWORD_LENGTH))
    doc = {'_id': utils.get_iuid(),
           constants.DOCTYPE: constants.USER,
           'username': username,
           'email': email,
           'role': role,
           'password': utils.hashed_password(password),
           'owner': username,
           'created': utils.timestamp(),
           'modified': utils.timestamp()}
    db.save(doc)
Example #4
0
 def get(self):
     "Get title and process into same state as index in database."
     orig = self.get_argument('title', '')
     # Keep this in sync with JavaScript 'keyword.js'
     title = orig.replace(':', ' ')
     title = title.replace(',', ' ')
     title = title.replace("'", ' ')
     title = utils.normalize(title)
     iuids = set()
     view = self.db.view('note/keyword')
     id_sets = []
     for part in [p for p in title.split() if len(p) > 2]:
         id_sets.append(set([r.id for r in
                             view[part : part+constants.CEILING]]))
     if id_sets:
         id_set = reduce(lambda i,j: i.intersection(j), id_sets)
         result = [self.get_note(id) for id in id_set]
     else:
         result = []
     if len(result) == 1:
         self.see_other('note', result[0]['_id'])
     result.sort(lambda i,j: cmp(i['modified'], j['modified']), reverse=True)
     paging = self.get_paging_parameters(len(result))
     self.render('search.html', notes=result, title=orig, **paging)
Example #5
0
File: note.py Project: pekrau/notes
 def get_title(self):
     self['title'] = self.rqh.get_argument('title', None) or '[no title]'
     self['title_normalized'] = utils.normalize(self['title'])