def post(self): query_string = cgi.escape(self.request.get('query_string')) if not query_string : self.errorpage("That query does not exist") else: if(query_string[0]=='#'): #self.response.write("TAGGG") queryAll = Stream.query() tagToStream = [] for query in queryAll: tags = query.tags for tag in tags: if(query_string==tag): #self.response.write(tag[0:]) tagToStream.append(query) # for streamName in tagToStream: # self.response.write(streamName + " ") if(len(tagToStream)>1):self.multiple(query_string, tagToStream) elif(len(tagToStream)==1): goToStream = "/view_stream/?stream_name=" + str(tagToStream[0].name) self.redirect(goToStream) else: self.errorpage("That query does not exist") else: queryStream = Stream.query(Stream.name == query_string) entity = queryStream.get() if entity is not None: goToStream = "/view_stream/?stream_name=" + query_string self.redirect(goToStream) else: self.errorpage("That query does not exist")
def get(self): query_string = cgi.escape(self.request.get('query_string')) queryStreams = Stream.query(Stream.name == query_string) images = {'stream_names': [], 'image_urls': []} for stream in queryStreams: images['stream_names'].append(stream.name) images['image_urls'].append(stream.cover_image) image_json = json.dumps(images, indent=4, separators=(',', ': ')) self.response.write(image_json)
def post(self): JINJA_ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader('templates'), extensions=['jinja2.ext.autoescape'], autoescape=True) #Get the stream's data stream_name = cgi.escape(self.request.get('stream_name')) subscribers_string = cgi.escape(self.request.get('subscribers')) message = cgi.escape(self.request.get('message')) tags_string = cgi.escape(self.request.get('tags')) cover_image = cgi.escape(self.request.get('cover_image')) subscribers = [x.strip() for x in subscribers_string.split(',')] tags = [x.strip() for x in tags_string.split(',')] #Send emails to all subscribers email = mail.EmailMessage() user = users.get_current_user() email.sender = user.email() email.subject = "'Notification of Subscription to %s'" % stream_name email.body = message subscriber_ids=[] for subscriber in subscribers: if len(subscriber)!=0: sub_id = users.User(subscriber).user_id() subscriber_ids.append("%s" % sub_id) email.to = "%s" % subscriber email.send() #stream already exists if not stream_name: self.redirect('/error') stream = Stream.query(Stream.name == stream_name).get() if stream: self.redirect('/error') else : #Create a new stream with name, no photos, and no views initially #Add stream to the datastore user = users.get_current_user() new_stream = Stream(owner_id = user.user_id(),name=stream_name,photos=[], num_photos = 0, views=0, view_queue=[], subscribed_users=subscriber_ids,timestamp = datetime.datetime.now(), tags = tags, cover_image=cover_image, email=user.email()) new_stream.key = ndb.Key(Stream, stream_name) new_stream.put() #encure redict happens after data store is updated jobDone = False while(not jobDone): search_results = Stream.query(Stream.name == stream_name) for search in search_results: jobDone = True self.redirect('/management')
def get(self): latitude = cgi.escape(self.request.get('latitude')) longitude = cgi.escape(self.request.get('longitude')) lat_min = float(latitude) - 20.0 lat_max = float(latitude) + 20.0 lng_min = float(longitude) - 20.0 lng_max = float(longitude) + 20.0 allStreams = Stream.query() images = {'stream_names': [], 'image_urls': []} for stream in allStreams: photos_in_stream = stream.photos # for photo in photos_in_stream: # images['image_urls'].append(photo.url) stream_name = stream.name for photo in photos_in_stream : if photo.lat > lat_min and photo.lat < lat_max and photo.lng > lng_min and photo.lng < lng_max : images['image_urls'].append(photo.url) images['stream_names'].append(stream_name) image_json = json.dumps(images,indent=4, separators=(',', ': ')) self.response.write(image_json)
def get(self): latitude = cgi.escape(self.request.get('latitude')) longitude = cgi.escape(self.request.get('longitude')) lat_min = float(latitude) - 20.0 lat_max = float(latitude) + 20.0 lng_min = float(longitude) - 20.0 lng_max = float(longitude) + 20.0 allStreams = Stream.query() images = {'stream_names': [], 'image_urls': []} for stream in allStreams: photos_in_stream = stream.photos # for photo in photos_in_stream: # images['image_urls'].append(photo.url) stream_name = stream.name for photo in photos_in_stream: if photo.lat > lat_min and photo.lat < lat_max and photo.lng > lng_min and photo.lng < lng_max: images['image_urls'].append(photo.url) images['stream_names'].append(stream_name) image_json = json.dumps(images, indent=4, separators=(',', ': ')) self.response.write(image_json)