Exemplo n.º 1
0
  def get(self):
    user, template_values = snipglobals.initialize_user(self.request,
                                                        self.response)
    snippage, key = self.get_snippage(user, template_values)
    if not snippage:
      return
    template_values['is_owner'] = user and user == snippage.owner
    
    http_host = os.environ['HTTP_HOST']
    if http_host == 'localhost:8080':  # this is needed for local development.
      inc_host = http_host
    else:
      inc_host = 'hosted.%s' % http_host
    
    if not users.is_current_user_admin():
      db.run_in_transaction(self.increment_views, key)
      snippage.views += 1
    elif user == snippage.owner:  # admin, but looking at its own pages.
      db.run_in_transaction(self.increment_views, key)
      snippage.views += 1
    
    template_values.update({
      'error': False,
      'snippage': vo.SnipPageVO(snippage),
      'inc_host': inc_host,

      'title_img': '/view_icon.png',
      'title': snippage.title,
      'fliplinks': ['my', 'public'],
    })    
    path = os.path.join(os.path.dirname(__file__), '../../templates/view.html')
    self.response.out.write(template.render(path, template_values))
Exemplo n.º 2
0
  def get(self):
    user, template_values = snipglobals.initialize_user(self.request,
                                                        self.response)
    assert users.is_current_user_admin()
    email = self.request.get('email')
    if not email:
      template_values.update({
        'snippages': None,
        'title': 'Inspect Snippets'
      })
    else:
      order, offset, limit = self.get_pagination('-created')
      snippages, more, more_offset = self.get_user_snippets(
        email, order, offset, limit)    
      template_values.update({
        'snippages': snippages,
        'prev': offset > 0,
        'prev_offset': max(offset - limit, 0),
        'more': more,
        'more_offset': more_offset,
        'limit': limit,
        'order': order,
        'extra_params': '&email=%s' % email,

        'title': '%s\'s Snippets' % email,
      })
    template_values.update({
      'fliplinks': ['public', 'my'],
      'email': email,
    })
    path = os.path.join(os.path.dirname(__file__), '../../templates/user.html')
    self.response.out.write(template.render(path, template_values))
Exemplo n.º 3
0
    def get(self):
        user, template_values = snipglobals.initialize_user(self.request, self.response)
        if not user:
            self.redirect(users.create_login_url(self.request.uri))
            return

        order, offset, limit = self.get_pagination("-created")
        snippages, more, more_offset = self.get_private_snippets(order, offset, limit)

        template_values.update(
            {
                "snippages": snippages,
                "prev": offset > 0,
                "prev_offset": max(offset - limit, 0),
                "more": more,
                "more_offset": more_offset,
                "limit": limit,
                "order": order,
                "title_img": "/my_icon_small.png",
                "title": "Your Snippets",
                "fliplinks": ["public"],
            }
        )
        path = os.path.join(os.path.dirname(__file__), "../../templates/my.html")
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 4
0
 def _respond_with_error(self, user_message):
   _, template_values = snipglobals.initialize_user(
     self.request, self.response, generate_xsrf=False, propagate_cookies=False)
   template_values.update({
     'error': user_message,
     'title': 'Error!',
   })
   path = os.path.join(os.path.dirname(__file__), self._error_template_file)
   self.response.out.write(template.render(path, template_values))
Exemplo n.º 5
0
 def render_page(self, html_page, title, fliplinks=None):
   user, template_values = snipglobals.initialize_user(self.request,
                                                       self.response)      
   template_values['title'] = title
   if fliplinks is None:
     template_values['fliplinks'] = ['public']
   else:
     template_values['fliplinks'] = fliplinks
   path = os.path.join(os.path.dirname(__file__), '../../templates/%s' % html_page)
   self.response.out.write(template.render(path, template_values))
Exemplo n.º 6
0
 def get(self):
   self.set_error_template_file('../../templates/iframe.html')
   user, template_values = snipglobals.initialize_user(
       self.request, self.response, generate_xsrf=False)
   snippage, key = self.get_snippage(user, template_values)
   if not snippage:
     return
     
   template_values.update({
     'error': False,
     'snippage': vo.SnipPageVO(snippage),
     'parent_host': os.environ['HTTP_HOST'].replace('hosted.', '', 1)
   })
   path = os.path.join(os.path.dirname(__file__), '../../templates/iframe.html')
   self.response.out.write(template.render(path, template_values))
Exemplo n.º 7
0
    def get(self):
        user, template_values = snipglobals.initialize_user(self.request, self.response)
        order, offset, limit = self.get_pagination("-views")
        snippages, more, more_offset = self.get_public_snippets(order, offset, limit)

        template_values.update(
            {
                "snippages": snippages,
                "prev": offset > 0,
                "prev_offset": max(offset - limit, 0),
                "more": more,
                "more_offset": more_offset,
                "limit": limit,
                "order": order,
                "title_img": "/public_icon_small.png",
                "title": "Public Snippets",
                "fliplinks": ["my", "login"],
            }
        )
        path = os.path.join(os.path.dirname(__file__), "../../templates/public.html")
        self.response.out.write(template.render(path, template_values))
Exemplo n.º 8
0
 def get(self):
   user, template_values = snipglobals.initialize_user(self.request,
                                                       self.response)        
   path = os.path.join(os.path.dirname(__file__), '../templates/test.html')
   self.response.out.write(template.render(path, template_values))