当前位置: 首页>>代码示例>>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;未经允许,请勿转载。