def get(self): search_item = self.request.get("search_item") print(search_item) streams = Stream.query().fetch() nameList = list() cover_list = [] stream_list = [] for stream in streams: nameList.append(stream.name) index = list() for i in xrange(len(nameList)): index.append(LCS(nameList[i], search_item)) tmp = zip(index, nameList) tmp.sort(reverse=True) #we only show five most relation streams for i in xrange(len(tmp)): stream = Stream.query(Stream.name == tmp[i][1]).fetch()[0] stream_list.append(stream.name) #self.response.write(stream.numberofpictures) #if stream.numberofpictures > 0: # pictures=db.GqlQuery("SELECT * FROM Picture " +"WHERE ANCESTOR IS :1 "+"ORDER BY uploaddate DESC",db.Key.from_path('Stream',stream.name)) cover_list.append(stream.coverurl) dictPassed = {'streamList': stream_list, 'displayCovers': cover_list} jsonObj = json.dumps(dictPassed, sort_keys=True, indent=4, separators=(',', ': ')) print('write json') self.response.write(jsonObj)
def get(self): search_item = self.request.get("search_item") print(search_item) streams = Stream.query().fetch() nameList = list() cover_list = [] stream_list = [] for stream in streams: nameList.append(stream.name) index = list() for i in xrange(len(nameList)): index.append(LCS(nameList[i], search_item)) tmp = zip(index, nameList) tmp.sort(reverse=True) # we only show five most relation streams for i in xrange(len(tmp)): stream = Stream.query(Stream.name == tmp[i][1]).fetch()[0] stream_list.append(stream.name) # self.response.write(stream.numberofpictures) # if stream.numberofpictures > 0: # pictures=db.GqlQuery("SELECT * FROM Picture " +"WHERE ANCESTOR IS :1 "+"ORDER BY uploaddate DESC",db.Key.from_path('Stream',stream.name)) cover_list.append(stream.coverurl) dictPassed = {"streamList": stream_list, "displayCovers": cover_list} jsonObj = json.dumps(dictPassed, sort_keys=True, indent=4, separators=(",", ": ")) print("write json") self.response.write(jsonObj)
def get(self): url = self.request.url stream_name = re.findall('searchStream=(\S+)',url) if len(stream_name) == 0: self.response.write(url) else: stream_name = re.findall('searchStream=(\S+)',url)[0] streams = Stream.query().fetch() nameList = list() for stream in streams: nameList.append(stream.name) index = list() for i in xrange(len(nameList)): index.append(LCS(nameList[i], stream_name)) tmp = zip(index, nameList) tmp.sort(reverse = True) #we only show five most relation streams if len(tmp) < 5: showNum = len(tmp) else: showNum = 5 self.response.write(SEARCH_PAGE_TEMPLATE) self.response.write('<p>%d results for <b>%s</b>,<br> click on image to view stream</p>' % (showNum,stream_name)) for i in xrange(showNum): stream = Stream.query(Stream.name==tmp[i][1]).fetch()[0] #self.response.write(stream.numberofpictures) if stream.numberofpictures > 0: pictures=db.GqlQuery("SELECT * FROM Picture " +"WHERE ANCESTOR IS :1 "+"ORDER BY uploaddate DESC",db.Key.from_path('Stream',stream.name)) self.response.write('<table border="1" style="width:100%"><table style = "width:10%">') self.response.out.write('<td><div style = "position:relative;"><a href = "%s"><img src="img?img_id=%s" ></img><div style = "position: absolute; left:150px; top:20px"></a>%s</div></div></td>' % (stream.url, pictures[0].key(),stream.name)) self.response.write('</table>') else: self.response.out.write('<td><div style = "position:relative;"><a href = "%s"><img src="http://www.estatesale.com/img/no_image.gif" ></img><div style = "position: absolute; left:150px; top:20px"></a>%s</div></div></td>' % (stream.url, stream.name))
def get(self): stream_name = self.request.get("stream_name") email = self.request.get("email") caption = [] displayImages = [] #print stream_name pictures = db.GqlQuery("SELECT * FROM Picture " +"WHERE ANCESTOR IS :1 "+"ORDER BY uploaddate DESC",db.Key.from_path('Stream',stream_name)) stream = Stream.query(Stream.name==stream_name).fetch()[0] if stream.author_name.lower()!= email.split("@",1)[0]: count=CountViews.query(CountViews.name==stream.name,ancestor=ndb.Key('User',stream.author_name)).fetch()[0] count.numbers=count.numbers+1 count.totalviews=count.totalviews+1 count.put() for pic in pictures: url = images.get_serving_url(pic.imgkey) url = url + "=s500" displayImages.append(url) caption.append(pic.caption) #print url dictPassed = {'displayImages':displayImages,'caption':caption,'author':str(stream.author)} #dictPassed = {'displayImages':displayImages,'caption':caption} jsonObj = json.dumps(dictPassed, sort_keys=True,indent=4, separators=(',', ': ')) self.response.write(jsonObj)
def get(self): status = (0, 0) stream_name = re.findall("%3D(.*)", self.request.url)[0] # Change!# stream=Stream.query(Stream.name==stream_name, Stream.author==users.get_current_user()).fetch()[0] stream = Stream.query(Stream.name == stream_name).fetch()[0] if stream.author == users.get_current_user(): status = (1, 1) elif users.get_current_user(): status = (1, 0) else: self.redirect(users.create_login_url(self.request.url)) pictures = db.GqlQuery( "SELECT *FROM Picture " + "WHERE ANCESTOR IS :1 " + "ORDER BY uploaddate DESC LIMIT 3", db.Key.from_path("Stream", stream_name), ) uploadurl = blobstore.create_upload_url("/upload") showmoreurl = urllib.urlencode({"showmore": stream.name + "==" + users.get_current_user().nickname()}) geoviewurl = urllib.urlencode({"geoview": stream.name + "==" + users.get_current_user().nickname()}) template_values = { "user_name": users.get_current_user().nickname(), "showmoreurl": showmoreurl, "stream_name": stream_name, "pictures": pictures, "status": status, "uploadurl": uploadurl, "geoviewurl": geoviewurl, } template = JINJA_ENVIRONMENT.get_template("viewsinglestream_index.html") self.response.write(template.render(template_values))
def get(self): status = (0,0) stream_name=re.findall('%3D(.*)',self.request.url)[0] #Change!# stream=Stream.query(Stream.name==stream_name, Stream.author==users.get_current_user()).fetch()[0] stream=Stream.query(Stream.name==stream_name).fetch()[0] if(stream.author==users.get_current_user()): status = (1,1) elif(users.get_current_user()): status = (1,0) else: self.redirect(users.create_login_url(self.request.url)) pictures=db.GqlQuery("SELECT *FROM Picture " + "WHERE ANCESTOR IS :1 " +"ORDER BY uploaddate DESC LIMIT 3" , db.Key.from_path('Stream',stream_name)) uploadurl = blobstore.create_upload_url('/upload') showmoreurl=urllib.urlencode({'showmore': stream.name+"=="+users.get_current_user().nickname()}) geoviewurl=urllib.urlencode({'geoview': stream.name+"=="+users.get_current_user().nickname()}) template_values = { 'user_name':users.get_current_user().nickname(), 'showmoreurl': showmoreurl, 'stream_name': stream_name, 'pictures':pictures, 'status':status, 'uploadurl':uploadurl, 'geoviewurl': geoviewurl } template = JINJA_ENVIRONMENT.get_template('viewsinglestream_index.html') self.response.write(template.render(template_values))
def post(self): original_url0 = self.request.headers['Referer'] original_url = original_url0 if "%3D" not in original_url: original_url += '%3D%3D' original_url += users.get_current_user().nickname() stream_name=re.findall('=(.*)%3D%3D',original_url) if(len(stream_name)<1): stream_name=re.findall('%3D(.*)%3D%3D',original_url)[0] else: stream_name=stream_name[0] user_name=re.findall('%3D%3D(.*)\?',original_url) if(len(user_name)<1): user_name=re.findall('%3D%3D(.*)',original_url)[0] else: user_name=user_name[0] user_name=user_name.split('%40') if(len(user_name)>1): user_name=user_name[0]+'@'+user_name[1] else: user_name=user_name[0] #Change!# stream=Stream.query(Stream.name==stream_name, Stream.author_name==user_name).fetch()[0] stream=Stream.query(Stream.name==stream_name).fetch()[0] if users.get_current_user(): #stream.subscribers.append(users.get_current_user().nickname()) stream.subscribers.append(users.get_current_user().email()) stream.put() self.redirect(original_url0)
def get(self): streams = Stream.query().fetch() ndb.delete_multi(stream_name_set.query().fetch(keys_only=True)) for stream in streams: name_set = stream_name_set() name_set.name = stream.name name_set.put()
def get(self): #self.response.write(users.get_current_user()) stream_name = re.findall('%3D(.*)%3D%3D', self.request.url)[0] user_name = re.findall('%3D%3D(.*)', self.request.url)[0] infos = [] status = (0, 0) index = 0 url = "" #Change!# stream=Stream.query(Stream.name==stream_name, Stream.author_name==user_name).fetch()[0] pictures = db.GqlQuery( "SELECT * FROM Picture " + "WHERE ANCESTOR IS :1 " + "ORDER BY uploaddate DESC", db.Key.from_path('Stream', stream_name)) stream = Stream.query(Stream.name == stream_name).fetch()[0] if (users.get_current_user() and stream.author == users.get_current_user()): status = (1, 1) for picture in pictures: lat = random.random() lng = random.random() infos.append((picture.key(), picture.imgkey, picture.uploaddate, lat, lng, index)) index = index + 1 if (index == 4): index = 0 url = urllib.urlencode({'streamname': stream.name}) else: if (users.get_current_user()): count = CountViews.query(CountViews.name == stream.name, ancestor=ndb.Key( 'User', stream.author_name)).fetch()[0] count.numbers = count.numbers + 1 count.totalviews = count.totalviews + 1 count.put() status = (1, 0) url = urllib.urlencode({'streamname': stream.name}) for picture in pictures: lat = random.random() lng = random.random() infos.append((picture.key(), picture.imgkey, picture.uploaddate, lat, lng, index)) index = index + 1 if (index == 4): index = 0 else: self.redirect(users.create_login_url(self.request.url)) template_values = { "stream_name": stream_name, "infos": infos, "url": url, "status": status } template = JINJA_ENVIRONMENT.get_template("geoview_index.html") self.response.write(template.render(template_values))
def get(self, photoIndexes, currentLocation): passedInCoord = currentLocation.split('_') lat = float(passedInCoord[0]) lon = float(passedInCoord[1]) displayImageObjs = [] # displayPhotoList = [] stream_query = Stream.query() for stream in stream_query: photos = db.GqlQuery("SELECT * FROM Picture " + "WHERE ANCESTOR IS :1 " +"ORDER BY uploaddate DESC" , db.Key.from_path('Stream', stream.name)) for photo in photos: photoUrl = images.get_serving_url(photo.imgkey) photoUrl = str(photoUrl) + "=s500" photoDict = {} photoDict["photoServingURL"] = photoUrl photoDict["date"] = str(photo.uploaddate) photoDict["loc"] = str(photo.loc) photoDict["streamName"] = str(stream.name) # photoDict["streamID"] = str(stream.key.id()) photoCoord = str(photo.loc).split(',') plat = float(photoCoord[0]) plon = float(photoCoord[1]) R = 6373.0 lat1 = radians(lat) lon1 = radians(lon) lat2 = radians(plat) lon2 = radians(plon) dlon = lon2 - lon1 dlat = lat2 - lat1 a = (sin(dlat / 2)) ** 2 + cos(lat1) * cos(lat2) * (sin(dlon / 2)) ** 2 c = 2 * atan2(sqrt(a), sqrt(1-a)) distance = R * c photoDict["actualDistance"] = distance if distance > 10: photoDict["strDistance"] = str(distance).split('.', 1)[0] + 'km' else: photoDict["strDistance"] = str(distance * 1000).split('.', 1)[0] + 'm' displayImageObjs.append(photoDict) displayImageObjs = sorted(displayImageObjs, key = lambda k: k['actualDistance']) passedPhotos = [] morePhotos = "False" indexURL = photoIndexes indexList = str(photoIndexes).split('_') if len(displayImageObjs) - 1 > int(indexList[1]): for i in range(int(indexList[0]), int(indexList[1]) + 1): passedPhotos.append(displayImageObjs[i]) indexURL = str(int(indexList[0]) + 16) + '_' + str(int(indexList[1]) + 16) morePhotos = "True" else: for i in range(int(indexList[0]), len(displayImageObjs)): passedPhotos.append(displayImageObjs[i]) dictPassed = {'user': None, 'morePhotos': morePhotos, 'indexURL': indexURL,'displayImageObjs': passedPhotos}#'displayPhotoList' : displayStreamList jsonObj = json.dumps(dictPassed, sort_keys=True, indent=4, separators=(',', ': ')) self.response.write(jsonObj)
def post(self): stream_name = self.request.get("streamname") if len(stream_name) == 0: stream_name = "untitledstream" stream_tags = self.request.get("streamtags").split(',') stream_subscribers = self.request.get("subscribers").split(';') stream_url = self.request.get("url") emailContext = self.request.get("context") emailSubject = "Stream Update Info with UserID: " + users.get_current_user( ).nickname() emailSender = users.get_current_user().email() #Change! # streams=Stream.query(Stream.name==stream_name, Stream.author==users.get_current_user()).fetch() streams = Stream.query(Stream.name == stream_name).fetch() if (len(streams) < 1): stream = Stream() count = CountViews( parent=ndb.Key('User', users.get_current_user().nickname())) pic_num = Count_pic(parent=ndb.Key('Stream', stream_name)) pic_num.numbers = 0 pic_num.put() stream.name = stream_name count.name = stream_name count.numbers = 0 count.totalviews = 0 count.put() stream.numberofpictures = 0 stream.total = 0 stream.author = users.get_current_user() stream.author_name = users.get_current_user().nickname() stream.url = urllib.urlencode({'streamname': stream.name}) stream.guesturl = urllib.urlencode({ 'showmore': stream.name + "==" + users.get_current_user().nickname() }) default_context = "Notice: " + users.get_current_user().nickname( ) + " add a new stream named '" + stream_name + "' and the link to the stream is: " + "http://mini1-test1.appspot.com/" + stream.guesturl + "\n\n" if len(stream_tags) > 0: stream.tag = stream_tags if len(stream_subscribers[0]) > 0: stream.subscribers = stream_subscribers for emailReceiver in stream.subscribers: mail.send_mail(sender=emailSender, to=emailReceiver, subject=emailSubject, body=default_context + emailContext) if len(stream_url) > 0: stream.coverurl = stream_url else: stream.coverurl = "https://pbs.twimg.com/profile_images/3207366683/25547cceacb728c382e49cd34d9e800a.png" stream.put() self.redirect('/management', permanent=False) else: self.redirect('/error', permanent=False)
def post(self): original_url0 = self.request.headers['Referer'] original_url = original_url0 if "%3D" not in original_url: original_url += '%3D%3D' original_url += users.get_current_user().nickname() stream_name = re.findall('=(.*)%3D%3D', original_url) if (len(stream_name) < 1): stream_name = re.findall('%3D(.*)%3D%3D', original_url)[0] else: stream_name = stream_name[0] user_name = re.findall('%3D%3D(.*)\?', original_url) if (len(user_name) < 1): user_name = re.findall('%3D%3D(.*)', original_url)[0] else: user_name = user_name[0] user_name = user_name.split('%40') if (len(user_name) > 1): user_name = user_name[0] + '@' + user_name[1] else: user_name = user_name[0] #Change!# stream=Stream.query(Stream.name==stream_name, Stream.author_name==user_name).fetch()[0] stream = Stream.query(Stream.name == stream_name).fetch()[0] if users.get_current_user(): #stream.subscribers.append(users.get_current_user().nickname()) stream.subscribers.append(users.get_current_user().email()) stream.put() self.redirect(original_url0)
def post(self): original_url0 = self.request.headers["Referer"] original_url = original_url0 if "%3D" not in original_url: original_url += "%3D%3D" original_url += users.get_current_user().nickname() stream_name = re.findall("=(.*)%3D%3D", original_url) if len(stream_name) < 1: stream_name = re.findall("%3D(.*)%3D%3D", original_url)[0] else: stream_name = stream_name[0] user_name = re.findall("%3D%3D(.*)\?", original_url) if len(user_name) < 1: user_name = re.findall("%3D%3D(.*)", original_url)[0] else: user_name = user_name[0] user_name = user_name.split("%40") if len(user_name) > 1: user_name = user_name[0] + "@" + user_name[1] else: user_name = user_name[0] # Change!# stream=Stream.query(Stream.name==stream_name, Stream.author_name==user_name).fetch()[0] stream = Stream.query(Stream.name == stream_name).fetch()[0] if users.get_current_user(): # stream.subscribers.append(users.get_current_user().nickname()) # users.get_current_user().email() = users.get_current_user().email().lower() stream.subscribers.append(users.get_current_user().email().lower()) stream.put() self.redirect(original_url0)
def get(self): url = self.request.url stream_name = re.findall('searchStream=(\S+)', url) if len(stream_name) == 0: self.response.write(url) else: stream_name = re.findall('searchStream=(\S+)', url)[0] streams = Stream.query().fetch() nameList = list() key_list = [] stream_list = [] for stream in streams: nameList.append(stream.name) index = list() for i in xrange(len(nameList)): index.append(LCS(nameList[i], stream_name)) tmp = zip(index, nameList) tmp.sort(reverse=True) #we only show five most relation streams if len(tmp) < 5: showNum = len(tmp) else: showNum = 5 for i in xrange(showNum): stream = Stream.query(Stream.name == tmp[i][1]).fetch()[0] stream_list.append(stream) #self.response.write(stream.numberofpictures) if stream.numberofpictures > 0: pictures = db.GqlQuery( "SELECT * FROM Picture " + "WHERE ANCESTOR IS :1 " + "ORDER BY uploaddate DESC", db.Key.from_path('Stream', stream.name)) key_list.append(pictures[0].imgkey) else: key_list.append(0) template_values = { 'showNum': showNum, 'stream_name': stream_name, 'key_list': key_list, 'stream_list': stream_list } template = JINJA_ENVIRONMENT.get_template('showsearch_index.html') self.response.write(template.render(template_values))
def get(self): url = self.request.url stream_name = re.findall("searchStream=(\S+)", url) if len(stream_name) == 0: self.response.write(url) else: stream_name = re.findall("searchStream=(\S+)", url)[0] streams = Stream.query().fetch() nameList = list() key_list = [] stream_list = [] for stream in streams: nameList.append(stream.name) index = list() for i in xrange(len(nameList)): index.append(LCS(nameList[i], stream_name)) tmp = zip(index, nameList) tmp.sort(reverse=True) # we only show five most relation streams if len(tmp) < 5: showNum = len(tmp) else: showNum = 5 for i in xrange(showNum): stream = Stream.query(Stream.name == tmp[i][1]).fetch()[0] stream_list.append(stream) # self.response.write(stream.numberofpictures) if stream.numberofpictures > 0: pictures = db.GqlQuery( "SELECT * FROM Picture " + "WHERE ANCESTOR IS :1 " + "ORDER BY uploaddate DESC", db.Key.from_path("Stream", stream.name), ) key_list.append(pictures[0].imgkey) else: key_list.append(0) template_values = { "showNum": showNum, "stream_name": stream_name, "key_list": key_list, "stream_list": stream_list, } template = JINJA_ENVIRONMENT.get_template("showsearch_index.html") self.response.write(template.render(template_values))
def post(self): email = self.request.get("email") final_picture = [] displayImages = [] caption = [] streams = Stream.query().fetch() #print streams #print streams[0] #print type(users.get_current_user().nickname()) #print users.get_current_user() # for stream in streams: # if(users.get_current_user().nickname() in stream.subscribers): # print stream.name for stream in streams: #print "user0: "+user # print type(user) print stream.subscribers #print type(stream.subscribers[0]) if (email in stream.subscribers): # print "user1: "+user pictures = db.GqlQuery( "SELECT *FROM Picture " + "WHERE ANCESTOR IS :1 " + "ORDER BY uploaddate DESC", db.Key.from_path('Stream', stream.name)) for pic in pictures: if len(final_picture) < 16: # print ("user2",pic.uploaddate) # print("user2",pic.imgkey) final_picture.append(pic) continue else: # print "user3: "+user if pic.uploaddate > final_picture[15].uploaddate: final_picture.pop() final_picture.append(pic) final_picture.sort(key=lambda pic: pic.uploaddate, reverse=True) final_picture.sort(key=lambda pic: pic.uploaddate, reverse=True) for f_pic in final_picture: #print f_pic.uploaddate #f = "http://aptmini3.appspot.com/view_photo/"+f_pic.imgkey # f.get_serving_url() caption.append(f_pic.caption) url = images.get_serving_url(f_pic.imgkey) url = url + "=s600" displayImages.append(url) print url # print f_pic.uploaddate dictPassed = {'displayImages': displayImages, 'caption': caption} jsonObj = json.dumps(dictPassed, sort_keys=True, indent=4, separators=(',', ': ')) self.response.write(jsonObj)
def post(self): email = self.request.get("email") final_picture = [] displayImages = [] caption = [] streams = Stream.query().fetch() #print streams #print streams[0] #print type(users.get_current_user().nickname()) #print users.get_current_user() # for stream in streams: # if(users.get_current_user().nickname() in stream.subscribers): # print stream.name for stream in streams: #print "user0: "+user # print type(user) print email print stream.subscribers #print type(stream.subscribers[0]) if(email in stream.subscribers): # print "user1: "+user print "1" pictures=db.GqlQuery("SELECT *FROM Picture " + "WHERE ANCESTOR IS :1 " +"ORDER BY uploaddate DESC" , db.Key.from_path('Stream',stream.name)) for pic in pictures: if len(final_picture) < 16: # print ("user2",pic.uploaddate) # print("user2",pic.imgkey) final_picture.append(pic) continue else: # print "user3: "+user print pic.uploaddate print final_picture[15].uploaddate if pic.uploaddate > final_picture[15].uploaddate: final_picture.pop() final_picture.append(pic) final_picture.sort(key=lambda pic:pic.uploaddate, reverse=True) print final_picture final_picture.sort(key=lambda pic:pic.uploaddate, reverse=True) for f_pic in final_picture: #print f_pic.uploaddate #f = "http://aptmini3.appspot.com/view_photo/"+f_pic.imgkey # f.get_serving_url() caption.append(f_pic.caption) url = images.get_serving_url(f_pic.imgkey) url = url + "=s400" displayImages.append(url) print url # print f_pic.uploaddate dictPassed = {'displayImages':displayImages,'caption':caption} jsonObj = json.dumps(dictPassed, sort_keys=True,indent=4, separators=(',', ': ')) self.response.write(jsonObj)
def post(self): original_url=self.request.headers['Referer'] stream_name=re.findall('=(.*)%3D%3D',original_url)[0] stream=Stream.query(Stream.name==stream_name, Stream.author==users.get_current_user()).fetch()[0] dellsts=self.request.get_all("status") pictures=db.GqlQuery("SELECT * FROM Picture " +"WHERE ANCESTOR IS :1 AND id IN :2",db.Key.from_path('Stream',stream_name),dellsts) db.delete(pictures) stream.numberofpictures=stream.numberofpictures-len(dellsts) stream.put() self.redirect(original_url)
def get(self): # self.response.write(users.get_current_user()) stream_name = re.findall("%3D(.*)%3D%3D", self.request.url)[0] user_name = re.findall("%3D%3D(.*)", self.request.url)[0] infos = [] status = (0, 0) index = 0 url = "" # Change!# stream=Stream.query(Stream.name==stream_name, Stream.author_name==user_name).fetch()[0] pictures = db.GqlQuery( "SELECT * FROM Picture " + "WHERE ANCESTOR IS :1 " + "ORDER BY uploaddate DESC", db.Key.from_path("Stream", stream_name), ) stream = Stream.query(Stream.name == stream_name).fetch()[0] if users.get_current_user() and stream.author == users.get_current_user(): status = (1, 1) for picture in pictures: print ("index") print index infos.append((picture.key(), picture.imgkey, index)) index = index + 1 if index == 4: index = 0 url = urllib.urlencode({"streamname": stream.name}) else: if users.get_current_user(): count = CountViews.query( CountViews.name == stream.name, ancestor=ndb.Key("User", stream.author_name) ).fetch()[0] count.numbers = count.numbers + 1 count.totalviews = count.totalviews + 1 count.put() status = (1, 0) url = urllib.urlencode({"streamname": stream.name}) for picture in pictures: infos.append((picture.key(), picture.imgkey, index)) index = index + 1 if index == 4: index = 0 else: self.redirect(users.create_login_url(self.request.url)) template_values = { "stream_name": stream_name, "infos": infos, "url": url, "status": status, "user_name": users.get_current_user().nickname(), } template = JINJA_ENVIRONMENT.get_template("showmore_index.html") self.response.write(template.render(template_values))
def get(self): all_streams=Stream.query().order(-Stream.creattime).fetch() cover_url_list = [] stream_list = [] for stream in all_streams: stream_list.append(stream.name) cover_url_list.append(stream.coverurl) dictPassed = {'displayCovers':cover_url_list, 'streamList':stream_list} jsonObj = json.dumps(dictPassed, sort_keys=True,indent=4, separators=(',', ': ')) self.response.write(jsonObj)
def get(self): original_url = self.request.headers["Referer"] dellsts = self.request.get_all("status") if len(dellsts) > 0: streams = Stream.query(Stream.name.IN(dellsts), Stream.author == users.get_current_user()).fetch() for stream in streams: pictures = db.GqlQuery( "SELECT * FROM Picture " + "WHERE ANCESTOR IS :1", db.Key.from_path("Stream", stream.name) ) db.delete(pictures) ndb.delete_multi(ndb.put_multi(streams)) self.redirect(original_url)
def get(self): self.response.write(VIEW_SINGLE_STREAM_TEMPLATE) stream_name=re.findall('%3D(.*)',self.request.url)[0] self.response.write('<h2 >%s</h2>' %stream_name) #Change!# stream=Stream.query(Stream.name==stream_name, Stream.author==users.get_current_user()).fetch()[0] stream=Stream.query(Stream.name==stream_name).fetch()[0] pictures=db.GqlQuery("SELECT *FROM Picture " + "WHERE ANCESTOR IS :1 " +"ORDER BY uploaddate DESC LIMIT 3" , db.Key.from_path('Stream',stream_name)) self.response.write('<table border="1" style="width:100%"><tr>') for picture in pictures: self.response.out.write('<td><img src="img?img_id=%s"></img></td>' %picture.key()) self.response.write('</tr></table>') # url=urllib.urlencode({'showmore': stream.name+"=="+users.get_current_user().nickname()}) # self.response.write('<form action="%s" ,method="post"><input type="submit" value="More Pictures"></form>' %url) #Change! Added if-else# # if stream.author==users.get_current_user(): if users.get_current_user() and stream.author==users.get_current_user(): url=urllib.urlencode({'showmore': stream.name+"=="+users.get_current_user().nickname()}) self.response.write('<form action="%s" ,method="post"><input type="submit" value="More Pictures"></form>' %url) upload_url = blobstore.create_upload_url('/upload') self.response.out.write('<form action="/upload" method="post" enctype="multipart/form-data">') self.response.out.write("""Upload File: <input type="file" name="file" ><br> <input type="submit" name="submit" value="Submit"> </form>""") else: #Change! Added# stream = Stream.query(Stream.name==stream_name).fetch()[0] count=CountViews.query(CountViews.name==stream.name,ancestor=ndb.Key('User',stream.author_name)).fetch()[0] count.numbers=count.numbers+1 count.totalviews=count.totalviews+1 count.put() url=urllib.urlencode({'showmore': stream.name+"=="+users.get_current_user().nickname()}) self.response.write('<form action="%s" ,method="post"><input type="submit" value="More Pictures"></form>' %url) self.response.write('<form action="subscribe" method="post"><input type="submit" value="Subscribe"></form>')
def post(self): stream_name=self.request.get("streamname") if len(stream_name)==0: stream_name="untitledstream" stream_tags=self.request.get("streamtags").split(',') stream_subscribers=self.request.get("subscribers").split(';') stream_url=self.request.get("url") emailContext = self.request.get("context") emailSubject = "Stream Update Info with UserID: " + users.get_current_user().nickname() emailSender = users.get_current_user().email() #Change! # streams=Stream.query(Stream.name==stream_name, Stream.author==users.get_current_user()).fetch() streams=Stream.query(Stream.name==stream_name).fetch() if (len(streams)<1): stream=Stream() count=CountViews(parent=ndb.Key('User',users.get_current_user().nickname())) pic_num = Count_pic(parent = ndb.Key('Stream',stream_name)) pic_num.numbers = 0 pic_num.put() stream.name=stream_name count.name=stream_name count.numbers=0 count.totalviews = 0 count.put() stream.numberofpictures=0 stream.total=0 stream.author=users.get_current_user() stream.author_name=users.get_current_user().nickname() stream.url=urllib.urlencode({'streamname': stream.name}) stream.guesturl=urllib.urlencode({'showmore': stream.name+"=="+users.get_current_user().nickname()}) default_context = "Notice: " + users.get_current_user().nickname() + " add a new stream named '" + stream_name +"' and the link to the stream is: "+"http://mini1-test1.appspot.com/"+stream.guesturl+"\n\n" if len(stream_tags) > 0: stream.tag=stream_tags if len(stream_subscribers[0])>0: stream.subscribers=stream_subscribers for emailReceiver in stream.subscribers: mail.send_mail(sender = emailSender, to = emailReceiver, subject = emailSubject, body = default_context + emailContext) if len(stream_url) > 0: stream.coverurl = stream_url else: stream.coverurl = "https://pbs.twimg.com/profile_images/3207366683/25547cceacb728c382e49cd34d9e800a.png" stream.put() self.redirect('/management',permanent=False) else: self.redirect('/error', permanent = False)
def get(self): #self.response.write(users.get_current_user()) stream_name=re.findall('%3D(.*)%3D%3D',self.request.url)[0] user_name=re.findall('%3D%3D(.*)',self.request.url)[0] infos = [] status = (0,0) index=0 url = "" #Change!# stream=Stream.query(Stream.name==stream_name, Stream.author_name==user_name).fetch()[0] pictures=db.GqlQuery("SELECT * FROM Picture " +"WHERE ANCESTOR IS :1 "+"ORDER BY uploaddate DESC",db.Key.from_path('Stream',stream_name)) stream = Stream.query(Stream.name==stream_name).fetch()[0] if(users.get_current_user() and stream.author==users.get_current_user()): status = (1,1) for picture in pictures: lat = random.random() lng = random.random() infos.append((picture.key(),picture.imgkey,picture.uploaddate, lat, lng, index)) index=index+1 if(index==4): index = 0 url=urllib.urlencode({'streamname': stream.name}) else: if(users.get_current_user()): count=CountViews.query(CountViews.name==stream.name,ancestor=ndb.Key('User',stream.author_name)).fetch()[0] count.numbers=count.numbers+1 count.totalviews=count.totalviews+1 count.put() status = (1,0) url=urllib.urlencode({'streamname': stream.name}) for picture in pictures: lat = random.random() lng = random.random() infos.append((picture.key(),picture.imgkey,picture.uploaddate, lat, lng,index)) index=index+1 if(index==4): index = 0 else: self.redirect(users.create_login_url(self.request.url)) template_values={"stream_name": stream_name,"infos":infos,"url":url,"status":status} template=JINJA_ENVIRONMENT.get_template("geoview_index.html") self.response.write(template.render(template_values))
def get(self): original_url = self.request.headers['Referer'] dellsts = self.request.get_all("status") if (len(dellsts) > 0): streams = Stream.query( Stream.name.IN(dellsts), Stream.author == users.get_current_user()).fetch() for stream in streams: pictures = db.GqlQuery( "SELECT * FROM Picture " + "WHERE ANCESTOR IS :1", db.Key.from_path('Stream', stream.name)) db.delete(pictures) ndb.delete_multi(ndb.put_multi(streams)) self.redirect(original_url)
def get(self): all_streams = Stream.query().order(-Stream.creattime).fetch() cover_url_list = [] stream_list = [] for stream in all_streams: stream_list.append(stream.name) cover_url_list.append(stream.coverurl) dictPassed = { 'displayCovers': cover_url_list, 'streamList': stream_list } jsonObj = json.dumps(dictPassed, sort_keys=True, indent=4, separators=(',', ': ')) self.response.write(jsonObj)
def get(self): #Change!# streams=Stream.query(Stream.author==users.get_current_user()).order(-Stream.creattime).fetch() all_streams = Stream.query().order(-Stream.creattime).fetch() user_name = "" if users.get_current_user(): user_name = users.get_current_user().nickname() print "yes!" print users.get_current_user().email() template_values = { 'user_name': user_name, 'all_streams': all_streams, } template = JINJA_ENVIRONMENT.get_template('view_index.html') self.response.write(template.render(template_values))
def get(self): #Change!# streams=Stream.query(Stream.author==users.get_current_user()).order(-Stream.creattime).fetch() all_streams=Stream.query().order(-Stream.creattime).fetch() user_name = "" if users.get_current_user(): user_name = users.get_current_user().nickname() print "yes!" print users.get_current_user().email() template_values = { 'user_name': user_name, 'all_streams': all_streams, } template = JINJA_ENVIRONMENT.get_template('view_index.html') self.response.write(template.render(template_values))
def get(self): #self.response.write(users.get_current_user()) stream_name=re.findall('%3D(.*)%3D%3D',self.request.url)[0] user_name=re.findall('%3D%3D(.*)',self.request.url)[0] self.response.write('<h2 >%s</h2>' %stream_name) index=0 #Change!# stream=Stream.query(Stream.name==stream_name, Stream.author_name==user_name).fetch()[0] pictures=db.GqlQuery("SELECT * FROM Picture " +"WHERE ANCESTOR IS :1 "+"ORDER BY uploaddate DESC",db.Key.from_path('Stream',stream_name)) stream = Stream.query(Stream.name==stream_name).fetch()[0] if(users.get_current_user() and stream.author==users.get_current_user()): self.response.write('<form action="delpic" method="post"><table border="1" style="width:100%">') for picture in pictures: if(index==0): self.response.write("<tr>") self.response.out.write('<td><img src="img?img_id=%s"></img><input type="checkbox" name="status", value="%s"></td>' %(picture.key(),picture.id)) if(index==3): self.response.write("</tr>") index=index+1 self.response.write('</table>') self.response.write('<input type="submit" value="Delete Selected"></form>') url=urllib.urlencode({'streamname': stream.name}) self.response.write('<a href="%s">Go Back</a>'% url) else: self.response.write('<table border="1" style="width:100%">') for picture in pictures: if(index==0): self.response.write("<tr>") self.response.out.write('<td><img src="img?img_id=%s"></img></td>' %picture.key()) if(index==3): self.response.write("</tr>") index=index+1 self.response.write('</table>') if(users.get_current_user()): self.response.write('<form action="subscribe" method="post"><input type="submit" value="Subscribe"></form>') url=urllib.urlencode({'streamname': stream.name}) self.response.write('<a href="%s">Go Back</a>'% url) else: self.redirect(users.create_login_url(self.request.url))
def post(self): original_url=self.request.headers['Referer'] stream_name=re.findall('=(.*)%3D%3D',original_url)[0] stream=Stream.query(Stream.name==stream_name, Stream.author==users.get_current_user()).fetch()[0] dellsts=self.request.get_all("status") print dellsts pictures=db.GqlQuery("SELECT * FROM Picture " +"WHERE ANCESTOR IS :1 AND imgkey IN :2",db.Key.from_path('Stream',stream_name),dellsts) for picture in pictures: blobstore.delete(picture.imgkey) images.delete_serving_url(picture.imgkey) db.delete(pictures) pic_count= Count_pic.query(ancestor=ndb.Key('Stream',stream_name)).fetch()[0] # print(pic_counts) # for pic_count in pic_counts: pic_count.numbers=pic_count.numbers - len(dellsts) pic_count.put() stream.numberofpictures=pic_count.numbers stream.put() self.redirect(original_url)
def get(self): gl=Global.query(Global.name=="global").fetch() stream_list = [] count_list = [] if len(gl)>0: gl=gl[0] #streams=Stream.query(Stream.author==users.get_current_user()).order(-Stream.views).fetch(3) counts=CountViews.query().order(-CountViews.numbers).fetch(3) for count in counts: stream=Stream.query(Stream.name==count.name).fetch() if (len(stream)>0): stream = stream[0] stream_list.append(stream) count_list.append(count.numbers) gl=Global.query(Global.name=="global").fetch() str = "" if(len(gl)>0): gl=gl[0] fre=gl.limit if fre==0: str="No reports" if fre==1: str="Every 5 Minutes" if fre==12: str="Every 1 hour" if fre==288: str="Every day" user_name = users.get_current_user().nickname() print count_list print stream_list template_values = { 'user_name':user_name, 'str':str, 'count_list':count_list, 'stream_list': stream_list } template = JINJA_ENVIRONMENT.get_template('trending_index.html') self.response.write(template.render(template_values))
def post(self): print('1') original_url = self.request.headers['Referer'] img = self.get_uploads()[0] stream_name = re.findall('=(.*)', original_url)[0] if Stream.author == users.get_current_user(): stream = Stream.query( Stream.name == stream_name, Stream.author == users.get_current_user()).fetch()[0] #for img in imgs: print('3') picture = Picture(parent=db.Key.from_path('Stream', stream_name), imgkey=str(img.key())) stream.lastnewdate = picture.uploaddate pic_count = Count_pic.query( ancestor=ndb.Key('Stream', stream_name)).fetch()[0] print pic_count # print(pic_counts) # for pic_count in pic_counts: pic_count.numbers = pic_count.numbers + 1 pic_count.put() if stream.tag != None: picture.caption = stream.tag[0] #stream.numberofpictures=pic_count.numbers #stream.total=stream.total+1 #picture.id=str(stream.total) #img=img.resize((300,300)) # picture.imgkey=str(img.key()) # print picture.imgkey picture.put() stream.put() # print('!!') #print (stream.numberofpictures) # print (stream.total) #time.sleep(5.0) else: self.response.out.write('<h2 >Action not allowed!</h2>') print('5') self.redirect(original_url)
def post(self): original_url=self.request.headers['Referer'] img=self.request.get('file') if len(img) != 0: stream_name=re.findall('=(.*)',original_url)[0] if Stream.author==users.get_current_user(): stream=Stream.query(Stream.name==stream_name, Stream.author==users.get_current_user()).fetch()[0] picture=Picture(parent=db.Key.from_path('Stream',stream_name)) stream.lastnewdate= picture.uploaddate stream.numberofpictures=stream.numberofpictures+1 stream.total=stream.total+1 picture.id=str(stream.total) img=images.resize(img,300,300) picture.image=db.Blob(img) picture.put() stream.put() else: self.response.out.write('<h2 >Action not allowed!</h2>') self.redirect(original_url)
def get(self): status = (0, 0) stream_name = re.findall('%3D(.*)', self.request.url)[0] #Change!# stream=Stream.query(Stream.name==stream_name, Stream.author==users.get_current_user()).fetch()[0] stream = Stream.query(Stream.name == stream_name).fetch()[0] if (stream.author == users.get_current_user()): status = (1, 1) elif (users.get_current_user()): status = (1, 0) else: self.redirect(users.create_login_url(self.request.url)) pictures = db.GqlQuery( "SELECT *FROM Picture " + "WHERE ANCESTOR IS :1 " + "ORDER BY uploaddate DESC LIMIT 3", db.Key.from_path('Stream', stream_name)) uploadurl = blobstore.create_upload_url('/upload') showmoreurl = urllib.urlencode({ 'showmore': stream.name + "==" + users.get_current_user().nickname() }) geoviewurl = urllib.urlencode({ 'geoview': stream.name + "==" + users.get_current_user().nickname() }) template_values = { 'user_name': users.get_current_user().nickname(), 'showmoreurl': showmoreurl, 'stream_name': stream_name, 'pictures': pictures, 'status': status, 'uploadurl': uploadurl, 'geoviewurl': geoviewurl } template = JINJA_ENVIRONMENT.get_template( 'viewsinglestream_index.html') self.response.write(template.render(template_values))
def post(self): upload = self.get_uploads()[0] stream_name = self.request.params["stream_name"] img_location_lat = float(self.request.params["locationLat"]) img_location_long = float(self.request.params["locationLong"]) print (img_location_long) print (img_location_lat) email = self.request.params["email"] user_photo = Picture( parent=db.Key.from_path("Stream", stream_name), imgkey=str(upload.key()), loc=db.GeoPt(img_location_lat, img_location_long), ) caption = self.request.params["photoCaption"] if caption != None: user_photo.caption = caption print (user_photo.loc) user_photo.put() stream = Stream.query(Stream.name == stream_name).fetch()[0] stream.lastnewdate = user_photo.uploaddate pic_count = Count_pic.query(ancestor=ndb.Key("Stream", stream_name)).fetch()[0] # print(pic_counts) # for pic_count in pic_counts: pic_count.numbers = pic_count.numbers + 1 pic_count.put() # print (stream) # print (pic_count.numbers) # print (stream.numberofpictures) # print (stream.total) # stream.numberofpictures=pic_count.numbers # stream.total=stream.total+1 # picture.id=str(stream.total) # img=img.resize((300,300)) # picture.imgkey=str(img.key()) # print picture.imgkey # picture.put() stream.put()
def post(self): upload = self.get_uploads()[0] stream_name = self.request.params['stream_name'] img_location_lat = float(self.request.params['locationLat']) img_location_long = float(self.request.params['locationLong']) print(img_location_long) print(img_location_lat) email = self.request.params['email'] user_photo = Picture(parent=db.Key.from_path('Stream', stream_name), imgkey=str(upload.key()), loc=db.GeoPt(img_location_lat, img_location_long)) caption = self.request.params['photoCaption'] if caption != None: user_photo.caption = caption print(user_photo.loc) user_photo.put() stream = Stream.query(Stream.name == stream_name).fetch()[0] stream.lastnewdate = user_photo.uploaddate pic_count = Count_pic.query( ancestor=ndb.Key('Stream', stream_name)).fetch()[0] # print(pic_counts) # for pic_count in pic_counts: pic_count.numbers = pic_count.numbers + 1 pic_count.put() #print (stream) #print (pic_count.numbers) #print (stream.numberofpictures) #print (stream.total) #stream.numberofpictures=pic_count.numbers #stream.total=stream.total+1 #picture.id=str(stream.total) #img=img.resize((300,300)) # picture.imgkey=str(img.key()) # print picture.imgkey # picture.put() stream.put()
def post(self): print('1') original_url=self.request.headers['Referer'] img=self.get_uploads()[0] stream_name=re.findall('=(.*)',original_url)[0] if Stream.author==users.get_current_user(): stream=Stream.query(Stream.name==stream_name, Stream.author==users.get_current_user()).fetch()[0] #for img in imgs: print('3') picture=Picture(parent=db.Key.from_path('Stream',stream_name),imgkey=str(img.key())) stream.lastnewdate= picture.uploaddate pic_count= Count_pic.query(ancestor=ndb.Key('Stream',stream_name)).fetch()[0] print pic_count # print(pic_counts) # for pic_count in pic_counts: pic_count.numbers=pic_count.numbers+1 pic_count.put() if stream.tag != None: picture.caption = stream.tag[0] #stream.numberofpictures=pic_count.numbers #stream.total=stream.total+1 #picture.id=str(stream.total) #img=img.resize((300,300)) # picture.imgkey=str(img.key()) # print picture.imgkey picture.put() stream.put() # print('!!') #print (stream.numberofpictures) # print (stream.total) #time.sleep(5.0) else: self.response.out.write('<h2 >Action not allowed!</h2>') print('5') self.redirect(original_url)
def get(self): stream_name = self.request.get("stream_name") email = self.request.get("email") caption = [] displayImages = [] #print stream_name pictures = db.GqlQuery( "SELECT * FROM Picture " + "WHERE ANCESTOR IS :1 " + "ORDER BY uploaddate DESC", db.Key.from_path('Stream', stream_name)) stream = Stream.query(Stream.name == stream_name).fetch()[0] if stream.author_name.lower() != email.split("@", 1)[0]: count = CountViews.query( CountViews.name == stream.name, ancestor=ndb.Key('User', stream.author_name)).fetch()[0] count.numbers = count.numbers + 1 count.totalviews = count.totalviews + 1 count.put() for pic in pictures: url = images.get_serving_url(pic.imgkey) url = url + "=s500" displayImages.append(url) caption.append(pic.caption) #print url dictPassed = { 'displayImages': displayImages, 'caption': caption, 'author': str(stream.author) } #dictPassed = {'displayImages':displayImages,'caption':caption} jsonObj = json.dumps(dictPassed, sort_keys=True, indent=4, separators=(',', ': ')) self.response.write(jsonObj)
def get(self): self.response.write(TRENDING_TEMPLATE) gl=Global.query(Global.name=="global").fetch() if(len(gl)>0): gl=gl[0] #streams=Stream.query(Stream.author==users.get_current_user()).order(-Stream.views).fetch(3) counts=CountViews.query().order(-CountViews.numbers).fetch(3) self.response.write('<table style = "width:70%">') for count in counts: stream=Stream.query(Stream.name==count.name).fetch() if (len(stream)>0): stream = stream[0] self.response.out.write('<td><div style = "position:relative;"><a href="%s"><img src="%s" ></img><div style = "position: absolute; left:0px; top:0px">%s</div></a></div><div>%s views in the past hour</div></td>' % (stream.url,stream.coverurl,stream.name,count.numbers)) self.response.write('</table>') self.response.write('<form action="/update" method="post">') self.response.write('<input type="radio" name="frequency" value="no">No reports<br>') self.response.write('<input type="radio" name="frequency" value="5m">Every 5 minutes<br>') self.response.write('<input type="radio" name="frequency" value="1h">Every 1 hour<br>') self.response.write('<input type="radio" name="frequency" value="1d">Every day<br>') self.response.write('<input type="submit" value="Update rate"></form>') gl=Global.query(Global.name=="global").fetch() if(len(gl)>0): gl=gl[0] fre=gl.limit if fre==0: str="No reports" if fre==1: str="Every 5 Minutes" if fre==12: str="Every 1 hour" if fre==288: str="Every day" self.response.write("Current Update Frequency: "+ str)
def post(self): original_url = self.request.headers['Referer'] stream_name = re.findall('=(.*)%3D%3D', original_url)[0] stream = Stream.query( Stream.name == stream_name, Stream.author == users.get_current_user()).fetch()[0] dellsts = self.request.get_all("status") print dellsts pictures = db.GqlQuery( "SELECT * FROM Picture " + "WHERE ANCESTOR IS :1 AND imgkey IN :2", db.Key.from_path('Stream', stream_name), dellsts) for picture in pictures: blobstore.delete(picture.imgkey) images.delete_serving_url(picture.imgkey) db.delete(pictures) pic_count = Count_pic.query( ancestor=ndb.Key('Stream', stream_name)).fetch()[0] # print(pic_counts) # for pic_count in pic_counts: pic_count.numbers = pic_count.numbers - len(dellsts) pic_count.put() stream.numberofpictures = pic_count.numbers stream.put() self.redirect(original_url)
def get(self): print("test!!") dellsts=self.request.get_all("status") if (len(dellsts) > 0): streams=Stream.query(Stream.name.IN(dellsts), Stream.author==users.get_current_user()).fetch() counts=CountViews.query(CountViews.name.IN(dellsts), ancestor=ndb.Key('User', users.get_current_user().nickname())).fetch() for stream in streams: pictures=db.GqlQuery("SELECT * FROM Picture " +"WHERE ANCESTOR IS :1",db.Key.from_path('Stream',stream.name)) for pic in pictures: images.delete_serving_url(pic.imgkey) blobstore.delete(pic.imgkey) db.delete(pictures) pic_count= Count_pic.query(ancestor=ndb.Key('Stream',stream.name)) ndb.delete_multi(ndb.put_multi(pic_count)) #print pic_count ndb.delete_multi(ndb.put_multi(streams)) ndb.delete_multi(ndb.put_multi(counts)) dellsts=self.request.get_all("status1") #self.response.write(len(dellsts)) if (len(dellsts) > 0): streams=Stream.query(Stream.name.IN(dellsts)).fetch() for stream in streams: if(users.get_current_user() and users.get_current_user().nickname() in stream.subscribers): stream.subscribers.remove(users.get_current_user().nickname()) stream.put() picNum_list = [] streams_1=Stream.query(Stream.author==users.get_current_user()).order(-Stream.creattime).fetch() for stream in streams_1: pic_count= Count_pic.query(ancestor=ndb.Key('Stream',stream.name)).fetch()[0] pictures=db.GqlQuery("SELECT * FROM Picture " +"WHERE ANCESTOR IS :1 "+"ORDER BY uploaddate DESC",db.Key.from_path('Stream',stream.name)) # print (stream.name, pic_count.numbers) # picNum_list.append(pic_count.numbers) picNum_list.append(pictures.count()) streams = Stream.query().fetch() streams_2 = [] count_list = [] user_name = users.get_current_user().nickname() # url =users.create_login_url('/') # if(users.get_current_user()): #user_name = users.get_current_user().nickname() url = users.create_logout_url('/') for stream in streams: if(users.get_current_user().email().lower() in stream.subscribers): count=CountViews.query(CountViews.name==stream.name,ancestor=ndb.Key('User',stream.author_name)).fetch()[0] pictures=db.GqlQuery("SELECT * FROM Picture " +"WHERE ANCESTOR IS :1 "+"ORDER BY uploaddate DESC",db.Key.from_path('Stream',stream.name)) stream.numberofpictures = pictures.count() streams_2.append(stream) count_list.append(count.numbers) #else: # self.redirect(url,permanent=False) template_values = { 'user_name':user_name, 'streams_1': streams_1, 'streams_2': streams_2, 'count_list': count_list, 'url': url, "picNum_list":picNum_list } template = JINJA_ENVIRONMENT.get_template('management_index.html') self.response.write(template.render(template_values))
def get(self): streams = Stream.query() for stream in streams: for i in range(len(stream.subscribers) - 1): stream.subscribers[i] = stream.subscribers[i].lower() self.response.write("Lower Sub Done!")
def get(self, photoIndexes, currentLocation): passedInCoord = currentLocation.split('_') lat = float(passedInCoord[0]) lon = float(passedInCoord[1]) displayImageObjs = [] # displayPhotoList = [] stream_query = Stream.query() for stream in stream_query: photos = db.GqlQuery( "SELECT * FROM Picture " + "WHERE ANCESTOR IS :1 " + "ORDER BY uploaddate DESC", db.Key.from_path('Stream', stream.name)) for photo in photos: photoUrl = images.get_serving_url(photo.imgkey) photoUrl = str(photoUrl) + "=s500" photoDict = {} photoDict["photoServingURL"] = photoUrl photoDict["date"] = str(photo.uploaddate) photoDict["loc"] = str(photo.loc) photoDict["streamName"] = str(stream.name) # photoDict["streamID"] = str(stream.key.id()) photoCoord = str(photo.loc).split(',') plat = float(photoCoord[0]) plon = float(photoCoord[1]) R = 6373.0 lat1 = radians(lat) lon1 = radians(lon) lat2 = radians(plat) lon2 = radians(plon) dlon = lon2 - lon1 dlat = lat2 - lat1 a = (sin( dlat / 2))**2 + cos(lat1) * cos(lat2) * (sin(dlon / 2))**2 c = 2 * atan2(sqrt(a), sqrt(1 - a)) distance = R * c photoDict["actualDistance"] = distance if distance > 10: photoDict["strDistance"] = str(distance).split('.', 1)[0] + 'km' else: photoDict["strDistance"] = str(distance * 1000).split( '.', 1)[0] + 'm' displayImageObjs.append(photoDict) displayImageObjs = sorted(displayImageObjs, key=lambda k: k['actualDistance']) passedPhotos = [] morePhotos = "False" indexURL = photoIndexes indexList = str(photoIndexes).split('_') if len(displayImageObjs) - 1 > int(indexList[1]): for i in range(int(indexList[0]), int(indexList[1]) + 1): passedPhotos.append(displayImageObjs[i]) indexURL = str(int(indexList[0]) + 16) + '_' + str(int(indexList[1]) + 16) morePhotos = "True" else: for i in range(int(indexList[0]), len(displayImageObjs)): passedPhotos.append(displayImageObjs[i]) dictPassed = { 'user': None, 'morePhotos': morePhotos, 'indexURL': indexURL, 'displayImageObjs': passedPhotos } #'displayPhotoList' : displayStreamList jsonObj = json.dumps(dictPassed, sort_keys=True, indent=4, separators=(',', ': ')) self.response.write(jsonObj)
def get(self): dellsts = self.request.get_all("status") if len(dellsts) > 0: streams = Stream.query(Stream.name.IN(dellsts), Stream.author == users.get_current_user()).fetch() counts = CountViews.query( CountViews.name.IN(dellsts), ancestor=ndb.Key("User", users.get_current_user().nickname()) ).fetch() for stream in streams: pictures = db.GqlQuery( "SELECT * FROM Picture " + "WHERE ANCESTOR IS :1", db.Key.from_path("Stream", stream.name) ) db.delete(pictures) ndb.delete_multi(ndb.put_multi(streams)) ndb.delete_multi(ndb.put_multi(counts)) dellsts = self.request.get_all("status1") # self.response.write(len(dellsts)) if len(dellsts) > 0: streams = Stream.query(Stream.name.IN(dellsts)).fetch() for stream in streams: if users.get_current_user() and users.get_current_user().nickname() in stream.subscribers: stream.subscribers.remove(users.get_current_user().nickname()) stream.put() self.response.write(users.get_current_user()) self.response.write(MANAGEMENT_PAGE_TEMPLATE) streams = Stream.query(Stream.author == users.get_current_user()).order(-Stream.creattime).fetch() self.response.write('<form action="/management" ,method="post"><table border="1" style="width:100%">') self.response.write("<tr><td>Name</td><td>Last New Picture</td><td>Number of Pictures</td><td>Delete</td></tr>") for stream in streams: self.response.write( '<tr><td><a href="%s">%s</a></td><td>%s</td><td>%s</td><td><input type="checkbox" name="status", value="%s"></td></tr>' % (stream.url, stream.name, stream.lastnewdate, stream.numberofpictures, stream.name) ) self.response.write("</table>") self.response.write('<input type="submit" value="Delete"></form>') self.response.write("<h2>Streams I Subscribe to</h2>") streams = Stream.query().fetch() self.response.write('<form action="/management" ,method="post"><table border="1" style="width:100%">') self.response.write( "<tr><td>Name</td><td>Last New Picture</td><td>Number of Pictures</td><td>Views</td><td>Delete</td></tr>" ) if users.get_current_user(): for stream in streams: if users.get_current_user().nickname() in stream.subscribers: count = CountViews.query( CountViews.name == stream.name, ancestor=ndb.Key("User", stream.author_name) ).fetch()[0] self.response.write( '<tr><td><a href="%s">%s</a></td><td>%s</td><td>%s</td><td>%s</td><td><input type="checkbox" name="status1", value="%s"></td></tr>' % ( stream.guesturl, stream.name, stream.lastnewdate, stream.numberofpictures, count.totalviews, stream.name, ) ) self.response.write("</table>") self.response.write('<input type="submit" value="Delete"></form>') self.response.write("<br><a href=%s>Logout</a>" % users.create_logout_url(self.request.url)) if not users.get_current_user(): self.redirect("/", permanent=False)
def get(self): print("test!!") dellsts = self.request.get_all("status") if (len(dellsts) > 0): streams = Stream.query( Stream.name.IN(dellsts), Stream.author == users.get_current_user()).fetch() counts = CountViews.query( CountViews.name.IN(dellsts), ancestor=ndb.Key('User', users.get_current_user().nickname())).fetch() for stream in streams: pictures = db.GqlQuery( "SELECT * FROM Picture " + "WHERE ANCESTOR IS :1", db.Key.from_path('Stream', stream.name)) for pic in pictures: images.delete_serving_url(pic.imgkey) blobstore.delete(pic.imgkey) db.delete(pictures) pic_count = Count_pic.query( ancestor=ndb.Key('Stream', stream.name)) ndb.delete_multi(ndb.put_multi(pic_count)) #print pic_count ndb.delete_multi(ndb.put_multi(streams)) ndb.delete_multi(ndb.put_multi(counts)) dellsts = self.request.get_all("status1") #self.response.write(len(dellsts)) if (len(dellsts) > 0): streams = Stream.query(Stream.name.IN(dellsts)).fetch() for stream in streams: if (users.get_current_user() and users.get_current_user().nickname() in stream.subscribers): stream.subscribers.remove( users.get_current_user().nickname()) stream.put() picNum_list = [] streams_1 = Stream.query(Stream.author == users.get_current_user() ).order(-Stream.creattime).fetch() for stream in streams_1: pic_count = Count_pic.query( ancestor=ndb.Key('Stream', stream.name)).fetch()[0] pictures = db.GqlQuery( "SELECT * FROM Picture " + "WHERE ANCESTOR IS :1 " + "ORDER BY uploaddate DESC", db.Key.from_path('Stream', stream.name)) # print (stream.name, pic_count.numbers) # picNum_list.append(pic_count.numbers) picNum_list.append(pictures.count()) streams = Stream.query().fetch() streams_2 = [] count_list = [] user_name = users.get_current_user().nickname() # url =users.create_login_url('/') # if(users.get_current_user()): #user_name = users.get_current_user().nickname() url = users.create_logout_url('/') for stream in streams: if (users.get_current_user().email() in stream.subscribers): count = CountViews.query(CountViews.name == stream.name, ancestor=ndb.Key( 'User', stream.author_name)).fetch()[0] pictures = db.GqlQuery( "SELECT * FROM Picture " + "WHERE ANCESTOR IS :1 " + "ORDER BY uploaddate DESC", db.Key.from_path('Stream', stream.name)) stream.numberofpictures = pictures.count() streams_2.append(stream) count_list.append(count.numbers) #else: # self.redirect(url,permanent=False) template_values = { 'user_name': user_name, 'streams_1': streams_1, 'streams_2': streams_2, 'count_list': count_list, 'url': url, "picNum_list": picNum_list } template = JINJA_ENVIRONMENT.get_template('management_index.html') self.response.write(template.render(template_values))