當前位置: 首頁>>代碼示例>>Python>>正文


Python models.DeviceModelGroup類代碼示例

本文整理匯總了Python中ralph.discovery.models.DeviceModelGroup的典型用法代碼示例。如果您正苦於以下問題:Python DeviceModelGroup類的具體用法?Python DeviceModelGroup怎麽用?Python DeviceModelGroup使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了DeviceModelGroup類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: post

 def post(self, *args, **kwargs):
     if not self.request.user.get_profile().has_perm(
             Perm.edit_device_info_financial):
         raise HttpResponseForbidden(
                 "You have no permission to edit catalog")
     if 'move' in self.request.POST:
         items = self.request.POST.getlist('items')
         if not items:
             messages.error(self.request, "Nothing to move.")
             return HttpResponseRedirect(self.request.path)
         target_id = self.request.POST.get('target', '')
         if target_id == 'none':
             target = None
         elif target_id == 'new':
             item = get_object_or_404(DeviceModel, id=items[0])
             target = DeviceModelGroup(name=item.name, type=item.type)
             target.save()
         else:
             target = get_object_or_404(DeviceModelGroup, id=target_id)
         for item in items:
             model = get_object_or_404(DeviceModel, id=item)
             model.group = target
             model.save()
         self.update_cached(target)
         messages.success(self.request, "Items moved.")
         return HttpResponseRedirect(self.request.path)
     elif 'delete' in self.request.POST:
         try:
             self.group_id = int(self.kwargs.get('group', ''))
         except ValueError:
             messages.error(self.request, "No such group.")
         else:
             self.group = get_object_or_404(DeviceModelGroup,
                                            id=self.group_id)
             self.group.price = 0
             self.group.save()
             self.update_cached(self.group)
             self.group.delete()
             messages.warning(self.request,
                              "Group '%s' deleted." % self.group.name)
         return HttpResponseRedirect(self.request.path+'..')
     else:
         try:
             self.group_id = int(self.kwargs.get('group', ''))
         except ValueError:
             self.group_id = None
             self.group = None
         else:
             self.group = get_object_or_404(DeviceModelGroup,
                                            id=self.group_id)
         self.form = DeviceModelGroupForm(self.request.POST,
                                          instance=self.group)
         if self.form.is_valid():
             self.form.save()
             self.update_cached(self.group)
             messages.success(self.request, "Changes saved.")
             return HttpResponseRedirect(self.request.path)
         else:
             messages.error(self.request, "Correct the errors.")
     return self.get(*args, **kwargs)
開發者ID:tosuch,項目名稱:ralph,代碼行數:60,代碼來源:catalog.py

示例2: test_blade_server

    def test_blade_server(self):
        encl = Device.create(sn='devicex', model_type=DeviceType.blade_system,
                             model_name='device encl')
        dev = Device.create(sn='device', model_type=DeviceType.blade_server,
                            model_name='device', parent=encl)

        encl_dmg = DeviceModelGroup(name='DeviceModelGroup encl')
        encl_dmg.slots = 4
        encl_dmg.price = 65535
        encl_dmg.save()
        encl.model.group = encl_dmg
        encl.model.save()

        dmg = DeviceModelGroup(name='DeviceModelGroup')
        dmg.price = 1337
        dmg.slots = 1
        dmg.save()
        dev.model.group = dmg
        dev.model.save()

        pricing.device_update_cached(encl)
        pricing.device_update_cached(dev)
        dev = Device.objects.get(id=dev.id)
        encl = Device.objects.get(id=encl.id)

        self.assertEquals(dev.cached_price, 17720.75)
        self.assertEquals(encl.cached_price, 49151.25)
        self.assertEquals(dev.cached_price + encl.cached_price, 65535 + 1337)
開發者ID:damjanek,項目名稱:ralph,代碼行數:28,代碼來源:tests.py

示例3: test_rack_server

 def test_rack_server(self):
     dev = Device.create(sn='device', model_type=DeviceType.rack_server,
                         model_name='device')
     dmg = DeviceModelGroup(name='DeviceModelGroup')
     dmg.price = 1337
     dmg.save()
     dev.model.group = dmg
     dev.model.save()
     pricing.device_update_cached(dev)
     dev = Device.objects.get(id=dev.id)
     self.assertEquals(dev.cached_price, 1337)
開發者ID:damjanek,項目名稱:ralph,代碼行數:11,代碼來源:tests.py

示例4: test_rack_server

    def test_rack_server(self):
        dev = Device.create(sn="device", model_type=DeviceType.rack_server, model_name="device")
        dmg = DeviceModelGroup(name="DeviceModelGroup")
        dmg.price = 1337
        dmg.save()
        dev.model.group = dmg
        dev.model.save()

        pricing.device_update_cached(dev)

        self.assertEquals(dev.cached_price, 1337)
開發者ID:viciu,項目名稱:ralph,代碼行數:11,代碼來源:tests.py

示例5: test_manual_price

    def test_manual_price(self):
        dev = Device.create(sn='device', model_type=DeviceType.rack_server,
                            model_name='device')
        dmg = DeviceModelGroup(name='DeviceModelGroup')
        dmg.price = 1337
        dmg.save()
        dev.model.group = dmg
        dev.model.save()

        dev.price = 238
        dev.save()
        pricing.device_update_cached(dev)

        self.assertEquals(dev.cached_price, 238)
