Esempio n. 1
0
    def get_template_version_managers(self):
        """ Get all user template version managers.

        Returns:

        """
        return template_version_manager_api.get_all_by_user_id(
            user_id=str(self.request.user.id))
Esempio n. 2
0
    def get_template_version_managers(self):
        """Get all UserTemplateVersionManager

        Returns:

            List of UserTemplateVersionManager
        """
        return template_version_manager_api.get_all_by_user_id(
            request=self.request)
    def get(self, request, *args, **kwargs):
        """ Method GET

        Args:
            request:
            args:
            kwargs:

        Returns:
        """
        # Get templates
        if self.administration:
            template_versions = template_version_manager_api.get_all()
        else:
            template_versions = template_version_manager_api.get_all_by_user_id(
                request.user.id)

        detailed_templates = []
        for template_version in template_versions:
            # If the version manager doesn't have a user, the template is global.
            if template_version.user is not None:
                detailed_templates.append({
                    'template_version':
                    template_version,
                    'template':
                    template_api.get(template_version.current),
                    'user':
                    user_api.get_user_by_id(template_version.user).username,
                    'title':
                    template_version.title
                })

        context = {
            'number_total': len(detailed_templates),
            'user_data': detailed_templates,
            'user_form': UserForm(request.user),
            'document': dashboard_constants.FUNCTIONAL_OBJECT_ENUM.TEMPLATE,
            'object_name': dashboard_constants.FUNCTIONAL_OBJECT_ENUM.TEMPLATE,
            'template': dashboard_constants.DASHBOARD_TEMPLATES_TEMPLATE_TABLE,
            'menu': False
        }

        modals = [
            "core_main_app/admin/templates/list/modals/disable.html",
            EditTemplateVersionManagerView.get_modal_html_path()
        ]

        assets = {
            "css":
            dashboard_constants.CSS_COMMON,
            "js": [{
                "path": 'core_main_app/common/js/templates/list/restore.js',
                "is_raw": False
            }, {
                "path":
                'core_main_app/common/js/templates/list/modals/disable.js',
                "is_raw": False
            },
                   EditTemplateVersionManagerView.get_modal_js_path()]
        }

        return self.common_render(request,
                                  self.template,
                                  context=context,
                                  assets=assets,
                                  modals=modals)
 def test_get_all_by_user_id_as_superuser_returns_user_templates(self):
     mock_request = create_mock_request(user=self.superuser1)
     list_tvm = template_vm_api.get_all_by_user_id(request=mock_request)
     for tvm in list_tvm:
         self.assertEqual(tvm.user, str(self.superuser1.id))
 def test_get_all_by_user_id_as_anonymous_returns_nothing(self):
     mock_request = create_mock_request(user=self.anonymous_user)
     list_tvm = template_vm_api.get_all_by_user_id(request=mock_request)
     self.assertEqual(list_tvm.count(), 0)
    def get(self, request, *args, **kwargs):
        """Method GET

        Args:
            request:
            args:
            kwargs:

        Returns:
        """
        try:
            # Get templates
            if self.administration:
                template_versions = template_version_manager_api.get_all(
                    request=request
                )
            else:
                template_versions = template_version_manager_api.get_all_by_user_id(
                    request=request
                )

            detailed_templates = []
            for template_version in template_versions:
                # If the version manager doesn't have a user, the template is global.
                if template_version.user is not None:
                    try:
                        username = user_api.get_user_by_id(
                            template_version.user
                        ).username
                    except ObjectDoesNotExist:
                        username = "******"

                    detailed_templates.append(
                        {
                            "template_version": template_version,
                            "template": template_api.get(
                                template_version.current, request=request
                            ),
                            "user": username,
                            "title": template_version.title,
                        }
                    )

            context = {
                "number_total": len(detailed_templates),
                "user_data": detailed_templates,
                "user_form": UserForm(request.user),
                "document": dashboard_constants.FUNCTIONAL_OBJECT_ENUM.TEMPLATE.value,
                "object_name": dashboard_constants.FUNCTIONAL_OBJECT_ENUM.TEMPLATE.value,
                "template": dashboard_constants.DASHBOARD_TEMPLATES_TEMPLATE_TABLE,
                "menu": False,
            }
            modals = [
                "core_main_app/admin/templates/list/modals/disable.html",
                EditTemplateVersionManagerView.get_modal_html_path(),
            ]

            assets = {
                "css": dashboard_constants.CSS_COMMON,
                "js": [
                    {
                        "path": "core_main_app/common/js/templates/list/restore.js",
                        "is_raw": False,
                    },
                    {
                        "path": "core_main_app/common/js/templates/list/modals/disable.js",
                        "is_raw": False,
                    },
                    EditTemplateVersionManagerView.get_modal_js_path(),
                ],
            }

            return self.common_render(
                request, self.template, context=context, assets=assets, modals=modals
            )
        except AccessControlError:
            return self.common_render(
                request,
                "core_main_app/common/commons/error.html",
                context={"error": "Access Forbidden", "status_code": 403},
            )