Exemplo n.º 1
0
 def post(self):
     user = users.get_current_user()
     name = self.request.get("name")
     emails = re.findall(r'[^(?: |\n|,)].+', self.request.get("email"))
     extra_message = self.request.get("extra_message")
     tag = self.request.get("tag")
     cover_image_url = self.request.get("cover_image_url")
     for email in emails:
         if not is_valid_email(
                 email):  # take from http://www.regular-expressions.info/
             jumpToErrorPage(
                 self, 'Stream is not created! "' + email +
                 '" is not a valid email!')
             return
     if len(
             Stream.query(Stream.user == user.email(),
                          Stream.name == name,
                          ancestor=getStreamKey()).fetch()) > 0:
         jumpToErrorPage(
             self, 'Stream is not created! Name "' + name +
             '" already exists. Please use another name.')
         return
     stream = createStream(user.email(), name, tag, cover_image_url)
     addStreamToSearchService(stream)
     sendSubscribeInvitationEmail(emails, extra_message, stream)
     self.redirect(urls.URL_MANAGEMENT_PAGE, permanent=True)
Exemplo n.º 2
0
 def post(self):
     user = users.get_current_user()
     if self.request.get('delete'):
         for sid in self.request.get_all("del_checkbox"):
             stream = Stream.get_by_id(int(sid), getStreamKey())
             if stream:
                 removeStreamFromSearchService(stream)
                 deleteStream(stream)
         self.redirect(urls.URL_MANAGEMENT_PAGE, permanent=True)
         return
     if self.request.get('unsubscribe'):
         for sid in self.request.get_all("unsub_checkbox"):
             stream = Stream.get_by_id(int(sid), getStreamKey())
             if stream:
                 unsubscribeStream(stream, user.email())
     self.redirect(urls.URL_MANAGEMENT_PAGE, permanent=True)
Exemplo n.º 3
0
 def get(self):
     user = users.get_current_user()
     streams = Stream.query(Stream.user == user.email(),
                            ancestor=getStreamKey()).order(
                                -Stream.last_newpic_time, -Stream.pic_num,
                                Stream.name, -Stream.create_time)
     subscribed = Stream.query(Stream.subscribers == user.email(),
                               ancestor=getStreamKey()).order(
                                   -Stream.last_newpic_time,
                                   -Stream.pic_num, Stream.name,
                                   -Stream.create_time)
     template_dict = urls.getUrlDir()
     template_dict['cur_page'] = 'management'
     template_dict["streams"] = streams
     template_dict["subscribed"] = subscribed
     self.response.write(
         urls.getTemplate(template_name).render(template_dict))
 def get(self):
     user = users.get_current_user()
     streams = Stream.query(ancestor=getStreamKey()).order(-Stream.last_newpic_time, -Stream.viewCount,
                            -Stream.pic_num, Stream.name, -Stream.create_time)
     template_dict = urls.getUrlDir()
     template_dict['cur_page'] = 'view_all_stream'
     template_dict["streams"] = streams
     self.response.write(urls.getTemplate(template_name).render(template_dict))
Exemplo n.º 5
0
 def getOwnedStreams(self, request):
     user = endpoints.get_current_user()
     if user:
         return RespondStreams(streams=[getStreamInfo(stream) for stream in Stream.query(Stream.user == user.email(),
                               ancestor=getStreamKey()).order(-Stream.last_newpic_time, -Stream.pic_num, Stream.name,
                               -Stream.create_time)])
     else:
         return RespondStreams(streams=[])
Exemplo n.º 6
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)
     ])
 def get(self):
     user = users.get_current_user()
     streams = Stream.query(ancestor=getStreamKey()).order(
         -Stream.last_newpic_time, -Stream.viewCount, -Stream.pic_num, Stream.name, -Stream.create_time
     )
     template_dict = urls.getUrlDir()
     template_dict["cur_page"] = "view_all_stream"
     template_dict["streams"] = streams
     self.response.write(urls.getTemplate(template_name).render(template_dict))
