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): 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 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 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 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')
def get(self): countView = CountViewModel.query().fetch() if len(countView)>0: for count in countView: count.count = 0 count.put()