예제 #1
0
파일: common.py 프로젝트: damjanek/ralph
 def get_context_data(self, **kwargs):
     ret = super(Prices, self).get_context_data(**kwargs)
     ret.update({
         'components': _get_details(self.object,
                                    purchase_only=False,
                                    with_price=True),
         'deprecated': is_deprecated(self.object),
     })
     return ret
예제 #2
0
파일: common.py 프로젝트: damjanek/ralph
 def get_context_data(self, **kwargs):
     query_variable_name = 'cost_page'
     ret = super(Costs, self).get_context_data(**kwargs)
     history = self.object.historycost_set.order_by('-end', '-start').all()
     has_perm = self.request.user.get_profile().has_perm
     for h in history:
         if not has_perm(Perm.list_devices_financial, h.venture):
             h.daily_cost = None
         if h.end < FOREVER_DATE and h.start:
             h.span = (h.end - h.start).days
         elif h.start:
             h.span = (datetime.date.today() - h.start).days
     try:
         page = max(1, int(self.request.GET.get(query_variable_name, 1)))
     except ValueError:
         page = 1
     history_page = Paginator(history, HISTORY_PAGE_SIZE).page(page)
     ret.update({
         'history': history,
         'history_page': history_page,
         'query_variable_name': query_variable_name,
         'ALWAYS_DATE': ALWAYS_DATE,
         'FOREVER_DATE': FOREVER_DATE,
         'deprecated': is_deprecated(self.object),
     })
     last_month = datetime.date.today() - datetime.timedelta(days=31)
     splunk = self.object.splunkusage_set.filter(
             day__gte=last_month
         ).order_by('-day')
     if splunk.count():
         size = splunk.aggregate(db.Sum('size'))['size__sum'] or 0
         cost = (
             splunk[0].get_price(size=size) /
             splunk[0].model.group.size_modifier
         )
         ret.update({
             'splunk_size': size,
             'splunk_monthly_cost': cost,
             'splunk_daily_cost': cost / splunk.count(),
         })
     return ret
예제 #3
0
파일: reports.py 프로젝트: damjanek/ralph
 def get_device_with_components(self, venture_devices, blacklist):
     devices = []
     for device in venture_devices:
         all_components_price = 0
         components = []
         for component in _get_details(device, ignore_deprecation=True):
             count = 1
             model = component.get("model")
             if not isinstance(model, basestring):
                 component_type = model.type
                 component_group = model.group_id
                 model_group = model.group
             else:
                 component_group = None
                 component_type = None
                 model_group = None
             act_components = [x.get("name") for x in components]
             if model not in act_components and component_type not in blacklist:
                 if is_bladesystem(component):
                     bs_count = device.child_set.filter(deleted=False).count() or 1
                     chassis_price = get_device_chassis_price(device)
                     auto_price = get_device_auto_price(device)
                     bs_price = 0
                     if device.price != 0:
                         bs_price = device.price / bs_count
                     elif chassis_price != 0:
                         bs_price = chassis_price
                     elif auto_price != 0:
                         bs_price = auto_price / bs_count
                     components.append(
                         {
                             "icon": component.get("icon"),
                             "name": model,
                             "price": bs_price,
                             "count": count,
                             "bs_count": bs_count,
                         }
                     )
                 elif component_type == ComponentType.share:
                     components.append(
                         {
                             "icon": component.get("icon"),
                             "name": model,
                             "price": component.get("price") or 0,
                             "count": component.get("count") or 1,
                         }
                     )
                 else:
                     d_price = 0
                     if device.price and device.price != 0:
                         d_price = device.price
                     else:
                         d_price = component.get("price") or 0
                     components.append(
                         {
                             "icon": component.get("icon"),
                             "name": model,
                             "price": d_price,
                             "model_group": model_group,
                             "count": count,
                         }
                     )
             else:
                 for component in components:
                     if component.get("name") == model:
                         count = component.get("count")
                         component.update(count=count + 1)
         for component in components:
             count = component.get("count")
             price = component.get("price")
             total_component = price * count
             component["total_component"] = total_component
             all_components_price += total_component
         devices.append(
             {
                 "device": device,
                 "deprecated": is_deprecated(device),
                 "price": all_components_price,
                 "components": components,
             }
         )
     return devices