def get(self):
     View.more = True
     template = JINJA_ENVIRONMENT.get_template('templates/searchresult.html')
     pattern = self.request.get("searchPattern")
     found_in_tag = False
     Name = []
     streams = StreamModel.query().fetch()
     for st in streams:
         Name.append(st.name)
     num = 0
     infos = []
     for name in Name:
         fi = re.findall(pattern, name)
         stream = StreamModel.query(StreamModel.name==name).fetch()[0]
         for tag in stream.tag:
             if len(re.findall(pattern,tag))>0:
                 found_in_tag = True
         if len(fi)>0 or found_in_tag==True:
             infos.append((stream.name, stream.coverpageURL, stream.url, num))
             if num==3:
                 num = 0
             else:
                 num += 1
     template_values = {
         'infos': infos
     }
     self.response.write(template.render(template_values))
 def get(self):
     pattern = re.findall("%3D%3D(.+)",self.request.url)[0]
     found_in_tag = False
     Name = []
     streams = StreamModel.query().fetch()
     for st in streams:
         Name.append(st.name)
     display = 0
     streamcoverURLs = []
     streamnames = []
     # infos = []
     for name in Name:
         fi = re.findall(pattern, name)
         stream = StreamModel.query(StreamModel.name==name).fetch()[0]
         for tag in stream.tag:
             if len(re.findall(pattern,tag))>0:
                 found_in_tag = True
         if len(fi)>0 or found_in_tag==True:
             streamcoverURLs.append(stream.coverpageURL)
             streamnames.append(stream.name)
             display += 1
     result = {"streamcoverurls":streamcoverURLs, 'streamnames':streamnames}
     jsonObj=json.dumps(result, sort_keys=True,indent=4, separators=(',', ': '))
     self.response.headers['Content-Type']="application/json"
     self.response.write(jsonObj)
    def get(self):
        user = users.get_current_user()
        View.more = True
        if (user):

            url = users.create_logout_url(self.request.url)
            url_linktext = 'Logout'
            stream_query = StreamModel.query(StreamModel.author==user).order(-StreamModel.createTime).fetch()
            stream_query_all = StreamModel.query().fetch()
            findone = 0

            if (len(stream_query_all)>0):
                for stream in stream_query_all:
                    if user.nickname() in stream.subscribers:
                        findone = 1

            template_values = {
                'user': user,
                'url': url,
                'url_linktext': url_linktext,
                'stream_query_len': len(stream_query),
                'stream_query': stream_query,
                'stream_query_all': stream_query_all,
                'stream_query_all_len': len(stream_query_all),
                'find_done': findone,
            }
            template = JINJA_ENVIRONMENT.get_template('templates/management.html')
            self.response.write(template.render(template_values))
        else:
            self.redirect('/')
