def follow_form(parser, token): """ Renders the following form. This can optionally take a success url, an extra class for the follow button, and a tooltip class for tooltip position, or complety override the default btn + btn-primary behaviour Usage ('next' is optional):: {% follow_form user object %} {% follow_form user object next="" base_class="btn" success_class="btn-primary" tooltip_class="tooltip-top" %} """ bits = token.split_contents() if len(bits) < 3: raise TemplateSyntaxError("'%s' takes at least two arguments" " (user and object to follow)" % bits[0]) tag_name = bits[0] user = bits[1] obj = bits[2] bits = bits[3:] args, kwargs, asvar = get_node_extra_arguments(parser, bits, tag_name, 2) return FollowFormNode(user, obj, args, kwargs, asvar)
def tags_display(parser, token): """ Renders the tags contained in a TaggableManager using tag_display template. Can add a max number of tags displayed condition, a quote type (single or double), an extra class parameter for the tag template, a separator displayed between tags Usage:: {% tags_display tags %} {% tags_display tags max_nb=None quote_type="double" sep=" " extra_class="" %} {% tags_display tags 4 sep=" " as tags_html %} """ bits = token.split_contents() if len(bits) < 2: raise TemplateSyntaxError("'%s' takes at least 1 arguments." % bits[0]) tag_name = bits[0] tags = bits[1] bits = bits[2:] args, kwargs, asvar = get_node_extra_arguments(parser, bits, tag_name, 4) return TagsDisplayNode(tags, args, kwargs, asvar)
def edit_buttons(parser, token): """ Renders two buttons (edit and delete), using _edit_buttons template, given a user (client side) and an editable object. Can add redirection paths after success. Can store the html in a variable. Usage:: {% edit_buttons user obj %} {% edit_buttons user obj edit_next="" delete_next="" %} {% edit_buttons user obj "/content" delete_next="/" %} {% edit_buttons user obj edit_next=var as html_var %} """ bits = token.split_contents() if len(bits) < 3: raise TemplateSyntaxError("'%s' takes at least 2 arguments." % bits[0]) tag_name = bits[0] user = bits[1] obj = bits[2] bits = bits[3:] args, kwargs, asvar = get_node_extra_arguments(parser, bits, tag_name, 2) return EditButtonsNode(user, obj, args, kwargs, asvar)
def price(parser, token): """ Return formatted currency value. This is a way to define links that aren't tied to a particular URL configuration:: {% price value currency language_code %} The first argument is a decimal number. Other arguments are space-separated values. 'currency' is a affiliation.CURRENCIES choice associated with the price value. 'language_code' is the language convention used for the display. Don't mix positional and keyword arguments. 'currency' and 'language_code' are not mandatory. 'currency' defaults to euro while 'language_code' defaults to environment variable 'LC_NUMERIC'. For example:: {% price value currency language_code %} with value = Decimal("101.34") currency = AffiliationItemBase.dollar language_code = 'fr' will give u'101,34\xa0$US' """ bits = token.split_contents() if len(bits) < 2: raise TemplateSyntaxError("'%s' takes at least one argument" " (price to display)" % bits[0]) tag_name = bits[0] value = bits[1] bits = bits[2:] args, kwargs, asvar = get_node_extra_arguments(parser, bits, tag_name, 2) return PriceNode(value, args, kwargs, asvar)
def tag_display(parser, token): """ Renders a tag using tag_display template. Can add a quote type (single or double), and an extra class parameter for the tag template. Can store the html in a variable. Usage:: {% tag_display tag %} {% tag_display tag quote_type="double" extra_class="" %} {% tag_display tag "simple" extra_class="" as tag_html %} """ bits = token.split_contents() if len(bits) < 2: raise TemplateSyntaxError("'%s' takes at least 1 arguments." % bits[0]) tag_name = bits[0] tag = bits[1] bits = bits[2:] args, kwargs, asvar = get_node_extra_arguments(parser, bits, tag_name, 2) return TagDisplayNode(tag, args, kwargs, asvar)
def object_display(parser, token): """ Renders the item link with or without its popover, depending on display. Can add a css defined color and paste html in a variable. Usage:: {% object_display object display %} {% object_display object display color="blue" %} {% object_display object "list" "black" as user_popover %} """ bits = token.split_contents() if len(bits) < 3: raise TemplateSyntaxError("'%s' takes at least 2 arguments." % bits[0]) tag_name = bits[0] obj = bits[1] display = bits[2] bits = bits[3:] args, kwargs, asvar = get_node_extra_arguments(parser, bits, tag_name, 1) return ObjectDisplayNode(obj, display, args, kwargs, asvar)
def get_absolute_uri(parser, token): """ Returns the full uri of an object. Value can be pasted in var. Syntax:: {% get_absolute_uri object request %} Example:: {% get_absolute_uri answer request as my_uri %} """ bits = token.split_contents() if len(bits) != 3: raise TemplateSyntaxError("'%s' takes 2 arguments." % bits[0]) tag_name = bits[0] obj = bits[1] request = bits[2] bits = bits[3:] args, kwargs, asvar = get_node_extra_arguments(parser, bits, tag_name, 0) return URINode(obj, request, args, kwargs, asvar)
def vote_form(parser, token): """ Renders the vote form. Can add redirection paths after success. Can store the html in a variable. Usage:: {% vote_form object vote %} {% vote_form object vote next %} {% vote_form object vote "/" as form %} """ bits = token.split_contents() if len(bits) < 2: raise TemplateSyntaxError("'%s' takes at least 2 arguments." % bits[0]) tag_name = bits[0] obj = bits[1] vote = bits[2] bits = bits[3:] args, kwargs, asvar = get_node_extra_arguments(parser, bits, tag_name, 1) return VoteFormNode(obj, vote, args, kwargs, asvar)
def content_info(parser, token): """ Displays content creation related info: author, creation date... Usage ('pic_size' is optional):: {% content_info content display %} {% content_info content display pic_size %} where display can be: "signature", "signature-author", "signature-pic" "header" """ bits = token.split_contents() if len(bits) < 2: raise TemplateSyntaxError("'%s' takes at least 2 arguments." % bits[0]) tag_name = bits[0] content = bits[1] display = bits[2] bits = bits[3:] args, kwargs, asvar = get_node_extra_arguments(parser, bits, tag_name, 1) return ContentInfoNode(content, display, args, kwargs, asvar)
def source_display(parser, token): """ Renders the sources of a content object whether it be one or several products and/or one or several tags. Can add a separator (default is 'text') and paste html in a variable. Usage:: {% source_display content display %} {% source_display content "list" as source %} {% source_display content "list" sep="," as source %} """ bits = token.split_contents() if len(bits) < 3: raise TemplateSyntaxError("'%s' takes at least 2 arguments." % bits[0]) tag_name = bits[0] obj = bits[1] display = bits[2] bits = bits[3:] args, kwargs, asvar = get_node_extra_arguments(parser, bits, tag_name, 1) return SourceDisplayNode(obj, display, args, kwargs, asvar)