Exemplo n.º 1
0
 def getImages(self, request):
     stream = Stream.get_by_id(request.stream_id, getStreamKey())
     if not stream:
         return ResponseImages()
     return ResponseImages(images=[
         getImageInfo(x)
         for x in Image.query(ancestor=stream.key).order(-Image.create_time)
     ])
Exemplo n.º 2
0
 def getNearbyImages(self, request):
     if request.latitude < -90.0 or request.latitude > 90.0 or request.longitude < -180.0 or request.longitude > 180.0:
         return ResponseImages()
     images = filter(
         lambda x: x.longitude >= -180.0 and x.longitude <= 180.0,
         Image.query(Image.latitude >= -90.0,
                     Image.latitude <= 90.0).fetch())
     return ResponseImages(images=[
         getImageInfo(img)
         for img in sorted(images,
                           key=lambda x: HaversineDistance(
                               (request.latitude, request.longitude),
                               (x.latitude, x.longitude)))
     ])
Exemplo n.º 3
0
 def getNearbyImages(self, request):
     if request.latitude < -90.0 or request.latitude > 90.0 or request.longitude < -180.0 or request.longitude > 180.0:
         return ResponseImages()
     images = filter(lambda x: x.longitude>=-180.0 and x.longitude<=180.0, Image.query(Image.latitude>=-90.0, Image.latitude<=90.0).fetch());
     return ResponseImages(images=[getImageInfo(img) for img in sorted(images,
             key=lambda x: HaversineDistance((request.latitude, request.longitude), (x.latitude, x.longitude)))])
Exemplo n.º 4
0
 def getImages(self, request):
     stream = Stream.get_by_id(request.stream_id, getStreamKey())
     if not stream:
         return ResponseImages()
     return ResponseImages(images=[getImageInfo(x) for x in Image.query(ancestor=stream.key).order(-Image.create_time)])
Exemplo n.º 5
0
 def get(self):
     user = users.get_current_user()
     streamId = self.request.get("id")
     if not streamId:
         logging.error("Unable to get id from url")
         self.error(400)
         jumpToErrorPage(self)
         return
     stream = Stream.get_by_id(int(streamId), getStreamKey())
     if not stream:
         logging.error("Unable to get stream with id " + streamId)
         self.error(400)
         jumpToErrorPage(
             self, 'Unable to find the stream! The stream may be deleted!')
         return
     if self.request.get('newest_pic'):
         self.response.write(
             get_serving_url(
                 Image.query(ancestor=stream.key).order(
                     -Image.create_time).get().img))
         return
     if (self.request.get('geo_info')):
         timeline = self.request.get_all('timeline[]')
         if (timeline is None) or len(timeline) < 2:
             self.error(400)
             return
         startDate = datetime.now() - timedelta(365 - int(timeline[0]))
         endDate = datetime.now() - timedelta(365 - int(timeline[1]))
         images = Image.query(Image.create_time >= startDate,
                              Image.create_time <= endDate,
                              ancestor=stream.key)
         images = filter(
             lambda x: x.latitude >= -90.0 and x.latitude <= 90.0 and x.
             longitude >= -180.0 and x.longitude <= 180.0, images)
         self.response.write(
             json.dumps([{
                 'url': get_serving_url(img.img),
                 'latitude': img.latitude,
                 'longitude': img.longitude
             } for img in images]))
         return
     if self.request.get('upload'):
         self.response.write(
             blobstore.create_upload_url(
                 urls.URL_VIEW_STREAM_PAGE + urls.URL_UPLOAD_HANDLER +
                 '/?' + urllib.urlencode({'id': streamId})))
         return
     template_dict = urls.getUrlDir()
     template_dict['images'] = [
         get_serving_url(x.img)
         for x in Image.query(ancestor=stream.key).order(-Image.create_time)
     ]
     template_dict['id'] = streamId
     template_dict['stream'] = stream
     template_dict['images_per_page'] = images_per_page
     if stream.user == user.email():
         template_dict['is_owner'] = True
     else:
         template_dict['is_owner'] = False
         increaseViewNum(stream)
         stream.viewCount = stream.viewCount + 1
         template_dict['subscribed'] = user.email() in stream.subscribers
         stream.put()
     self.response.write(
         urls.getTemplate(template_name).render(template_dict))