Ejemplo n.º 1
0
def form(parser, token):
    p = TokenParser(token.contents)
    args = []
    while p.more():
        args.append(p.value())
    body = parser.parse(('endform',))
    parser.delete_first_token()
    return FormNode(body, *args)
Ejemplo n.º 2
0
def get_comment_list(parser, token):
  """
  Gets comments for the given params and populates the template context with a
  special comment_package variable, whose name is defined by the ``as``
  clause.

  Syntax::

      {% get_comment_list for app_label.model context_var_containing_obj_id as varname (reversed) %}

  Example usage::

      {% get_comment_list for lcom.eventtimes event.id as comment_list %}

  To get a list of comments in reverse order -- that is, most recent first --
  pass ``reversed`` as the last param.
  """
  tokenparser = TokenParser(token.contents)
  if tokenparser.tag() != 'for':
      raise template.TemplateSyntaxError, "'get_comment_list' requires 'for' as the first parameter"
  (app_label, model) = tokenparser.tag().split('.')
  obj_id_lookup_var = tokenparser.tag()
  if tokenparser.tag() != 'as':
      raise template.TemplateSyntaxError, "'get_comment_list' requires 'as' before the variable name to set"
  var_name = tokenparser.tag()
  return CommentListNode(app_label, model, obj_id_lookup_var, var_name)
Ejemplo n.º 3
0
def get_comment_form(parser, token):
  tokenparser = TokenParser(token.contents)
  if tokenparser.tag() != 'for':
      raise template.TemplateSyntaxError, "'get_comment_form' requires 'for' as the first parameter"
  (app_label, model) = tokenparser.tag().split('.')
  obj_id_lookup_var = tokenparser.tag()
  
  if tokenparser.tag() != 'user':
      raise template.TemplateSyntaxError, "'get_comment_form' requires 'user'"
  user = tokenparser.tag()
  
  return CommentFormNode(app_label, model, obj_id_lookup_var, user)
Ejemplo n.º 4
0
    def test_token_parsing(self):
        # Tests for TokenParser behavior in the face of quoted strings with
        # spaces.

        p = TokenParser("tag thevar|filter sometag")
        self.assertEqual(p.tagname, "tag")
        self.assertEqual(p.value(), "thevar|filter")
        self.assertTrue(p.more())
        self.assertEqual(p.tag(), "sometag")
        self.assertFalse(p.more())

        p = TokenParser('tag "a value"|filter sometag')
        self.assertEqual(p.tagname, "tag")
        self.assertEqual(p.value(), '"a value"|filter')
        self.assertTrue(p.more())
        self.assertEqual(p.tag(), "sometag")
        self.assertFalse(p.more())

        p = TokenParser("tag 'a value'|filter sometag")
        self.assertEqual(p.tagname, "tag")
        self.assertEqual(p.value(), "'a value'|filter")
        self.assertTrue(p.more())
        self.assertEqual(p.tag(), "sometag")
        self.assertFalse(p.more())
Ejemplo n.º 5
0
    def test_token_parsing(self):
        # Tests for TokenParser behavior in the face of quoted strings with
        # spaces.

        p = TokenParser("tag thevar|filter sometag")
        self.assertEqual(p.tagname, "tag")
        self.assertEqual(p.value(), "thevar|filter")
        self.assertTrue(p.more())
        self.assertEqual(p.tag(), "sometag")
        self.assertFalse(p.more())

        p = TokenParser('tag "a value"|filter sometag')
        self.assertEqual(p.tagname, "tag")
        self.assertEqual(p.value(), '"a value"|filter')
        self.assertTrue(p.more())
        self.assertEqual(p.tag(), "sometag")
        self.assertFalse(p.more())

        p = TokenParser("tag 'a value'|filter sometag")
        self.assertEqual(p.tagname, "tag")
        self.assertEqual(p.value(), "'a value'|filter")
        self.assertTrue(p.more())
        self.assertEqual(p.tag(), "sometag")
        self.assertFalse(p.more())
Ejemplo n.º 6
0
def textarea(parser, token):
    p = TokenParser(token.contents)
    args = [p.value()]
    while p.more():
        args.append(p.value())
    return TextareaNode(*args)
Ejemplo n.º 7
0
def input_field(parser, token):
    p = TokenParser(token.contents)
    args = [p.value()]
    while p.more():
        args.append(p.value())
    return InputFieldNode(*args)