def post(self): """Create a message from the api. Example:: { "username": "******", "message": "Something interesting", "picture_url": "http://avator.com/my_image.jpg", "url": "http://github.com/defunkt/github/commit/k20lkjs920lskjlskjjd1", "commit_hash": "k20lkjs920lskjlskjjd1", "project": "http://github.com/defunkt/github" }, """ form = self.parse_form() if not form.is_valid(): return self.respond_json(form.errors, status_code=400) message = Message.create_message(**form.cleaned_data) self.respond_json({'message': self.serialize(message)}, status_code=201)
def live(request): stats = Accumulator.get_histogram('global') total = sum(stats) message_future = Message.query().order(-Message.timestamp).fetch_async(30) # Julython live stuffs token_key = 'live_token:%s' % request.user.username token = memcache.get(token_key) if token is None: token = channel.create_channel(request.user.username) memcache.set(token_key, token, time=7000) message_models = message_future.get_result() m_list = [to_dict(m) for m in message_models] m_list.reverse() messages = json.dumps(m_list) return render_to_response('live/index.html', { 'token': token, 'messages': messages, 'total': total}, context_instance=RequestContext(request))
def live(request): stats = Accumulator.get_histogram('global') total = sum(stats) message_future = Message.query().order(-Message.timestamp).fetch_async(30) # Julython live stuffs token_key = 'live_token:%s' % request.user.username token = memcache.get(token_key) if token is None: token = channel.create_channel(request.user.username) memcache.set(token_key, token, time=7000) message_models = message_future.get_result() m_list = [to_dict(m) for m in message_models] m_list.reverse() messages = json.dumps(m_list) return render_to_response('live/index.html', { 'token': token, 'messages': messages, 'total': total }, context_instance=RequestContext(request))
def test_create_message(self): data = json.dumps(self.DATA) self.app.post('/api/v1/live', data) count = Message.query().count(10) self.assertEqual(count, 1)
def index(request): """Render the home page""" # For now we are just using hard coded sections #sections = cache.get('front_page') #if sections is None: # sections = Section.all().order('order').fetch(10) # cache.set('front_page', sections, 120) stats = [] total = 0 people = [] locations = [] projects = [] teams = [] messages = [] token = '' # this is only shown on authenticated page loads # to save on the overhead. if True: stats = Accumulator.get_histogram('global') total = sum(stats) location_future = Location.query().order(-Location.total).fetch_async( 15) people_future = User.query().order( -ndb.GenericProperty('total')).fetch_async(10) project_future = Project.query().order(-Project.total).fetch_async(10) team_future = Team.query().order(-Team.total).fetch_async(15) message_future = Message.query().order(-Message.timestamp).fetch_async( 30) # Julython live stuffs #token_key = 'live_token:%s' % request.user.username #token = memcache.get(token_key) #if token is None: #token = channel.create_channel(request.user.username) #memcache.set(token_key, token, time=7000) locations = location_future.get_result() people = people_future.get_result() projects = project_future.get_result() teams = team_future.get_result() message_models = message_future.get_result() m_list = [to_dict(m) for m in message_models] m_list.reverse() messages = json.dumps(m_list) ctx = Context({ 'sections': [], 'people': people, 'projects': projects, 'locations': locations, 'teams': teams, 'stats': json.dumps(stats), 'total': total, 'token': token, 'messages': messages, 'user': request.user, 'MEDIA_URL': settings.MEDIA_URL, 'STATIC_URL': settings.STATIC_URL }) return render_to_response('index.html', context_instance=ctx)
def index(request): """Render the home page""" # For now we are just using hard coded sections #sections = cache.get('front_page') #if sections is None: # sections = Section.all().order('order').fetch(10) # cache.set('front_page', sections, 120) stats = [] total = 0 people = [] locations = [] projects = [] teams = [] messages = [] token = '' # this is only shown on authenticated page loads # to save on the overhead. if True: stats = Accumulator.get_histogram('global') total = sum(stats) location_future = Location.query().order(-Location.total).fetch_async(15) people_future = User.query().order(-ndb.GenericProperty('total')).fetch_async(10) project_future = Project.query().order(-Project.total).fetch_async(10) team_future = Team.query().order(-Team.total).fetch_async(15) message_future = Message.query().order(-Message.timestamp).fetch_async(30) # Julython live stuffs #token_key = 'live_token:%s' % request.user.username #token = memcache.get(token_key) #if token is None: #token = channel.create_channel(request.user.username) #memcache.set(token_key, token, time=7000) locations = location_future.get_result() people = people_future.get_result() projects = project_future.get_result() teams = team_future.get_result() message_models = message_future.get_result() m_list = [to_dict(m) for m in message_models] m_list.reverse() messages = json.dumps(m_list) ctx = Context({ 'sections': [], 'people': people, 'projects': projects, 'locations': locations, 'teams': teams, 'stats': json.dumps(stats), 'total': total, 'token': token, 'messages': messages, 'user': request.user, 'MEDIA_URL': settings.MEDIA_URL, 'STATIC_URL': settings.STATIC_URL}) return render_to_response('index.html', context_instance=ctx)