def get_template_version_managers(self): """ Get all user type version managers Returns: TypeVersionManager """ return type_version_manager_api.get_version_managers_by_user(user_id=self.request.user.id)
def test_get_version_managers_by_user_returns_types_with_given_user_id(self, mock_get_version_managers_by_user): # Arrange user_id = '10' mock_type1 = _create_mock_type_version_manager(user=user_id) mock_type2 = _create_mock_type_version_manager(user=user_id) mock_get_version_managers_by_user.return_value = [mock_type1, mock_type2] result = version_manager_api.get_version_managers_by_user(user_id) # Assert self.assertTrue(item.user_id == user_id for item in result)
def test_get_version_managers_by_user_returns_types_with_given_user_id( self, mock_get_version_managers_by_user): # Arrange user_id = "10" mock_user = create_mock_user(user_id=user_id, is_superuser=True) mock_request = create_mock_request(user=mock_user) mock_type1 = _create_mock_type_version_manager(user=user_id) mock_type2 = _create_mock_type_version_manager(user=user_id) mock_get_version_managers_by_user.return_value = [ mock_type1, mock_type2 ] result = version_manager_api.get_version_managers_by_user( request=mock_request) # Assert self.assertTrue(item.user_id == user_id for item in result)
def build_template(request, template_id): """View that allows to build the Template. Args: request: template_id: Returns: """ if template_id == "new": base_template_path = finders.find(join('core_composer_app', 'user', 'xsd', 'new_base_template.xsd')) xsd_string = read_file_content(base_template_path) else: template = template_api.get(template_id) xsd_string = template.content request.session['newXmlTemplateCompose'] = xsd_string request.session['includedTypesCompose'] = [] # store the current includes/imports xsd_tree = XSDTree.build_tree(xsd_string) includes = xsd_tree.findall("{}include".format(LXML_SCHEMA_NAMESPACE)) for el_include in includes: if 'schemaLocation' in el_include.attrib: request.session['includedTypesCompose'].append(el_include.attrib['schemaLocation']) imports = xsd_tree.findall("{}import".format(LXML_SCHEMA_NAMESPACE)) for el_import in imports: if 'schemaLocation' in el_import.attrib: request.session['includedTypesCompose'].append(el_import.attrib['schemaLocation']) # remove annotations from the tree remove_annotations(xsd_tree) xsd_string = XSDTree.tostring(xsd_tree) # loads XSLT xslt_path = finders.find(join('core_composer_app', 'user', 'xsl', 'xsd2html.xsl')) # reads XSLT xslt_string = read_file_content(xslt_path) # transform XML to HTML xsd_to_html_string = xsl_transform(xsd_string, xslt_string) # 1) Get user defined types user_types = type_version_manager_api.get_version_managers_by_user(str(request.user.id)) # 2) Get buckets buckets = bucket_api.get_all() # 3) no_buckets_types: list of types that are not assigned to a specific bucket no_buckets_types = type_version_manager_api.get_no_buckets_types() # 4) Build list of built-in types built_in_types = [] for built_in_type in get_xsd_types(): built_in_types.append({'current': 'built_in_type', 'title': built_in_type}) assets = { "js": [ { "path": 'core_composer_app/user/js/build_template.js', "is_raw": False }, { "path": 'core_composer_app/user/js/build_template.raw.js', "is_raw": True }, { "path": 'core_composer_app/user/js/xpath.js', "is_raw": False }, { "path": 'core_composer_app/user/js/menus.js', "is_raw": False }, { "path": 'core_composer_app/user/js/xsd_tree.js', "is_raw": False }, ], "css": ['core_main_app/common/css/XMLTree.css', 'core_composer_app/common/css/bucket.css', 'core_composer_app/user/css/menu.css', 'core_composer_app/user/css/style.css', 'core_composer_app/user/css/xsd_tree.css'] } context = { 'buckets': buckets, 'built_in_types': built_in_types, 'no_buckets_types': no_buckets_types, 'user_types': user_types, 'xsd_form': xsd_to_html_string, 'template_id': template_id, } modals = [ 'core_composer_app/user/builder/menus/sequence.html', 'core_composer_app/user/builder/menus/element.html', 'core_composer_app/user/builder/menus/element_root.html', 'core_composer_app/user/builder/modals/root_type_name.html', 'core_composer_app/user/builder/modals/element_name.html', 'core_composer_app/user/builder/modals/insert_element.html', 'core_composer_app/user/builder/modals/delete_element.html', 'core_composer_app/user/builder/modals/change_type.html', 'core_composer_app/user/builder/modals/save_template.html', 'core_composer_app/user/builder/modals/save_type.html', 'core_composer_app/user/builder/modals/save_success.html', 'core_composer_app/user/builder/modals/occurrences.html', 'core_composer_app/user/builder/modals/errors.html', ] return render(request, 'core_composer_app/user/build_template.html', assets=assets, context=context, modals=modals)
def get(self, request, *args, **kwargs): """ Method GET Args: request: args: kwargs: Returns: """ # Get types if self.administration: type_versions = type_version_manager_api.get_all_version_manager() else: type_versions = type_version_manager_api.get_version_managers_by_user( request.user.id) detailed_types = [] for type_version in type_versions: # If the version manager doesn't have a user, the type is global. if type_version.user is not None: detailed_types.append({ 'type_version': type_version, 'type': type_api.get(type_version.current), 'user': user_api.get_user_by_id(type_version.user).username, 'title': type_version.title }) context = { 'number_total': len(type_versions), 'user_form': UserForm(request.user), 'document': dashboard_constants.FUNCTIONAL_OBJECT_ENUM.TYPE, 'object_name': dashboard_constants.FUNCTIONAL_OBJECT_ENUM.TYPE, 'template': dashboard_constants.DASHBOARD_TYPES_TEMPLATE_TABLE, 'menu': False, 'user_data': detailed_types } 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 get(self, request, *args, **kwargs): """Method GET Args: request: args: kwargs: Returns: """ try: # Get types if self.administration: type_versions = type_version_manager_api.get_all_version_manager( request=request ) else: type_versions = type_version_manager_api.get_version_managers_by_user( request=request ) detailed_types = [] for type_version in type_versions: # If the version manager doesn't have a user, the type is global. if type_version.user is not None: try: username = user_api.get_user_by_id(type_version.user).username except ObjectDoesNotExist: username = "******" detailed_types.append( { "type_version": type_version, "type": type_api.get(type_version.current, request=request), "user": username, "title": type_version.title, } ) context = { "number_total": len(detailed_types), "user_form": UserForm(request.user), "document": dashboard_constants.FUNCTIONAL_OBJECT_ENUM.TYPE.value, "object_name": dashboard_constants.FUNCTIONAL_OBJECT_ENUM.TYPE.value, "template": dashboard_constants.DASHBOARD_TYPES_TEMPLATE_TABLE, "menu": False, "user_data": detailed_types, } 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}, )