Esempio n. 1
0
def mainPage(request):
    session = get_current_session()
    access_token_key = session['access_token_key']
    access_token_secret = session['access_token_secret']
    oauth_verifier = request.GET.get('oauth_verifier', '')
    get_absolute_path(request)
    if not access_token_key:
        #params['test'] = reverse('sinaweibo.views.login', args=[], kwargs={})#, current_app=context.current_app)        
        login_url = reverse('sinaweibo.views.login', args=[], kwargs={})
        #return shortcuts.render_to_response('test.html', params)
        return http.HttpResponseRedirect(login_url)
    else:
        auth = OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
        auth.setToken(access_token_key, access_token_secret)
        api = API(auth)
        
        #myself = api.get_user(id=1894001933)
        #screen_name = myself. __getattribute__('screen_name')
        myweibo = []
        myweibo_obj = api.user_timeline(count=20, page=1)
        for weibo in myweibo_obj:
            myweibo.append({'text': weibo.text, 
                            'created_at': weibo.created_at, 
                            'retweeted_status': hasattr(weibo, 'retweeted_status') and weibo.retweeted_status or None,
                            'source': weibo.source})
        wrapper__at(myweibo)
        params = {}
        
        params['user'] = api.verify_credentials()
        params['result'] = myweibo
        template = get_template_uri(appContext, 'weibo.html')
        return shortcuts.render_to_response(template, params)
Esempio n. 2
0
def respond(request, user, template, params=None):
  """Helper to render a response, passing standard stuff to the response.

  Args:
    request: The request object.
    user: The User object representing the current user; or None if nobody
      is logged in.
    template: The template name; '.html' is appended automatically.
    params: A dict giving the template parameters; modified in-place.

  Returns:
    Whatever render_to_response(template, params) returns.

  Raises:
    Whatever render_to_response(template, params) raises.
  """
  if params is None:
    params = {}
  if user:
    params['user'] = user
    params['sign_out'] = users.create_logout_url('/')
    params['is_admin'] = (users.is_current_user_admin() and
                          'Dev' in os.getenv('SERVER_SOFTWARE'))
  else:
    params['sign_in'] = users.create_login_url(request.path)
  return shortcuts.render_to_response(get_template_uri(appContext, template), params)
Esempio n. 3
0
    def render2_bak(self, template_file, params={}):
        """
        Helper method to render the appropriate template
        """

        params.update(self.template_vals)
        template = get_template_uri(self.app_context, template_file)
        return shortcuts.render_to_response(
            template_name=template, dictionary=params, context_instance=RequestContext(self.request)
        )
Esempio n. 4
0
 def render(self, template_file, params={}, mimetype=None, status=None, content_type=None):
     """
     Helper method to render the appropriate template
     """
     params.update(self.template_vals)
     template = get_template_uri(self.app_context, template_file)
     t = loader.get_template(template)
     c = RequestContext(self.request, params)
     self.response.write(t.render(c))
     if mimetype:
         content_type = mimetype
     if content_type:
         self.response["Content-Type"] = content_type
Esempio n. 5
0
def index(request):
    params = get_extra_context(appContext)
    template = get_template_uri(appContext, 'home.html')
    return shortcuts.render_to_response(template, params)
Esempio n. 6
0
 def render(self, template, params):
     params.update(self.template_vals)
     template = get_template_uri(self.app_context, 'index.html')
     return shortcuts.render_to_response(template_name = template, dictionary = params,
                                         context_instance = RequestContext(self.request))