blob: 56c820a912e8f543e33247bfde141ae02fa2a884 [file] [log] [blame]
Matteo Scandolo94042de2016-02-29 15:46:55 -08001from django.http import HttpResponse
2from django.views.generic import TemplateView, View
3from django import template
4from django.shortcuts import render
5from core.models import *
6import json
7import os
8import time
9import tempfile
10
11
12class ServiceGridView(TemplateView):
13 head_template = r"""{% extends "admin/dashboard/dashboard_base.html" %}
14 {% load admin_static %}
15 {% block content %}
16 """
17
18 # I hate myself for doing this
19 script = """
20 <script type="text/javascript">
21 $(window).ready(function(){
22 $('.kind-container').on('click', function(){
23 $(this).toggleClass('active')
24 });
25 })
26 </script>
27 """
28
29 tail_template = r"{% endblock %}"
30
31 def get(self, request, name="root", *args, **kwargs):
32 head_template = self.head_template
33 tail_template = self.tail_template
34 html = self.script
35 html = html + '<div class="col-xs-12 m-cord">'
36
37 # Select the unique kind of services
38 for kind in Service.objects.values('kind').distinct():
39
40 html = html + '<div class="kind-container row">'
41 html = html + '<div class="col-xs-12"><h2>%s</h2></div>' % (kind["kind"])
42
43 # for each kind select services
44 for service in Service.objects.filter(kind=kind["kind"]):
45 image_url = service.icon_url
46 if (not image_url):
Matteo Scandoloc9f04472016-02-29 17:12:49 -080047 image_url = "/static/mCordServices/service_common.png"
teone8ef088b2016-03-03 10:45:45 -080048 #if service.view_url.startswith("http"):
49 # target = 'target="_blank"'
50 #else:
51 # target = ''
52 target = ''
Matteo Scandolo2d483092016-02-29 16:42:57 -080053
Matteo Scandolo94042de2016-02-29 15:46:55 -080054 html = html + '<div class="col-xs-4 text-center service-container">'
Matteo Scandolo2d483092016-02-29 16:42:57 -080055 html = html + '<a href="%s" %s>' % (service.view_url, target)
Matteo Scandolo94042de2016-02-29 15:46:55 -080056 html = html + '<img class="img-responsive" src="%s">' % (image_url)
57 html = html + "<h4>" + service.name + "</h4>"
58 html = html + '</a>'
59 html = html + "</div>"
60
61 html = html + "</div>"
62
63 html = html + "</div>"
64 t = template.Template(head_template + html + self.tail_template)
65
66 response_kwargs = {}
67 response_kwargs.setdefault('content_type', self.content_type)
68 return self.response_class(
69 request=request,
70 template=t,
71 **response_kwargs
72 )