開發者ID:Makdaam,項目名稱:ralph,代碼行數:14,代碼來源:tests.py

示例6: test_cost

    def test_cost(self):
        dev = Device.create(sn="device", model_type=DeviceType.rack_server, model_name="device")
        dmg = DeviceModelGroup(name="DeviceModelGroup")
        dmg.price = 100
        dmg.save()
        dev.model.group = dmg
        dev.model.save()

        dev.margin_kind = MarginKind(name="50%", margin=50)
        dev.margin_kind.save()
        dev.deprecation_kind = DeprecationKind(name="10 months", months=10)
        dev.deprecation_kind.save()
        dev.save()
        pricing.device_update_cached(dev)
        self.assertEqual(dev.cached_cost, 15)
開發者ID:szaydel,項目名稱:ralph,代碼行數:15,代碼來源:tests.py

示例7: test_price_deprecation

 def test_price_deprecation(self):
     # Device after deprecation period should have raw price = 0
     dev = Device.create(sn="device", model_type=DeviceType.rack_server, model_name="device")
     dmg = DeviceModelGroup(name="DeviceModelGroup")
     dmg.price = 100
     dmg.save()
     dev.model.group = dmg
     dev.purchase_date = datetime.today() - timedelta(11 * (365 / 12))
     dev.model.save()
     dev.margin_kind = MarginKind(name="50%", margin=50)
     dev.margin_kind.save()
     dev.deprecation_kind = DeprecationKind(name="10 months", months=10)
     dev.deprecation_kind.save()
     dev.save()
     pricing.device_update_cached(dev)
     self.assertEqual(get_device_raw_price(dev), 0)
     self.assertEqual(dev.cached_price, 0)
     self.assertEqual(dev.cached_cost, 0)
開發者ID:szaydel,項目名稱:ralph,代碼行數:18,代碼來源:tests.py

示例8: test_price_deprecation_in_progress

 def test_price_deprecation_in_progress(self):
     # Device in deprecation period should have raw price >0 if price is set
     dev = Device.create(sn='device', model_type=DeviceType.rack_server,
                         model_name='device')
     dmg = DeviceModelGroup(name='DeviceModelGroup')
     dmg.price = 100
     dmg.save()
     dev.model.group = dmg
     # currently first month in deprecation period
     dev.purchase_date = datetime.today() - timedelta(1 * (365 / 12))
     dev.model.save()
     dev.margin_kind = MarginKind(name='50%', margin=50)
     dev.margin_kind.save()
     dev.deprecation_kind = DeprecationKind(name='10 months', months=10)
     dev.deprecation_kind.save()
     dev.save()
     pricing.device_update_cached(dev)
     self.assertEqual(get_device_raw_price(dev), 100)
     self.assertEqual(dev.cached_cost, 15)
     self.assertEqual(dev.cached_price, 100)
開發者ID:Makdaam,項目名稱:ralph,代碼行數:20,代碼來源:tests.py

示例9: test_cost

    def test_cost(self):
        dev = Device.create(sn='device', model_type=DeviceType.rack_server,
                            model_name='device')
        dmg = DeviceModelGroup(name='DeviceModelGroup')
        dmg.price = 100
        dmg.save()
        dev.model.group = dmg
        dev.model.save()

        mk = MarginKind(name='50%', margin=50)
        mk.save()
        dev.margin_kind = mk
        dk = DeprecationKind(name='10 months', months=10)
        dk.save()
        dev.deprecation_kind = dk
        dev.save()
        self.assertEqual(pricing.get_device_cost(dev), 15)
        pricing.device_update_cached(dev)
        dev = Device.objects.get(id=dev.id)
        self.assertEqual(pricing.get_device_cost(dev), 15)
        self.assertEqual(dev.cached_cost, 15)
開發者ID:damjanek,項目名稱:ralph,代碼行數:21,代碼來源:tests.py

示例10: test_price_deprecation

 def test_price_deprecation(self):
     # Device after deprecation period should have raw price = 0
     dev = Device.create(sn='device', model_type=DeviceType.rack_server,
                         model_name='device')
     dmg = DeviceModelGroup(name='DeviceModelGroup')
     dmg.price = 100
     dmg.save()
     dev.model.group = dmg
     dev.purchase_date = datetime.today() - timedelta(11 * (365 / 12))
     dev.model.save()
     mk = MarginKind(name='50%', margin=50)
     mk.save()
     dev.margin_kind = mk
     dk = DeprecationKind(name='10 months', months=10)
     dk.save()
     dev.deprecation_kind = dk
     dev.save()
     pricing.device_update_cached(dev)
     dev = Device.objects.get(id=dev.id)
     self.assertEqual(get_device_raw_price(dev), 0)
     self.assertEqual(dev.cached_price, 0)
     self.assertEqual(dev.cached_cost, 0)
開發者ID:damjanek,項目名稱:ralph,代碼行數:22,代碼來源:tests.py


注:本文中的ralph.discovery.models.DeviceModelGroup類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。