Example #4
0
 def get(self):
     self.response.write(SEARCH_PAGE_TEMPLATE)
     #returnURL = self.request.headers['Referer']
     #self.response.write(self.response.url)
     pattern = self.request.get("searchPattern")
     found_in_tag = False
     Name = []
     #StreamName = []
     streams = StreamModel.query().fetch()
     for st in streams:
         Name.append(st.name)
     num = 0
     for name in Name:
         fi = re.findall(pattern, name)
         stream = StreamModel.query(StreamModel.name==name).fetch()[0]
         for tag in stream.tag:
             if len(re.findall(pattern,tag))>0:
                 found_in_tag = True
         if len(fi)>0 or found_in_tag==True:
             #StreamName.append(name)
             if num==0:
                 self.response.write("<tr>")
             self.response.write(STREAM_ENTRY_TEMPLATE % (stream.url, stream.coverpageURL, stream.name))
             if num==3:
                 self.response.write("</tr>")
                 num = 0
             else:
                 num += 1
    def get(self):
        View.more = True
        self.response.write(TRENDING_PAGE_TEMPLATE)
        countView_query = CountViewModel.query().order(-CountViewModel.count).fetch()
        index = 0
        self.response.write('<table border="0" style="width:100%">')
        if len(countView_query)> 0:
            for view in countView_query:
                if index < 3:
                    index += 1
                    stream_query = StreamModel.query(StreamModel.name == view.name).fetch()
                    if len(stream_query)>0:
                        stream = stream_query[0]
                        self.response.write(STREAM_ENTRY_TEMPLATE % (stream.url, stream.coverpageURL, stream.name, str(view.count) + " views in past hour"))

        self.response.write('</table><hr>')

        self.response.write(TRENDING_REPORT_TEMPLATE)
        count_query = CountModel.query(CountModel.name=="Trending").fetch()
        if len(count_query)==0:
            count = CountModel(name="Trending", count=0, freq=0)
            self.response.write( "Present frequency: No reports")
            count.put()
        else:
            count = count_query[0]
            self.response.write("Present frequency: "+freq_dict[count.freq])
 def handle_upload(self, stream_name):
     results = []
     stream_query = StreamModel.query(StreamModel.name==stream_name)
     stream = stream_query.fetch()[0]
     for name, fieldStorage in self.request.POST.items():
         if type(fieldStorage) is unicode:
             continue
         result = {}
         result['name'] = re.sub(
             r'^.*\\',
             '',
             fieldStorage.filename)
         result['type'] = fieldStorage.type
         result['size'] = self.get_file_size(fieldStorage.file)
         if self.validate(result):
             picture = fieldStorage.value
             #self.write_data(stream, stream_name, picture)
             #num = num+1
             num = self.add(ndb.Key('StreamModel', stream.key.id()))
             user_picture = PictureModel(parent = db.Key.from_path('StreamModel', stream_name))
             user_picture.id = str(num)
             picture = images.resize(picture, 640, 800)
             user_picture.picture = db.Blob(picture)
             stream.lastUpdated = user_picture.uploadDate
             user_picture.lat = random.random()
             user_picture.lg = random.random()
             user_picture.put()
             # key = self.write_blob(
             #     picture, result
             # )
             # if key is not None:
         results.append(result)
     return results
    def get(self):
        View.more = True
        template = JINJA_ENVIRONMENT.get_template('templates/trending.html')
        countView_query = CountViewModel.query().order(-CountViewModel.count).fetch()
        index = 0
        infos = []
        if len(countView_query)> 0:
            for view in countView_query:
                if index < 3:
                    index += 1
                    stream_query = StreamModel.query(StreamModel.name == view.name).fetch()
                    if len(stream_query)>0:
                        stream = stream_query[0]
                        infos.append((stream.name, stream.coverpageURL, stream.url, str(view.count)))
        count_query = CountModel.query(CountModel.name=="Trending").fetch()
        freq = "No reports"
        if len(count_query)==0:
            count = CountModel(name="Trending", count=0, freq=0)
            count.put()
        else:
            count = count_query[0]
            freq = freq_dict[count.freq]

        template_values = {
            'infos': infos,
            'freq': freq
        }
        self.response.write(template.render(template_values))
 def get(self):
     global mobileshow
     stream_name = re.findall("%3D%3D(.+)", self.request.url)[0]
     stream_query = StreamModel.query(StreamModel.name==stream_name).fetch()
     picture_query = db.GqlQuery("SELECT *FROM PictureModel WHERE ANCESTOR IS :1 ORDER BY uploadDate DESC",
                                   db.Key.from_path('StreamModel', stream_name))
     stream = stream_query[0]
     Imagesurl = []
     Imagecap = []
     num = stream.totalPicture
     if (num > 16):
         for picture in picture_query:
             if (int(picture.id)>(mobileshow*16) and int(picture.id)<=((mobileshow+1)*16)):
                 s = "http://sacred-highway-108321.appspot.com/android/getimage==" + stream_name + "===" + str(picture.id)
                 Imagesurl.append(s)
                 Imagecap.append(str(picture.id))
         mobileshow += 1
         if mobileshow*16 > num:
             mobileshow = 0
     else:
         for picture in picture_query:
             s = "http://sacred-highway-108321.appspot.com/android/getimage==" + stream_name + "===" + str(picture.id)
             Imagesurl.append(s)
             Imagecap.append(str(picture.id))
     # Imagesurl.append("http://static.independent.co.uk/s3fs-public/styles/story_large/public/thumbnails/image/2013/01/24/12/v2-cute-cat-picture.jpg")
     # Imagecap.append("Haha")
     result = {"imageurl":Imagesurl, 'imagecap':Imagecap}
     jsonObj=json.dumps(result, sort_keys=True,indent=4, separators=(',', ': '))
     self.response.headers['Content-Type']="application/json"
     self.response.write(jsonObj)
    def get(self):
        user = users.get_current_user()
        View.more = True
        if (user):
            url = users.create_logout_url(self.request.url)
            url_linktext = 'Logout'
            self.response.write(MANAGEMENT_PAGE_TEMPLATE % (url, url_linktext))

            stream_query = StreamModel.query(StreamModel.author==user).order(-StreamModel.createTime).fetch()
            self.response.write('<form action="/deletestream", method="post"><table border="1" style="width:100%">')
            self.response.write('<tr><td>Name</td><td>Last New Picture</td><td>Number of Pictures</td><td>Delete</td></tr>')
            if len(stream_query) > 0:
                for stream in stream_query:
                    self.response.write(STREAM_I_OWN_ENTRY % (stream.url, stream.name,
                                                              stream.lastUpdated, str(stream.totalPicture), stream.name))
            else:
                self.response.write('<tr><td align="center" colspan="4">No data available in table</td></tr>')

            self.response.write('</table>')
            self.response.write('<input type="submit" value ="Delete Checked"></form>')

            ################################################################################################################
            self.response.write('<h3>Streams I Subscribe to</h3>')
            stream_query = StreamModel.query().fetch()
            self.response.write('<form action="/unsubscribe", method="post"><table border="1" style="width:100%">')
            self.response.write('<tr><td>Name</td><td>Last New Picture</td><td>Number of Pictures</td><td>Unsubscribe</td></tr>')

            findone = False
            if len(stream_query) > 0:
                for stream in stream_query:
                    if user.nickname() in stream.subscribers:
                        findone = True
                        self.response.write(STREAM_I_SUBSCRIBE_ENTRY % (stream.url, stream.name,
                                                              stream.lastUpdated, str(stream.totalPicture), stream.name))
            if not findone:
                self.response.write('<tr><td align="center" colspan="4">No data available in table</td></tr>')

            self.response.write('</table>')
            self.response.write('<input type="submit" value ="Unsubscribe Checked"></form>')

        else:
            self.redirect('/')
 def post(self):
     returnURL = self.request.headers['Referer']
     self.response.write(self.request.url)
     stream_name = re.findall("unsubscribesingle%3D(.*)",self.request.url)[0]
     self.response.write(stream_name)
     stream_query = StreamModel.query(StreamModel.name==stream_name).fetch()
     if len(stream_query)>0:
         stream = stream_query[0]
         stream.subscribers.remove(users.get_current_user().nickname())
         stream.put()
     self.redirect(returnURL)
    def post(self):
        returnURL = self.request.headers['Referer']
        streams = self.request.get_all("unSubscribe")

        if len(streams) > 0:
            stream_query = StreamModel.query(StreamModel.name.IN(streams))
            streams = stream_query.fetch()
            for stream in streams:
                stream.subscribers.remove(users.get_current_user().nickname())
                stream.put()

        self.redirect(returnURL)
 def post(self):
     returnURL = self.request.headers['Referer']
     streams = self.request.get_all("deleteStream")
     if len(streams) > 0:
         countViews = CountViewModel.query(CountViewModel.name.IN(streams)).fetch()
         ndb.delete_multi(ndb.put_multi(countViews))
         stream_query = StreamModel.query(StreamModel.name.IN(streams), StreamModel.author==users.get_current_user())
         streams = stream_query.fetch()
         for stream in streams:
             pictures = db.GqlQuery("SELECT *FROM PictureModel WHERE ANCESTOR IS :1", db.Key.from_path('StreamModle',stream.name))
             db.delete(pictures)
         ndb.delete_multi(ndb.put_multi(streams))
     self.redirect(returnURL)
 def post(self):
     picture = self.request.get('file')
     stream_name = self.request.params['streamname']
     stream_query = StreamModel.query(StreamModel.name==stream_name)
     stream = stream_query.fetch()[0]
     stream.totalPicture = stream.totalPicture + 1
     user_picture = PictureModel(parent = db.Key.from_path('StreamModel', stream_name))
     user_picture.id = str(stream.totalPicture)
     picture = images.resize(picture, 320, 400)
     user_picture.picture = db.Blob(picture)
     stream.lastUpdated = user_picture.uploadDate
     stream.put()
     user_picture.put()
 def get(self):
     user = re.findall("%3D%3D(.+)",self.request.url)[0]
     streamcoverURLs = []
     streamnames = []
     name = []
     streams = StreamModel.query().fetch()
     for st in streams:
         name = []
         for n in st.subscribers:
             name.append(n.lower())
         if user.lower() in name:
             streamcoverURLs.append(st.coverpageURL)
             streamnames.append(st.name)
     result = {"streamcoverurls":streamcoverURLs, 'streamnames':streamnames}
     jsonObj=json.dumps(result, sort_keys=True,indent=4, separators=(',', ': '))
     self.response.headers['Content-Type']="application/json"
     self.response.write(jsonObj)
 def post(self):
     returnURL = self.request.headers['Referer']
     picture = self.request.get('file')
     if (len(picture)>0):
         stream_name = re.findall('=(.*)', returnURL)[0]
         stream_query = StreamModel.query(StreamModel.name==stream_name)
         stream = stream_query.fetch()[0]
         if (stream.author == users.get_current_user()):
             stream.totalPicture = stream.totalPicture + 1
             user_picture = PictureModel(parent = db.Key.from_path('StreamModel', stream_name))
             user_picture.id = str(stream.totalPicture)
             picture = images.resize(picture, 320, 400)
             user_picture.picture = db.Blob(picture)
             stream.lastUpdated = user_picture.uploadDate
             user_picture.put()
             stream.put()
     self.redirect(returnURL)
 def get(self):
     latitude = float(re.findall("%3D%3D(.+)%3D%3D%3D", self.request.url)[0])
     longitude = float(re.findall("%3D%3D%3D(.+)", self.request.url)[0])
     stream_query = StreamModel.query().fetch()
     Imagesurl = []
     Imagecap = []
     streamnames = []
     container = []
     num = 0
     global nearbyshow
     total = 0
     for stream in stream_query:
         picture_query = db.GqlQuery("SELECT *FROM PictureModel WHERE ANCESTOR IS :1 ORDER BY uploadDate DESC",
                                   db.Key.from_path('StreamModel', str(stream.name)))
         for picture in picture_query:
             dis = abs(pow((30.28226821-latitude),2.0)+pow((97.7393+longitude),2.0))
             container.append((dis, picture, stream.name))
             total += 1
     container.sort(key=lambda x:x[0])
     if nearbyshow*8 <= total and (nearbyshow+1)*8 > total:
         nearbyshow = 0
     else:
         nearbyshow += 1
     for item in container:
         if nearbyshow == 0 or (nearbyshow*8< num and (nearbyshow+1)*8 >= num):
             pic = item[1]
             # parent = pic.getParent().get()
             s = "http://sacred-highway-108321.appspot.com/android/getimage==" + item[2] + "===" + str(pic.id)
             Imagesurl.append(s)
             Imagecap.append(str(pic.id))
             streamnames.append(item[2])
         num += 1
     # for pic in picture_query:
     #     if (num < 8):
     #         parent = pic.getParent().get()
     #         s = "http://sacred-highway-108321.appspot.com/android/getimage==" + parent.name + "===" + str(pic.id)
     #         Imagesurl.append(s)
     #         Imagecap.append(str(pic.id))
     #         streamnames.append(parent.name)
     #         num += 1
     result = {"imageurl":Imagesurl, 'imagecap':Imagecap, "streamnames": streamnames}
     jsonObj=json.dumps(result, sort_keys=True,indent=4, separators=(',', ': '))
     # self.response.write(container)
     self.response.headers['Content-Type']="application/json"
     self.response.write(jsonObj)
    def get(self):
        user = users.get_current_user()
        stream_name = re.findall('%3D(.*)', self.request.url)[0]
        self.response.write(VIEW_SINGLE_PAGE_TEMPLATE)
        self.response.write('<h3>%s</h3>' % stream_name)
        stream_query = StreamModel.query(StreamModel.name==stream_name)
        stream = stream_query.fetch()[0]

        self.response.write('<table style="width:100%"><tr>')
        picture_query = db.GqlQuery("SELECT *FROM PictureModel WHERE ANCESTOR IS :1 ORDER BY uploadDate DESC",
                                  db.Key.from_path('StreamModel', stream_name))

        global index
        showNum = 0

        self.response.write('The total number of picture is ' + str(stream.totalPicture) + ': ')
        for picture in picture_query[index:stream.totalPicture]:
            if (showNum < NUM_PICTURE_PER_STREAM):
                showNum += 1
                self.response.write(picture.id)
                self.response.write(PICTURE_ENTRY_TEMPLATE % picture.key())

        self.response.write('showned below.')
        self.response.write('</tr></table>')
        # morePictureURL = urllib.urlencode({'showmore':user.nickname()+"=="+stream_name+"++0"})
        morePictureURL = urllib.urlencode({'showmore':stream_name+"=="+str(index)})
        self.response.write(MORE_ENTRY_TEMPLATE % morePictureURL)
        if (stream.author == user):
            self.response.write(UPLOAD_ENTRY_TEMPLATE)
        else:
            countView_query = CountViewModel.query(CountViewModel.name==stream_name).fetch()
            #if len(countView_query)>0:
            if View.more == True:
                countView = countView_query[0]
                countView.count = countView.count + 1
                countView.total = countView.total + 1
                countView.put()
            View.more = False
            url = urllib.urlencode({'subscribe':stream_name})
            if user.nickname() in stream.subscribers:
                url = urllib.urlencode({'unsubscribesingle':stream_name})
                self.response.write(UNSUBSCRIBE_ENTRY_TEMPLATE % url)
            else:
                url = urllib.urlencode({'subscribe':stream_name})
                self.response.write(SUBSCRIBE_ENTRY_TEMPLATE % url)
 def get(self):
     template = JINJA_ENVIRONMENT.get_template('templates/view.html')
     stream_query = StreamModel.query().order(StreamModel.createTime).fetch()
     index_info = []
     num = 0
     if len(stream_query) > 0:
         self.more = True
         for stream in stream_query:
             index_info.append((stream.name, stream.coverpageURL, stream.url, num))
             if num==3:
                 num = 0
             else:
                 num += 1
     template_values = {
         'stream_query_len': len(stream_query),
         'index_info': index_info
     }
     self.response.write(template.render(template_values))
     def get(self):
        # patten = self.request.get('term')
        # print patten
        streams = StreamModel.query().fetch()
        namelist = list()
        for stream in streams:
            # if patten in stream.name:
            namelist.append(stream.name)
            for tag in stream.tag:
                # if (patten in tag) and (tag != ""):
                    namelist.append(tag)

        namelist.sort()
        list_json = {"namelist": namelist}

        self.response.headers['Content-Type'] = 'application/json'
        list_json = json.dumps(list_json)
        self.response.write(list_json)
    def get(self):
        # receivedata=json.loads(self.request.body)

        # print receivedata
        # print self.request.body
        # username=receivedata["username"]

        streams=StreamModel.query().order(StreamModel.createTime).fetch()
        names=[]
        coverurls=[]
        for stream in streams:
            names.append(stream.name)
            coverurls.append(stream.coverpageURL)

        result={"streamcoverurls":coverurls, 'streamnames':names}
        jsonObj=json.dumps(result, sort_keys=True,indent=4, separators=(',', ': '))
        self.response.headers['Content-Type']="application/json"
        self.response.write(jsonObj)
    def get(self):
        global index
        returnURL = self.request.headers['Referer']
        stream_name = re.findall('%3D(.*)%3D%3D', self.request.url)[0]
        oldIndex = int(re.findall('%3D%3D(.*)', self.request.url)[0])
        #countView_query = CountViewModel.query(CountViewModel.name==stream_name).fetch()
        stream = StreamModel.query(StreamModel.name == stream_name).fetch()[0]

        #if stream.author == users.get_current_user():
        #    pass
        #else:
        # countView = countView_query[0]
        # self.response.write(countView.count)
        # countView.count = countView.count - 1
        # countView.total = countView.total - 1
        # countView.put()
        index = oldIndex + NUM_PICTURE_PER_STREAM
        if index >= stream.totalPicture:
            index = 0

        self.redirect(returnURL)
