Exemple #1
0
    def get_context_data(self, request):
        host = client_proxy.get_host(self.request, self.tab_group.kwargs['host_id'])
        if not host:
            raise exceptions.Http302(reverse('horizon:giraffe_dashboard'
                                             ':hosts:index'))

        host_meters = client_proxy.get_host_meters( \
                                   self.request, \
                                   self.tab_group.kwargs['host_id'])

        return {'host': host, 'meters': host_meters}
Exemple #2
0
    def get_context_data(self, request):
        submitted = self.request.GET.get('meter', None) is not None

        host = client_proxy.get_host(self.request, self.tab_group.kwargs['host_id'])
        if not host:
            raise exceptions.Http302(reverse('horizon:giraffe_dashboard'
                                             ':hosts:index'))

        # @[fbahr] - TODO: make /hosts/hid/meters return only host meters?!
        meters = [meter \
                  for meter in client_proxy.get_host_meters( \
                                       self.request, \
                                       self.tab_group.kwargs['host_id']) \
                  if meter.name.startswith('host')]

        today = time.today()
        month = self.request.GET.get('month', today.month)
        day = self.request.GET.get('day', 0)
        year = self.request.GET.get('year', today.year)

        meter_id = self.request.GET.get('meter', meters[0].id if meters else None)
        meter = next(m for m in meters if int(m.id) == int(meter_id)) \
                    if meter_id \
                    else None

        form = forms.DateMeterForm(initial={'month': month,
                                            'year': year,
                                            'day': 0,
                                            'meter': meter_id},
                                   meters=meters)

        context = {'submitted': submitted}
        if submitted and meter_id:
            avgs = client_proxy.get_host_meter_records_avg(request=self.request,
                                                           host_id=host.id,
                                                           meter_id=meter_id,
                                                           year=year,
                                                           month=month,
                                                           day=int(day))

            ticks = 25 \
                    if   day \
                    else (calendar.monthrange(*map(int, (year, month)))[1] + 1)

            context['graph'] = {'y_data': avgs, 'x_data': range(1, ticks)}

        context['form'] = form
        context['meters'] = meters
        context['host'] = host
        context['meter'] = meter

        return context