def post(self): if users.is_current_user_admin(): key = self.request.get('key') if key: e = db.get(key) else: e = Entry() type = self.request.get('type') if not type: type = 'link' title = self.request.get('title') e.title = title.replace('&', '&').replace('<', '<').replace( '>', '>') url = self.request.get('url') purl = self.request.get('purl') if type == 'pic' and not key: e.url = purl.replace('&', '&').replace('<', '<').replace( '>', '>') else: e.url = url.replace('&', '&').replace('<', '<').replace( '>', '>') content = self.request.get('content') e.content = content if not key: e.addtime += datetime.timedelta(hours=+8) e.private = bool(int(self.request.get('private'))) e.type = type if type == 'pic' and not key: if url: try: result = urlfetch.fetch(url) if result.status_code == 200: e.image = db.Blob(result.content) except: self.response.out.write('获取图片超时!') return else: myfile = self.request.get("myfile") if not myfile: self.response.out.write('没有选择文件!') return try: e.image = db.Blob(myfile) except: self.response.out.write('文件上传失败!') return if key: #更新数据 for oldtag in e.tags: tag = Tag.all().filter('name', oldtag) if (tag.count(1) > 0): t = tag.get() if type == 'link': t.count_link -= 1 if type == 'note': t.count_note -= 1 if type == 'pic': t.count_pic -= 1 t.put() else: #新增数据 max_pageCount = 900 #超过此数据,则pageid递增 entry = Entry.all().order('-addtime') if entry.count() > 0: cur_pageid = entry.get().pageid else: cur_pageid = 0 cur_pageCount = entry.filter('pageid =', cur_pageid).count(1000) if cur_pageCount >= max_pageCount: e.pageid = cur_pageid + 1 else: e.pageid = cur_pageid e.tags = [] tag_names = self.request.get('tags').split() for tag_name in tag_names: tag = Tag.all().filter('name', tag_name) if (tag.count(1) > 0): t = tag.get() if type == 'link': t.count_link += 1 if type == 'note': t.count_note += 1 if type == 'pic': t.count_pic += 1 t.usetime = datetime.datetime.now() t.put() else: t = Tag() t.name = tag_name if type == 'link': t.count_link = 1 if type == 'note': t.count_note = 1 if type == 'pic': t.count_pic = 1 t.usetime = datetime.datetime.now() t.put() e.tags.append(db.Category(tag_name)) e.put() self.redirect('/' + type + '/') else: self.redirect(users.create_login_url(self.request.uri))
def post(self): #********************** User Auth **************************# user = users.get_current_user() nickname = '' if user: nickname=user.nickname() if nickname: key = self.request.get('key') if key : e = db.get(key) if e.user != nickname: e = Entry() e.user = nickname else: e = Entry() e.user = nickname type = self.request.get('type') if not type: type = 'link' tz = self.request.get('tz') if tz[0:1]=='-': tz = int(tz[1:]) tz = -tz else: tz = int(tz[1:]) tz = +tz title = self.request.get('title') e.title = title.replace('&','&').replace('<','<').replace('>','>') url = self.request.get('url') purl= self.request.get('purl') if type == 'pic' and not key: e.url = purl.replace('&','&').replace('<','<').replace('>','>') else: e.url = url.replace('&','&').replace('<','<').replace('>','>') content = self.request.get('content') e.content = content if not key: e.addtime +=datetime.timedelta(hours=tz) e.private = bool(int(self.request.get('private'))) e.type = type if type =='pic' and not key: if url: try: result = urlfetch.fetch(url) if result.status_code == 200: e.image = db.Blob(result.content) except : self.response.out.write('Fetch picture fail! You can <a href="/add?type=pic">upload</a> it manually') return else: myfile = self.request.get("myfile") if not myfile: self.response.out.write( 'No file specified!') return try: e.image = db.Blob(myfile) except : self.response.out.write( 'Uploading fail!') return if key:#更新数据 for oldtag in e.tags: tag = Tag.all().filter("user",nickname).filter('name',oldtag) if(tag.count(1)>0): t = tag.get() if type == 'link': t.count_link -=1 if type == 'note': t.count_note -=1 if type == 'pic': t.count_pic -=1 t.put() else:#新增数据 max_pageCount =900 #超过此数据,则pageid递增 entry = Entry.all().order('-addtime') if entry.count()>0: cur_pageid = entry.get().pageid else: cur_pageid = 0 cur_pageCount = entry.filter('pageid =',cur_pageid).count(1000) if cur_pageCount>=max_pageCount: e.pageid = cur_pageid+1 else: e.pageid = cur_pageid e.tags = [] tag_names = self.request.get('tags').split() for tag_name in tag_names: tag = Tag.all().filter("user",nickname).filter('name',tag_name) if(tag.count(1)>0): t = tag.get() if type == 'link': t.count_link +=1 if type == 'note': t.count_note +=1 if type == 'pic': t.count_pic +=1 t.user = nickname t.usetime = datetime.datetime.now() t.put() else: t = Tag() t.name = tag_name if type == 'link': t.count_link =1 if type == 'note': t.count_note =1 if type == 'pic': t.count_pic =1 t.user = nickname t.usetime = datetime.datetime.now() t.put() e.tags.append(db.Category(tag_name)) e.put() self.redirect('/'+type+'/'+nickname) else: self.redirect(users.create_login_url(self.request.uri))
def post(self): if users.is_current_user_admin(): key = self.request.get('key') if key : e = db.get(key) else: e = Entry() type = self.request.get('type') if not type: type = 'link' title = self.request.get('title') e.title = title.replace('&','&').replace('<','<').replace('>','>') url = self.request.get('url') purl= self.request.get('purl') if type == 'pic' and not key: e.url = purl.replace('&','&').replace('<','<').replace('>','>') else: e.url = url.replace('&','&').replace('<','<').replace('>','>') content = self.request.get('content') e.content = content if not key: e.addtime +=datetime.timedelta(hours=+8) e.private = bool(int(self.request.get('private'))) e.type = type if type =='pic' and not key: if url: try: result = urlfetch.fetch(url) if result.status_code == 200: e.image = db.Blob(result.content) except : self.response.out.write('获取图片超时!') return else: myfile = self.request.get("myfile") if not myfile: self.response.out.write( '没有选择文件!') return try: e.image = db.Blob(myfile) except : self.response.out.write( '文件上传失败!') return if key:#更新数据 for oldtag in e.tags: tag = Tag.all().filter('name',oldtag) if(tag.count(1)>0): t = tag.get() if type == 'link': t.count_link -=1 if type == 'note': t.count_note -=1 if type == 'pic': t.count_pic -=1 t.put() else:#新增数据 max_pageCount =900 #超过此数据,则pageid递增 entry = Entry.all().order('-addtime') if entry.count()>0: cur_pageid = entry.get().pageid else: cur_pageid = 0 cur_pageCount = entry.filter('pageid =',cur_pageid).count(1000) if cur_pageCount>=max_pageCount: e.pageid = cur_pageid+1 else: e.pageid = cur_pageid e.tags = [] tag_names = self.request.get('tags').split() for tag_name in tag_names: tag = Tag.all().filter('name',tag_name) if(tag.count(1)>0): t = tag.get() if type == 'link': t.count_link +=1 if type == 'note': t.count_note +=1 if type == 'pic': t.count_pic +=1 t.usetime = datetime.datetime.now() t.put() else: t = Tag() t.name = tag_name if type == 'link': t.count_link =1 if type == 'note': t.count_note =1 if type == 'pic': t.count_pic =1 t.usetime = datetime.datetime.now() t.put() e.tags.append(db.Category(tag_name)) e.put() self.redirect('/'+type+'/') else: self.redirect(users.create_login_url(self.request.uri))
def post(self): #********************** User Auth **************************# user = users.get_current_user() nickname = '' if user: nickname = user.nickname() if nickname: key = self.request.get('key') if key: e = db.get(key) if e.user != nickname: e = Entry() e.user = nickname else: e = Entry() e.user = nickname type = self.request.get('type') if not type: type = 'link' tz = self.request.get('tz') if tz[0:1] == '-': tz = int(tz[1:]) tz = -tz else: tz = int(tz[1:]) tz = +tz title = self.request.get('title') e.title = title.replace('&', '&').replace('<', '<').replace( '>', '>') url = self.request.get('url') purl = self.request.get('purl') if type == 'pic' and not key: e.url = purl.replace('&', '&').replace('<', '<').replace( '>', '>') else: e.url = url.replace('&', '&').replace('<', '<').replace( '>', '>') content = self.request.get('content') e.content = content if not key: e.addtime += datetime.timedelta(hours=tz) e.private = bool(int(self.request.get('private'))) e.type = type if type == 'pic' and not key: if url: try: result = urlfetch.fetch(url) if result.status_code == 200: e.image = db.Blob(result.content) except: self.response.out.write( 'Fetch picture fail! You can <a href="/add?type=pic">upload</a> it manually' ) return else: myfile = self.request.get("myfile") if not myfile: self.response.out.write('No file specified!') return try: e.image = db.Blob(myfile) except: self.response.out.write('Uploading fail!') return if key: #更新数据 for oldtag in e.tags: tag = Tag.all().filter("user", nickname).filter('name', oldtag) if (tag.count(1) > 0): t = tag.get() if type == 'link': t.count_link -= 1 if type == 'note': t.count_note -= 1 if type == 'pic': t.count_pic -= 1 t.put() else: #新增数据 max_pageCount = 900 #超过此数据,则pageid递增 entry = Entry.all().order('-addtime') if entry.count() > 0: cur_pageid = entry.get().pageid else: cur_pageid = 0 cur_pageCount = entry.filter('pageid =', cur_pageid).count(1000) if cur_pageCount >= max_pageCount: e.pageid = cur_pageid + 1 else: e.pageid = cur_pageid e.tags = [] tag_names = self.request.get('tags').split() for tag_name in tag_names: tag = Tag.all().filter("user", nickname).filter('name', tag_name) if (tag.count(1) > 0): t = tag.get() if type == 'link': t.count_link += 1 if type == 'note': t.count_note += 1 if type == 'pic': t.count_pic += 1 t.user = nickname t.usetime = datetime.datetime.now() t.put() else: t = Tag() t.name = tag_name if type == 'link': t.count_link = 1 if type == 'note': t.count_note = 1 if type == 'pic': t.count_pic = 1 t.user = nickname t.usetime = datetime.datetime.now() t.put() e.tags.append(db.Category(tag_name)) e.put() self.redirect('/' + type + '/' + nickname) else: self.redirect(users.create_login_url(self.request.uri))