Example #1
0
 def test_requiring_existing_assets_does_not_raise(self):
     with use_assets('a.css', 'b.css', 'c.js'):
         try:
             require_assets('a.css', 'c.js')
         except AssetMissing:
             raise
             self.fail('AssetMissing raised unexpectedly')
    def get_context_data(self, tab_instance, request, **kwargs):
        question_types = self._get_category_options(**kwargs)
        # Build the table
        table = ItemTable(
            self._get_items(**kwargs),
            categories=question_types,
            exclude=self._get_columns_to_exclude(**kwargs),
            orderable=True,
            order_by=request.GET.get("sort", None),
        )
        table.paginate(per_page=kwargs.get("per_page", 25), page=request.GET.get("page", 1))

        upload_form = self._build_upload_form(tab_instance, kwargs.get("source", None))
        actions = self._build_actions_dropdown(question_types)

        # Ensure we have the assets we want
        require_assets("hid/js/automatic_file_upload.js")
        require_assets("hid/js/select_all_checkbox.js")

        # And return the context
        return {
            "add_button_for": self._get_item_type_filter(kwargs),
            "type_label": kwargs.get("label", "?"),
            "table": table,
            "upload_form": upload_form,
            "actions": actions,
            "has_categories": len(question_types) > 0,
            "next": reverse("tabbed-page", kwargs={"name": tab_instance.page.name, "tab_name": tab_instance.name}),
        }
Example #3
0
    def get_context_data(self, **kwargs):
        """ Get the list of widgets for this dashboard, and organise them
            in row/columns to be displayed by the template.
        """
        context = super(DashboardView, self).get_context_data(**kwargs) or {}

        # Get dashboard
        if 'name' in self.kwargs and self.kwargs['name']:
            name = self.kwargs['name']
        else:
            name = 'main'
        dashboard = Dashboard.objects.get(name=name)
        context['name'] = dashboard.name

        # Get widgets and sort them by row
        widgets = dashboard.widgetinstance_set.all().order_by('row', 'column')
        context['rows'] = []
        current_row = []
        current_row_number = None
        for widget in widgets:
            if current_row_number is None:
                current_row_number = widget.row
            elif current_row_number != widget.row:
                context['rows'].append(current_row)
                current_row_number = widget.row
                current_row = []
            current_row.append(widget)
        if len(current_row) > 0:
            context['rows'].append(current_row)

        # Ensure we have all the javascript & css dependencies
        require_assets('dashboard/dashboard.css')
        for widget in widgets:
            try:
                widget_type = get_widget(widget.widget_type)
            except MissingWidgetType:
                continue
            if hasattr(widget_type, 'javascript'):
                require_assets(*widget_type.javascript)
            if hasattr(widget_type, 'css'):
                require_assets(*widget_type.css)

        # Return the context
        return context
Example #4
0
 def test_requiring_missing_assets_does_raise(self):
     with use_assets('a.css', 'b.css', 'c.js'):
         with self.assertRaises(AssetMissing):
             require_assets('a.css', 'missing.js')