UPD: improved tests.
This commit is contained in:
@@ -8,16 +8,23 @@ from django.views import generic
|
||||
|
||||
class RootView(generic.TemplateView):
|
||||
template_name = 'base/root.html'
|
||||
_default_color_hex = '47825b'
|
||||
|
||||
def _get_color_hex(self, hostname=None):
|
||||
color_hex = self._default_color_hex
|
||||
if hostname:
|
||||
buf = hostname
|
||||
buf = re.sub('[-.]', '', buf)
|
||||
buf = buf[:6].lower()
|
||||
if re.match('[0-9a-f]{6}', buf):
|
||||
color_hex = buf
|
||||
return color_hex
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
if 'hostname' not in kwargs:
|
||||
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
|
||||
kwargs['color_hex'] = self._get_color_hex(kwargs['hostname'])
|
||||
if 'time' not in kwargs:
|
||||
kwargs['time'] = timezone.now()
|
||||
return super(RootView, self).get_context_data(**kwargs)
|
||||
|
||||
Reference in New Issue
Block a user