コード例 #1
0
ファイル: admin.py プロジェクト: dudarev/osmtweet
    def get(self,action=None):
        self.response.out.write('Admin page<br/><br/>')
        message = self.request.get("message")
        if message:
            self.response.out.write('<font color="red">'+message+'</font><br/><br/>')
        self.response.out.write('<a href="/admin/load">Load and parse changesets</a> (takes time)<br/>')
        self.response.out.write('<a href="/admin/prepare">Prepare to tweet</a><br/>')
        self.response.out.write('<a href="/admin/tweet">Tweet</a><br/><br/>')
        self.response.out.write('<a href="/admin/update_counts">Update counts</a><br/><br/>')
        self.response.out.write('<a href="/admin/update_description">Update description</a><br/><br/>')
        self.response.out.write('<a href="http://localhost:8080/_ah/admin/datastore">Localhost datastore</a><br/><br/>')
        self.response.out.write('<a href="/">Home</a><br/><br/>')

        user = users.get_current_user(self)
        if user:
            login_logout_link = "%s<br/><a href=\"%s\">Logout</a>" % (user, users.create_logout_url(self, "/"))
        else:
            login_logout_link = "<a href=\"%s\">Login with Twitter</a>" % users.create_login_url(self, "/")
        self.response.out.write(login_logout_link)

        if action:
            if action == 'load':
                self.LoadHandler()
            if action == 'prepare':
                self.PrepareHandler()
            if action == 'tweet':
                self.TweetHandler()
            if action == 'update_counts':
                self.UpdateCountsHandler()
            if action == 'update_description':
                self.UpdateDescription()
コード例 #2
0
 def get(self):
     template = env.get_template('index.html')
     user = users.get_current_user()
     if user:
         template_vars = {'logstatus':"Log Out",
                          'logoutlink': users.create_logout_url('/')
                          }
         if UserStorage.query(UserStorage.email == user.email()).get().setup==True:
             template_vars['address'] = UserStorage.query(UserStorage.email == user.email()).get().address
         self.response.write(template.render(template_vars))
     else:
         template_vars = {'logstatus': "Log In",
                          'logoutlink': users.create_login_url('/login')}
         self.response.write(template.render(template_vars))
コード例 #3
0
ファイル: main.py プロジェクト: dudarev/twitterengine
  def get(self):
    config = get_config()

    # Tweets
    if self.sort_by_votes:
        count = Tweet.all().filter("votes_count >",0).count(1000)
    else:
        count = Tweet.all().count(1000)
    page = int(self.request.get('page', 1))
    prev_page = page-1
    next_page = page+1
    show_prev_page = (page>1)
    show_next_page = (page*20<count)
    tweets = []
    if self.sort_by_votes:
        query = Tweet.all().filter("votes_count >",0).order("-votes_count").order("-id").fetch(20, (page-1)*20)
    else:
        query = Tweet.all().order("-id").fetch(20, (page-1)*20)
    for tweet in query:
      tweet.status = twitter.Status(id=tweet.id, created_at=tweet.created_at)
      tweet.text = unescape(tweet.text)
      tweet.source = unescape(tweet.source)
      tweets.append(tweet)

    # User cloud
    cloud_tweets = Tweet.all().order('-id').fetch(300)
    cloud_items = {}
    cloud = []
    max = 0
    for tw in cloud_tweets:
      cloud_items[tw.from_user] = 0
    for tw in cloud_tweets:
      cloud_items[tw.from_user] = cloud_items[tw.from_user]+1
      if cloud_items[tw.from_user]>max: max = cloud_items[tw.from_user]
    for k in cloud_items:
      cloud.append({'name':k, 'lower_name':k.lower(), 'count':cloud_items[k], 'html':'<a href="http://twitter.com/%s" style="font-size:%spx">%s</a>' % (k, (9 + 16*(1.0*cloud_items[k]/max)), k)})

    user = users.get_current_user(self)
    if user:
      login_logout_link = "<strong>%s</strong> | <a href=\"%s\">Logout</a>" % (user,users.create_logout_url(self,"/"))
    else:
      login_logout_link = "<a href=\"%s\">Login</a>" % users.create_login_url(self,"/")
    nav_link = login_logout_link
      
    path = os.path.join(os.path.dirname(__file__), 'index.html')
    self.response.out.write(template.render(path, locals()))
コード例 #4
0
 def post(self):
     user = users.get_current_user()
     person = UserStorage.query(UserStorage.email == users.get_current_user().email()).get()
     person.id = self.request.get('name')
     address = self.request.get('user_LatLocation')
     person.address = address
     address = address.replace(" ", "+")
     content = urllib2.urlopen("https://maps.googleapis.com/maps/api/geocode/json?address=%s&key=AIzaSyADJhWkgPHBu3SXXrtqnJNmdmz7Xu_mhRc" % address).read()
     content_dict = json.loads(content)
     person.LatLocation = float(content_dict['results'][0]['geometry']['location']['lat'])
     person.LongLocation = float(content_dict['results'][0]['geometry']['location']['lng'])
     person.setup = True
     person.put()
     template = env.get_template('index.html')
     if user:
         template_vars = {'logstatus':"Log Out",
                          'logoutlink': users.create_logout_url('/'),
                          'address':person.address}
         self.response.write(template.render(template_vars))
     else:
         template_vars = {'logstatus': "Log In",
                          'logoutlink': users.create_login_url('/login')}
         self.response.write(template.render(template_vars))
コード例 #5
0
    def Render(self, template_name, extra_values={}):
        parsed = urlparse.urlparse(self.request.uri)
        request_url_without_path = parsed[0] + '://' + parsed[1]
        request_url_without_params = request_url_without_path + parsed[2]

        self.response.headers.add_header('X-XRDS-Location',
                                         request_url_without_path + '/xrds')

        values = {
            'request': self.request,
            'request_url_without_path': request_url_without_path,
            'request_url_without_params': request_url_without_params,
            'user': users.get_current_user(),
            'login_url': users.create_login_url(self.request.uri),
            'register_url': 'signup',
            'logout_url': users.create_logout_url('/'),
            'debug': self.request.get('deb'),
        }
        values.update(extra_values)
        cwd = os.path.dirname(__file__)
        path = os.path.join(cwd, 'templates', template_name + '.html')
        logging.debug(path)
        self.response.out.write(template.render(path, values))
コード例 #6
0
  def Render(self, template_name, extra_values={}):
    parsed = urlparse.urlparse(self.request.uri)
    request_url_without_path = parsed[0] + '://' + parsed[1]
    request_url_without_params = request_url_without_path + parsed[2]

    self.response.headers.add_header(
      'X-XRDS-Location', request_url_without_path + '/xrds')

    values = {
      'request': self.request,
      'request_url_without_path': request_url_without_path,
      'request_url_without_params': request_url_without_params,
      'user': users.get_current_user(),
      'login_url': users.create_login_url(self.request.uri),
      'register_url':  'signup',
      'logout_url': users.create_logout_url('/'),
      'debug': self.request.get('deb'),
    }
    values.update(extra_values)
    cwd = os.path.dirname(__file__)
    path = os.path.join(cwd, 'templates', template_name + '.html')
    logging.debug(path)
    self.response.out.write(template.render(path, values))