mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-13 13:12:42 +00:00
Add easy way to do xkey based purging of a template
Since we can purge based on the md5 hash of a template name, expose this in the purge dialog so one doesn't have to manually calculate the hash to use it.
This commit is contained in:
@ -16,6 +16,7 @@ from datetime import date, datetime, timedelta
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
import hashlib
|
||||||
|
|
||||||
from pgweb.util.decorators import cache, nocache
|
from pgweb.util.decorators import cache, nocache
|
||||||
from pgweb.util.contexts import render_pgweb, get_nav_menu, PGWebContextProcessor
|
from pgweb.util.contexts import render_pgweb, get_nav_menu, PGWebContextProcessor
|
||||||
@ -471,19 +472,28 @@ def admin_purge(request):
|
|||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
url = request.POST['url']
|
url = request.POST['url']
|
||||||
expr = request.POST['expr']
|
expr = request.POST['expr']
|
||||||
|
template = request.POST['template']
|
||||||
xkey = request.POST['xkey']
|
xkey = request.POST['xkey']
|
||||||
l = len([_f for _f in [url, expr, xkey] if _f])
|
l = len([_f for _f in [url, expr, template, xkey] if _f])
|
||||||
if l == 0:
|
if l == 0:
|
||||||
# Nothing specified
|
# Nothing specified
|
||||||
return HttpResponseRedirect('.')
|
return HttpResponseRedirect('.')
|
||||||
elif l > 1:
|
elif l > 1:
|
||||||
messages.error(request, "Can only specify one of url, expression and xkey!")
|
messages.error(request, "Can only specify one of url, expression, template and xkey!")
|
||||||
return HttpResponseRedirect('.')
|
return HttpResponseRedirect('.')
|
||||||
|
|
||||||
if url:
|
if url:
|
||||||
varnish_purge(url)
|
varnish_purge(url)
|
||||||
elif expr:
|
elif expr:
|
||||||
varnish_purge_expr(expr)
|
varnish_purge_expr(expr)
|
||||||
|
elif template:
|
||||||
|
path = os.path.abspath(os.path.join(settings.PROJECT_ROOT, '../templates', template))
|
||||||
|
if not os.path.isfile(path):
|
||||||
|
messages.error(request, "Template {} does not exist!".format(template))
|
||||||
|
return HttpResponseRedirect('.')
|
||||||
|
# Calculate the xkey
|
||||||
|
xkey = "pgwt_{}".format(hashlib.md5(template.encode('ascii')).hexdigest())
|
||||||
|
varnish_purge_xkey(xkey)
|
||||||
else:
|
else:
|
||||||
varnish_purge_xkey(xkey)
|
varnish_purge_xkey(xkey)
|
||||||
|
|
||||||
|
@ -21,6 +21,10 @@
|
|||||||
<td>Full expression:</td>
|
<td>Full expression:</td>
|
||||||
<td><input type="text" name="expr"></td>
|
<td><input type="text" name="expr"></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Template:</td>
|
||||||
|
<td><input type="text" name="template"></td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>XKey:</td>
|
<td>XKey:</td>
|
||||||
<td><input type="text" name="xkey"></td>
|
<td><input type="text" name="xkey"></td>
|
||||||
|
Reference in New Issue
Block a user