- Author:
- bl4th3rsk1t3
- Posted:
- June 1, 2009
- Language:
- Python
- Version:
- 1.0
- Score:
- 1 (after 1 ratings)
Is an updated way of splitting contents for a token, it does the split, but fixes the list..
EX:
From a tag call like this: {% partial "partials/template.html" %}
usually you get: ['partial','"partials/template.html"']
notice the " double quotes
fixes it with: ['partial','partials/template.html']
takes out the " quotes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | def split_contents2(token):
"""
Is an updated way of splitting contents for a token,
it does the split, but fixes the list..
EX:
From a tag call like this: {% partial "partials/template.html" %}
usually you get: ['partial','"partials/template.html"'] (notice the " double quotes)
fixes it with: ['partial','partials/template.html'] (takes out the " quotes)
"""
import types,re
value=token.split_contents()
newvalues=[]
for val in value:
if (type(val)==types.UnicodeType or isinstance(val,str)) and val[0]=='"' and val[-1]=='"':
val=re.sub(r'^\"','',val)
val=re.sub(r'\"$','',val)
newvalues.append(val)
return newvalues
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
Please login first before commenting.