예제 #1
0
def make_entry(rec):
    """docstring for make_entry"""
    body = rec.get('body')
    body_html = markdown2.markdown(body)
    rec.update({'body_html': body_html})
    slug = rec.get('slug')
    title = rec.get('title')
    excerpt = rec.get('excerpt')
    markdown = rec.get('markdown') or 'markdown'
    tags = rec.get('tags') or []
    if len(tags) == 0:
        tags = ['general']
    tags = [db.Category(utils.slugify(tag)) for tag in tags if tag]
    
    static = rec.get('static')
    
    if not slug:
        utils.slugify(title)
        
    if not excerpt:
        soup = BeautifulSoup.BeautifulSoup(body_html)
        paras = soup.findAll('p')
        if paras:
            excerpt = paras[0].string
    return Entry(author=users.get_current_user(),
    title=title,
    slug=slug,
    body=body,
    body_html=body_html,
    markdown=markdown,
    excerpt=excerpt,
    tags= tags,
    static=static,
    )
예제 #2
0
파일: search.py 프로젝트: ThomasMarcel/thas
	def search(self, text):
		self.text = text.lower().replace('\n', ' ').replace('\r', ' ').replace('\t', ' ')
                self.purgedlist = []
                for punct in self.punctuation:
                        self.text = self.text.replace(punct, ' ')
                for word in self.text.split(' '):
                        if word not in self.garbage and word != '':
                                self.purgedlist.append(word)
		wordlist = []
		sortedlist = []
		for pword in self.purgedlist:
			keywords = Keyword.all().filter("word =", pword).run()
			for keyword in keywords:
				worddict = {'word': keyword.word, 'key': keyword.entitykey, 'type': keyword.wordtype}
				wordlist.append(worddict)
		wordlist = sorted(wordlist, key=lambda k: k['key'])
		try:
			if len(wordlist) > 0:
				entry = Entry.get(wordlist[0]['key'])
				worddict = {'word': [wordlist[0]['word']], 'key': wordlist[0]['key'], 'type': [wordlist[0]['type']], 'entitytype': 'Blog', 'commonwords': 1, 'entrytitle': entry.title, 'entrydesc': entry.body.replace('\r', ' ').replace('\n', ' ').replace('\t', ' ')[0:300], 'entityid': entry.key().id()}
				for i in range(len(wordlist)):
					logging.info(str(i) + ' - ' + str(wordlist[i]))
					if i == 0:
						pass
					else:
						if wordlist[i]['key'] == worddict['key']:
							if wordlist[i]['word'] not in worddict['word']:
								worddict['word'].append(wordlist[i]['word'])
								worddict['commonwords'] += 1
							if wordlist[i]['type'] not in worddict['type']:
								worddict['type'].append(wordlist[i]['type'])
						else:
							sortedlist.append(worddict)
							entry = Entry.get(wordlist[i]['key'])
							worddict = {'word': [wordlist[i]['word']], 'key': wordlist[i]['key'], 'type': [wordlist[i]['type']], 'entitytype': 'Blog', 'commonwords': 1, 'entrytitle': entry.title, 'entrydesc': entry.body.replace('\r', ' ').replace('\n', ' ').replace('\t', ' ')[0:300], 'entityid': entry.key().id()}
				sortedlist.append(worddict)
		except KeyError:
			logging.error('KeyError')
		return sorted(sortedlist, key=lambda k: k['commonwords'], reverse=True)
예제 #3
0
 def get(self):
     entries = Entry.all().order("-published")
     self.render("templates/admin_entrylist.html",
         entries=entries)
예제 #4
0
파일: admin.py 프로젝트: Sam-Daniel/teh
 def get(self):
     entries = Entry.all().order("-published")
     self.render("templates/admin_entrylist.html", entries=entries)