def get(self, threadnumber): thread = database.Thread.get_by_key_name(str(threadnumber)) if not thread: self.error(404) self.response.headers['Content-Type'] = "text/plain" self.response.out.write("I have carefully searched my index but I can't find thread #%s" % threadnumber) else: tags = [association.tag for association in database.findassociations(thread=thread)] path = os.path.join(os.path.dirname(__file__), 'templates/thread.html') self.response.out.write(template.render(path, {'tags':tags, 'thread':thread, 'forum':thread.forum}))
def get(self, tagname): tagname = unicode(urllib.unquote(tagname),'utf-8') tag = database.Tag.get_by_key_name(tagname) if not tag: self.error(404) self.response.headers['Content-Type'] = "text/plain; charset=utf-8" self.response.out.write("I have carefully searched my index but I can't find %s" % tagname) else: threads = [association.thread for association in database.findassociations(tag=tag)] path = os.path.join(os.path.dirname(__file__), 'templates/tag.html') self.response.out.write(template.render(path, {'tag':tag, 'threads':threads}))
def get(self): self.response.headers['Content-Type'] = "application/json" threadnumber = None try: threadnumber = int(self.request.get('thread')) except: self.error(400); return thread = database.Thread.get_by_key_name(str(threadnumber)) if not thread: array = None else: tags = [association.tag for association in database.findassociations(thread=thread)] array = [tag.name for tag in tags] self.response.out.write(json.dumps(array))
def get(self): self.response.headers['Content-Type'] = "application/json" force_recount = False force_recount = True if self.request.get('force_recount')=='True' else False if force_recount: self.response.headers['X-Check-mode'] = "Yes" array = [] for tag in database.Tag.all(): if force_recount: newcount = database.findassociations(tag=tag).count() if newcount != tag.count: self.response.out.write("# the tag %s had a wrong number of threads: %s instead of %s" % (tag.name, tag.count, newcount)) tag.count = newcount tag.put() return array.append([tag.name, tag.count]) self.response.out.write(json.dumps(array))
def post(self): origintagname = self.request.get('origin') destinationtagname = self.request.get('destination') origintag = database.Tag.get_by_key_name(origintagname) destinationtag = database.Tag.get_by_key_name(destinationtagname) self.response.headers['Content-Type'] = "text/plain; charset=utf-8" if origintag and destinationtag and origintag!=destinationtag: count = 0 for association in database.findassociations(tag=origintag, includecancelled=True): association.tag = destinationtag association.put() count += 1 destinationtag.count += count destinationtag.put() origintag.delete() self.response.out.write("tag %s renamed as %s (%s associations changed)" % (origintagname, destinationtagname, count)) else: self.response.out.write("Merge not successful:\n") if not origintag: self.response.out.write("- tag %s not found\n" % origintagname) if not destinationtag: self.response.out.write("- tag %s not found\n" % destinationtagname)