def get(self): v = {} term = self.request.get("term") v['term'] = term text_query = full_text_query(term) posts = [] for i in text_query: rec = db.get(i.doc_id) if rec == None: continue rec.snip = "" for e in i.expressions: regex = "<b>(%s)<\/b>" % (term) try: this_term = re.search(regex, e.value, flags=re.IGNORECASE).group(1) except: this_term = term highlighted = '<span class="highlight">%s</span>' % (this_term) this_snip = e.value.replace("<br", "") this_snip = utility.strip_tags(this_snip) rec.snip += re.sub(term, highlighted, this_snip, count=10, flags=re.IGNORECASE) posts.append(rec) v = {"results":posts} v['title'] = "Search Results" if len(posts) >= 1: v['count'] = 1 else: v['count'] = 0 v['offset'] = 0 v['Tag'] = Tag v = pictures.random_pic_update(v) render.page(self, "/templates/main/landing.html", v)
def get(self, qtype="blog", tagslug = None): v = {} v = pictures.random_pic_update(v) if qtype == 'blog': v['title'] = 'Home' q = models.Article.all().order('-pub_date') q = q.filter('collection =', 'blog') elif qtype.lower() == 'tag' and tagslug != None: v['title'] = 'tag search' tag = models.Tag.get_by_key_name(tagslug) if tag == None: tagkey = None v['tag'] = tagslug else: tagkey = tag.key() v['tag'] = tag.name q = models.Article.all().filter('tags =', tagkey) v['Tag'] = models.Tag if self.request.get('o') != "": offset = int(self.request.get('o')) else: offset = 0 v['results'] = q.fetch(10, offset=offset) v['count'] = q.count(offset=offset, limit=10) v['offset'] = offset + 10 if offset == 0: render.page(self, '/templates/main/landing.html', v) else: render.page(self, '/templates/main/article_links.html', v)