Esempio n. 1
0
 def test_navigation_entry_respects_permissions(self):
     user = user_with_perms(["testapp.view_dragonfly"])
     self.assertEqual(
         navigation_component_entry(DragonflyViewSet().links["list"],
                                    user=user),
         ("dragonflys", "/dragonfly/"),
     )
     self.assertEqual(
         navigation_component_entry(SightingViewSet().links["list"],
                                    user=user), None)
Esempio n. 2
0
 def test_navigation_entry_handles_other_components(self):
     user = user_with_perms(["testapp.view_sighting"])
     self.assertEqual(
         navigation_component_entry(SightingViewSet().links["other_list"],
                                    user=user),
         ("Another list is possible", "/sighting/other/"),
     )
Esempio n. 3
0
 def test_navigation_entry_uses_model_name_as_list_label(self):
     user = user_with_perms(["testapp.view_dragonfly"])
     self.assertEqual(
         navigation_component_entry(DragonflyViewSet().links["list"],
                                    user=user),
         ("dragonflys", "/dragonfly/"),
     )
Esempio n. 4
0
def render_navigation(context):
    request = context.get("request", None)
    user = request.user if request else None

    grouped = []
    for app_label, viewsets_dict in default_registry.items():
        entries = []
        for viewset in viewsets_dict.values():
            entry = navigation_component_entry(viewset().links.get("list"),
                                               user=user,
                                               request=request)
            if entry:
                entries.append(entry)

        if not entries:
            continue

        group = {
            "app_label": app_label,
            "app_config": apps.get_app_config(app_label),
            "entries": entries,
        }
        grouped.append(group)
    navigation_template = get_template("beam/partials/navigation.html")
    request = context.get("request", None)
    return navigation_template.render({"apps": grouped, "request": request})
Esempio n. 5
0
 def test_navigation_entry_handles_empty(self):
     self.assertEqual(navigation_component_entry(None), None)