Improve Template hash calculation

Calculate the Template hash from the content actually returned.
Remove the newlines as these are irrelevant for HTML.

Signed-off-by: Roberto Rosario <Roberto.Rosario.Gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2019-01-09 12:38:38 -04:00
parent 58e38c1ff9
commit 8f24b2ed80

View File

@@ -301,7 +301,9 @@ class Template(object):
self.__class__._registry[name] = self
def get_absolute_url(self):
return reverse('rest_api:template-detail', args=(self.name,))
return reverse(
viewname='rest_api:template-detail', kwargs={'template_pk': self.name}
)
def render(self, request):
context = {
@@ -313,8 +315,10 @@ class Template(object):
context=context,
).render()
self.html = result.rendered_content
self.hex_hash = hashlib.sha256(result.content).hexdigest()
content = result.rendered_content.replace('\n', '')
self.html = content
self.hex_hash = hashlib.sha256(content).hexdigest()
return self