UPD: added more fun to the root view.

This commit is contained in:
2019-04-12 22:36:05 +02:00
parent 892ed029f6
commit 166fdd9133
2 changed files with 20 additions and 1 deletions

View File

@@ -8,7 +8,19 @@
my name is {{ hostname|capfirst }} and I am your server right now. my name is {{ hostname|capfirst }} and I am your server right now.
</p> </p>
<p> <p>
By the way, my clock says {{ time|time:'TIME_FORMAT'|default:'nothing' }}. Did I say now?<br />
My clock says {{ time|time:'TIME_FORMAT'|default:'nothing' }},
{% if time %}
and we are talking about the {{ time|time:'e' }} timezone.
{% else %}
and this is no good.
{% endif %}
</p>
<p>
{% with color_hex=color_hex|default:'47825b' %}
By the way, this is my favorite color:
<span class="badge" style="background-color: #{{ color_hex }};">&nbsp; #{{ color_hex }} &nbsp;</span>
{% endwith %}
</p> </p>
</div> </div>
</div> </div>

View File

@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import re
import socket import socket
from django.utils import timezone from django.utils import timezone
from django.views import generic from django.views import generic
@@ -11,6 +12,12 @@ class RootView(generic.TemplateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
if 'hostname' not in kwargs: if 'hostname' not in kwargs:
kwargs['hostname'] = socket.gethostname() kwargs['hostname'] = socket.gethostname()
if 'color_hex' not in kwargs:
buf = kwargs['hostname']
buf = re.sub('[-.]', '', buf)
buf = buf[:6].lower()
if re.match('[0-9a-f]{6}', buf):
kwargs['color_hex'] = buf
if 'time' not in kwargs: if 'time' not in kwargs:
kwargs['time'] = timezone.now() kwargs['time'] = timezone.now()
return super(RootView, self).get_context_data(**kwargs) return super(RootView, self).get_context_data(**kwargs)