コード例 #1
0
ファイル: models.py プロジェクト: desirefreer/zentral
 def links(self):
     known_models = {
         EnrollmentSecret:
         ("enrollment secret", "enrollment secrets", None),
         MachineTag: ("machine", "machines",
                      "{}?tag={}".format(reverse("inventory:index"),
                                         self.id)),
         MetaBusinessUnitTag: ("business unit", "business units",
                               "{}?tag={}".format(reverse("inventory:mbu"),
                                                  self.id))
     }
     link_list = []
     for related_objects in find_all_related_objects(self):
         if related_objects.name in ("taxonomy", "meta_business_unit"):
             continue
         if related_objects.objects_count:
             if related_objects.to_model in known_models:
                 label, label_plural, url = known_models[
                     related_objects.to_model]
                 link_list.append(("{} {}".format(
                     related_objects.objects_count,
                     label if related_objects.objects_count == 1 else
                     label_plural), url))
             else:
                 link_list.append(
                     ("{} {}".format(related_objects.objects_count,
                                     related_objects.name), None))
     return link_list
コード例 #2
0
ファイル: models.py プロジェクト: samueljon/zentral
 def can_be_deleted(self):
     for related_objects in find_all_related_objects(self):
         if len(related_objects.objects):
             if related_objects.name == "businessunit":
                 # OK to delete if all the business units can be deleted
                 for bu in related_objects.objects:
                     if not bu.can_be_deleted():
                         return False
                 continue
             else:
                 return False
     return True
コード例 #3
0
 def links(self):
     known_models = {
         Tag: ("tag", "tags", None)  # TODO: filter?
     }
     link_list = []
     for related_objects in find_all_related_objects(self):
         if related_objects.name == "meta_business_unit":
             continue
         if related_objects.objects_count:
             if related_objects.to_model in known_models:
                 label, label_plural, url = known_models[related_objects.to_model]
                 link_list.append(("{} {}".format(related_objects.objects_count,
                                                  label if related_objects.objects_count == 1 else label_plural),
                                   url))
             else:
                 link_list.append(("{} {}".format(related_objects.objects_count,
                                                  related_objects.name),
                                   None))
     return link_list