예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
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)
예제 #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)
예제 #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()
예제 #6
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)
예제 #7
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()
예제 #8
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)
예제 #9
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))
예제 #10
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))