Example #22
0
    def get(self):
        self.response.write(VIEW_PAGE_TEMPLATE)
        stream_query = StreamModel.query().order(StreamModel.createTime)
        streams = stream_query.fetch()
        num = 0
        self.response.write('<table border="0" style="width:100%">')
        if len(streams) > 0:
            self.more = True
            for stream in streams:
                if num==0:
                    self.response.write("<tr>")

                self.response.write(STREAM_ENTRY_TEMPLATE % (stream.url, stream.coverpageURL, stream.name))

                if num==3:
                    self.response.write("</tr>")
                    num = 0
                else:
                    num += 1

        else:
            self.response.write("<tr><td>No streams are available</td></tr>")
        self.response.write('</table>')
Example #23
0
    def post(self):
        stream_name = self.request.get('streamname', DEFAULT_CREATE_STREAM_NAME)
        if (len(stream_name) == 0):
            stream_name = DEFAULT_CREATE_STREAM_NAME
        stream_tags = self.request.get('streamtags').split(',')
        stream_subscribers = self.request.get('subscribers').split(',')
        stream_message = self.request.get('context')
        stream_coverpageURL = self.request.get('url')

        stream_query = StreamModel.query(StreamModel.name == stream_name).fetch()
        if (len(stream_query)==0):
            countView = CountViewModel()
            countView.count = 0
            countView.total = 0
            countView.name = stream_name
            countView.put()
            stream = StreamModel()
            stream.name = stream_name
            stream.author = users.get_current_user()
            stream.authorName = users.get_current_user().nickname()
            stream.url = urllib.urlencode({'streamname': stream.name})
            stream.totalPicture = 0
            if (len(stream_subscribers)>0):
                for email in stream_subscribers:
                    if len(email)>0:
                        mail.send_mail(sender=users.get_current_user().email(), to=email,
                                       subject="Stream "+ stream_name + " is created.", body= stream_message )
                stream.subscribers = stream_subscribers
            if (len(stream_message)>0):
                stream.message = stream_message
            if(len(stream_tags)>0):
                stream.tag = stream_tags
            if (len(stream_coverpageURL)>0):
                stream.coverpageURL = stream_coverpageURL
            else:
                stream.coverpageURL = "http://static.independent.co.uk/s3fs-public/styles/story_large/public/thumbnails/image/2013/01/24/12/v2-cute-cat-picture.jpg"
            stream.put()
            self.redirect('/manage')
        else:
            self.redirect('/error')