def postman_order_by(parser, token): """ Compose a query string to ask for a specific ordering in messages list. The unique argument must be one of the keywords of a set defined in the model. Example:: <a href="{% postman_order_by subject %}">...</a> """ try: tag_name, field_name = token.split_contents() field_code = ORDER_BY_MAPPER[field_name.lower()] except ValueError: raise TemplateSyntaxError("'{0}' tag requires a single argument".format(token.contents.split()[0])) except KeyError: raise TemplateSyntaxError( "'{0}' is not a valid argument to '{1}' tag." " Must be one of: {2}".format(field_name, tag_name, ORDER_BY_MAPPER.keys())) return OrderByNode(field_code)