def get(self, alias=None): """ check required data """ if alias is None: return self.redirect('http://www.knonce.com/') """ get unit """ unit = Unit.query(Unit.alias==alias.lower()).get() if unit is None: return self.redirect('http://www.knonce.com/') """ grab latest ten notes """ notes, cursor, more = Note.query(ancestor=unit.key).order(Note.date).fetch_page(10, projection=['date', 'short', 'title', 'summary']) pageval = { 'unit': unit, 'host': 'www.%s'%HOST, 'cursor': cursor.urlsafe() if cursor else None, 'more': more, 'notes': OrderedDict() } for note in notes: if note.date.date() not in pageval['notes']: pageval['notes'][note.date.date()] = [] pageval['notes'][note.date.date()].append(note) self.render('unit/home.html', pageval)
def make_note(self, note, unit, en_note, en_content): if note is None: note = Note(id='en-%s'%en_note.guid, parent=unit.key) """ set note title """ en_note.title = en_note.title #.decode('utf-8') if note.title != en_note.title: note.title = en_note.title """ handle english and non-english short name """ if all(c in string.printable for c in en_note.title): short = '-'.join(re.findall('\w+', en_note.title)).lower() else: #short = urllib.quote(en_note.title.encode('utf-8')).lower() #short = re.sub('\W+', '-', en_note.title.encode('utf-8')).lower() short = re.sub('\s+', '-', en_note.title, flags=re.U).lower() """ if short name is too long or duplicated """ retry = 0 while len(short) > 450 or Note.query(Note.short==short, ancestor=unit.key).get() is not None: short = self.get_lazy_short_name(unit.key) retry += 1 if retry >= 10: logging.error('en-note-guid = %s, faild to create lazy short name.' % en_note.guid) raise Exception note.short = short note.content = parse.parse_evernote(en_content) note.summary = parse.create_summary(note.content) note.usn = en_note.updateSequenceNum note.updated = en_note.updated note.created = en_note.created note.put()
def get(self, alias=None, short=None): """ check required data """ if alias is None: return self.redirect('http://www.knonce.com/') """ get unit """ unit = Unit.query(Unit.alias==alias.lower()).get() if unit is None: return self.redirect('http://www.knonce.com/') """ check required data """ if short is None: return self.redirect('/') """ get note """ logging.info(short.lower()) note = Note.query(Note.short==short.lower()).get() if note is None: return self.redirect('/') pageval = { 'host': 'www.%s'%HOST, 'unit': unit, 'note': note } self.render('unit/post.html', pageval)