Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    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()
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
    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()
Ejemplo n.º 6
0
 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)
Ejemplo n.º 7
0
    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))
Ejemplo n.º 8
0
    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))