regluit/notebooks/PR_483_Url_from_future.ipynb

102 lines
2.4 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from sh import (grep, glob)\n",
"\n",
"template_files = glob(\"/Users/raymondyee/C/src/Gluejar/regluit/*/templates/*.html\")\n",
"\n",
"# check that templates that don't \"load url from future\" also don't have any references to url templates.\n",
"\n",
"s = grep(\"-L\" , \"{% load url from future %}\", template_files)\n",
"\n",
"templates_wo_load_future = set(s.strip().split(\"\\n\"))\n",
"\n",
"s = grep(\"-L\" , \"{% url\", template_files)\n",
"\n",
"templates_wo_url = set(s.strip().split(\"\\n\"))\n",
"\n",
"templates_wo_load_future == templates_wo_url"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# now check that all url references are quoted\n",
"\n",
"from sh import (grep, glob)\n",
"import re\n",
"\n",
"template_files = glob(\"/Users/raymondyee/C/src/Gluejar/regluit/*/templates/*.html\")\n",
"\n",
"s = grep(\"-l\", \"{% url\", template_files)\n",
"files = s.strip().split(\"\\n\")\n",
"\n",
"for file in files:\n",
" f = open(files[0], 'rb')\n",
" data = f.read()\n",
" text = data.decode('utf-8')\n",
" \n",
" groups = re.findall(\"\\{%\\s+url\\\\s+([^\\s]*).*}\",text)\n",
" for g in groups:\n",
" if not re.search(r\"\"\"^(.).*\\1$\"\"\", g):\n",
" # print if not quoted\n",
" print(\"not quoted\", g)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.9"
}
},
"nbformat": 4,
"nbformat_minor": 0
}