def doindex(handler): tagname=handler.request.get('tag') entries=[] if tagname: tag=Tag.all().filter('name = ', tagname).get() if tag and tag.tagedEntries: for tagedEntry in tag.tagedEntries: if not(tagedEntry.entry.cparent) and tagedEntry.entry.user and tagedEntry.entry.user.nickname()=='JoeyKBlack': entries.append(tagedEntry.entry) else: for entry in Entry.all().fetch(100): if not(entry.cparent) and entry.user and entry.user.nickname()=='JoeyKBlack': entries.append(entry) entries.reverse() util.imageafi(entries) template_values = { 'entries':entries, 'ispost':users.is_current_user_admin(), 'filters':util.filters('') } template_values.update(util.loadstd(handler)) path = os.path.join(os.path.dirname(__file__), '../html/index.html') handler.response.out.write(template.render(path, template_values))
def dropdb(): for tagedEntry in TagedEntry.all().fetch(100): tagedEntry.delete() for entry in Entry.all().fetch(100): entry.delete() for tag in Tag.all().fetch(100): tag.delete() for luser in Minime.all().fetch(100): luser.delete()
def get(self): key=self.request.get('topkey') if key: entry=Entry.get(key) else: index.doindex(self) return entryform=EntryForm() editkey=self.request.get('editkey') tags='' if editkey: editentry=Entry.get(editkey) if editentry: if editentry.type=='Text': editentry.text=editentry.text.replace('<br />', '\n') entryform=EntryForm(instance=editentry) for tagged in editentry.tagedEntries: tags+=tagged.tag.name+',' tags=tags[0:-1] #takes off last char deletekey=self.request.get('deletekey') deleted=False if deletekey: deleteentry=Entry.get(deletekey) if deleteentry: delete.deleteEntry(deleteentry) deleted=True template_values = { 'editkey':editkey, 'up':up(entry), 'deleleted':deleted, 'comments':commentsHtml(top=entry,entry=entry), 'entryform':entryform, 'topkey':key, 'tags':tags } template_values.update(util.loadstd(self)) path = os.path.join(os.path.dirname(__file__), '../html/comments.html') self.response.out.write(template.render(path, template_values))
def get(self): util.vote(self) entryform=EntryForm() editkey=self.request.get('editkey') tags='' if editkey: editentry=Entry.get(editkey) if editentry: if editentry.type=='Text': editentry.text=editentry.text.replace('<br />', '\n') entryform=EntryForm(instance=editentry) for tagged in editentry.tagedEntries: tags+=tagged.tag.name+',' tags=tags[0:-1] #takes off last char deletekey=self.request.get('deletekey') if deletekey: deleteentry=Entry.get(deletekey) if deleteentry: delete.deleteEntry(deleteentry) dopostit(self, entryform=entryform, editkey=editkey, tags=tags)
def post(self): key=self.request.get('topkey') entry=Entry.get(key) util.saveEntry(self) template_values = { 'up':up(entry), 'comments':commentsHtml(top=entry,entry=entry), 'entryform':EntryForm(), 'topkey':key } template_values.update(util.loadstd(self)) path = os.path.join(os.path.dirname(__file__), '../html/comments.html') self.response.out.write(template.render(path, template_values))
def vote(handler): localuser = Minime.all().filter("user = "******"votekey") if votekey: localuser.votes -= 1 localuser.put() vote = handler.request.get("vote") entry = Entry.get(votekey) if entry: if not (entry.votes): entry.votes = 0 if vote == "up": entry.votes += 1 else: entry.votes -= 1 entry.put()
def dopostit(handler, entryform=EntryForm(), editkey='', tags=''): tagname=handler.request.get('tag') entries=[] if tagname: tag=Tag.all().filter('name = ', tagname).get() if tag and tag.tagedEntries: for tagedEntry in tag.tagedEntries: if not(tagedEntry.entry.cparent): entries.append(tagedEntry.entry) else: for entry in Entry.all().fetch(100): if not(entry.cparent): entries.append(entry) entries.reverse() util.imageafi(entries) username='' if users.get_current_user(): username=users.get_current_user().nickname() template_values = { 'currentuser':username, 'filters':util.filters('postit'), 'entryform':entryform, 'entries':entries, 'editkey':editkey, 'tags':tags } template_values.update(util.loadstd(handler)) path = os.path.join(os.path.dirname(__file__), '../html/postit.html') handler.response.out.write(template.render(path, template_values))
def saveEntry(handler): # load form key = handler.request.get("editkey") if key: entry = Entry.get(key) entry = EntryForm(data=handler.request.POST, instance=entry).save(commit=False) else: entry = EntryForm(handler.request.POST).save(commit=False) # get user user = users.get_current_user() if user: entry.user = user localuser = Minime.all().filter("user = "******"alias") if alias: entry.by = alias elif users.get_current_user(): entry.by = users.get_current_user().nickname() else: entry.by = "stranger" # image img = handler.request.get("img") if img: entry.img = db.Blob(img) # replace \n on text with <br /> but not on html entries if entry.type == "Text": entry.text = entry.text.replace("\n", "<br />") # set parent topkey = handler.request.get("topkey") if topkey: cparent = Entry.get(topkey) if cparent: entry.cparent = cparent # save entry.put() # tag (entry must be saved) tagnames = handler.request.get("tags") if tagnames: tagnames = tagnames.split(",") for tagname in tagnames: tag = Tag.all().filter("name = ", tagname).get() if tag: if model.blog.containsEntry(tag.tagedEntries, entry) == -1: TagedEntry(tag=tag, entry=entry).put() elif not (tag): tag = Tag(name=tagname).put() TagedEntry(tag=tag, entry=entry).put() # removed tags if entry.tagedEntries: for tagedEntry in entry.tagedEntries: found = False if tagnames: for tagname in tagnames: if tagedEntry.tag.name == tagname: found = True if not (found): if len(tagedEntry.tag.tagedEntries.fetch(100)) == 1: tagedEntry.tag.delete() tagedEntry.delete()