Exemplo n.º 8
0
 def getStream(self, request):
     user = endpoints.get_current_user()
     stream = Stream.get_by_id(request.stream_id, getStreamKey())
     if not stream:
         return RespondStream()
     if not (user and user.email()==stream.user):
         stream.viewCount = stream.viewCount + 1
         stream.put()
     return RespondStream(stream=getStreamInfo(stream))
Exemplo n.º 9
0
 def getUploadURL(self, request):
     user = endpoints.get_current_user()
     if not user:
         return StringResponse()
     stream = Stream.get_by_id(request.stream_id, getStreamKey())
     if not stream:
         return StringResponse()
     if stream.user != user.email():
         return StringResponse()
     return StringResponse(value=blobstore.create_upload_url(BackendFileuploadHandler.url +
                                 '/?'+urllib.urlencode({'id':stream.key.id()})))
Exemplo n.º 10
0
 def unsubscribe(self, request):
     user = endpoints.get_current_user()
     if not user:
         return BooleanResponse(value=False)
     stream = Stream.get_by_id(request.stream_id, getStreamKey())
     if not stream:
         return BooleanResponse(value=False)
     if stream.user == user.email():
         return BooleanResponse(value=False)
     if user.email() in stream.subscribers:
         unsubscribeStream(stream, user.email())
     return BooleanResponse(value=True)
Exemplo n.º 11
0
 def post(self):
     user = users.get_current_user()
     name = self.request.get("name")
     emails = re.findall(r'[^(?: |\n|,)].+', self.request.get("email"))
     extra_message = self.request.get("extra_message")
     tag = self.request.get("tag")
     cover_image_url = self.request.get("cover_image_url")
     for email in emails:
         if not is_valid_email(email): # take from http://www.regular-expressions.info/
             jumpToErrorPage(self, 'Stream is not created! "'+email+'" is not a valid email!')
             return
     if len(Stream.query( Stream.user==user.email(), Stream.name==name, ancestor=getStreamKey()).fetch()) > 0:
         jumpToErrorPage(self, 'Stream is not created! Name "'+name+'" already exists. Please use another name.')
         return
     stream = createStream(user.email(), name, tag, cover_image_url)
     addStreamToSearchService(stream)
     sendSubscribeInvitationEmail(emails, extra_message, stream)
     self.redirect(urls.URL_MANAGEMENT_PAGE, permanent=True)
Exemplo n.º 12
0
 def post(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)
         return
     stream = Stream.get_by_id(int(streamId), getStreamKey())
     if not stream:
         logging.error("Unable to get stream with id " + streamId)
         self.error(400)
         return
     if self.request.get('subscribe'):
         if user.email() in stream.subscribers:
             unsubscribeStream(stream, user.email())
             self.response.write('unsubscribed')
         else:
             subscribeStream(stream, user.email())
             self.response.write('subscribed')
Exemplo n.º 13
0
 def post(self):
     if not self.get_uploads('img') or len(self.get_uploads('img')) < 1:
         logging.error("Unable to get img")
         self.error(400)
         return
     upload = self.get_uploads('img')[0]
     if not upload.key():
         logging.error("Unable to get img")
         self.error(500)
         return
     sid = self.request.get('id')
     if not sid:
         logging.error("Unable to get id from url")
         self.error(400)
         blobstore.delete(upload.key())
         return
     stream = Stream.get_by_id(int(sid), getStreamKey())
     if not stream:
         logging.error("Unable to get stream with id " + str(sid))
         self.error(400)
         blobstore.delete(upload.key())
         return
     lat = self.request.get('latitude')
     if not lat:
         logging.error("Unable to get latitude!")
         self.error(400)
         blobstore.delete(upload.key())
         return
     lgi = self.request.get('longitude')
     if not lgi:
         logging.error('Unable to get longitude!')
         logging.error(400)
         blobstore.delete(upload.key())
         return
     addImage(stream, upload, float(lat), float(lgi),
              self.request.get('tag'))
     self.response.write('success')
Exemplo n.º 14
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.º 15
0
 def getAllStreams(self, request):
     return RespondStreams(streams=[getStreamInfo(stream) for stream in Stream.query(ancestor=getStreamKey())
                             .order(-Stream.last_newpic_time, -Stream.pic_num, Stream.name, -Stream.create_time)])
Exemplo n.º 16
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))