def test_get_all_as_superuser_returns_all_templates(self):
     mock_request = create_mock_request(user=self.superuser)
     templates = template_api.get_all(request=mock_request)
     self.assertEquals(templates.count(), 3)
     self.assertTrue(self.fixture.user1_template in list(templates))
     self.assertTrue(self.fixture.user2_template in list(templates))
     self.assertTrue(self.fixture.global_template in list(templates))
예제 #2
0
def discover_exporter():
    """ Exporters discover

    Returns:

    """
    patterns = __flatten_patterns_tree__(urls.urlpatterns)
    try:
        for pattern in patterns:
            try:
                try:
                    exporters_api.get_by_url(pattern['view'])
                except main_exception.DoesNotExist:
                    # if there is no exporter with the given url
                    # we add it
                    exporter_added = Exporter(
                        name=pattern['name'],
                        url=pattern['view'],
                        enable_by_default=pattern['enable_by_default'])
                    # if we added an exporter and it is a default one, we have to add it in all template
                    if exporter_added.enable_by_default is True:
                        exporter_added.templates = templates_api.get_all()
                    exporters_api.upsert(exporter_added)
            except Exception, e:
                print(
                    'ERROR : Impossible to load the following exporter, class not found : '
                    + pattern['view'])
    except ValidationError as e:
        raise Exception(
            'A validation error occured during the exporter discovery :' +
            e.message)
    except Exception, e:
        raise e
예제 #3
0
def create_template_schema_viewer_from_templates_in_db():
    """ Get all template in DB and create a TemplateSchemaViewer for each
    """
    # get all template in DB
    templates = template_api.get_all()
    for template in templates:
        try:
            # check if the TemplateSchemaViewer does not exist already
            template_schema_viewer_api.get_by_template_id(template.pk)
        except exceptions.DoesNotExist:
            # create the TemplateSchemaViewer associated only if it does not exist already
            template_schema_viewer = TemplateSchemaViewer(template=template)
            template_schema_viewer_api.upsert(template_schema_viewer)
예제 #4
0
def _get_templates_versions(request):
    """Get templates versions.

    Returns:
        List of templates versions.

    """
    templates = []
    # display all template, global and from users
    template_list = template_api.get_all(request=request)
    for template in template_list:
        templates.append((template.id, template.display_name))
    return templates
예제 #5
0
def _get_templates_versions():
    """ Get templates versions.

    Returns:
        List of templates versions.

    """
    templates = []
    try:
        # display all template, global and from users
        template_list = template_api.get_all()
        for template in template_list:
            templates.append((template.id, template.display_name))
    except Exception:
        pass
    return templates
예제 #6
0
class TemplateXsltRenderingForm(forms.Form):
    """
    Form to associate list and detail XSLTs to template
    """
    id = forms.CharField(widget=forms.HiddenInput(), required=False)
    template = forms.ModelChoiceField(widget=forms.HiddenInput(), required=False, queryset=template_api.get_all())
    list_xslt = forms.ModelChoiceField(label='List XSLT', empty_label="(No XSLT)", required=False,
                                       widget=forms.Select(attrs={'class': 'form-control'}),
                                       queryset=xsl_transformation_api.get_all())
    detail_xslt = forms.ModelChoiceField(label='Detail XSLT', empty_label="(No XSLT)", required=False,
                                         widget=forms.Select(attrs={'class': 'form-control'}),
                                         queryset=xsl_transformation_api.get_all())
예제 #7
0
 def test_template_list_contains_only_template(self, mock_get_all):
     _generic_get_all_test(self, mock_get_all, template_api.get_all())
 def test_get_all_as_staff_returns_accessible_templates(self):
     mock_request = create_mock_request(user=self.staff_user)
     templates = template_api.get_all(request=mock_request)
     self.assertEquals(templates.count(), 2)
     self.assertTrue(self.fixture.user2_template in list(templates))
     self.assertTrue(self.fixture.global_template in list(templates))
 def test_get_all_as_anonymous_returns_empty_list(self):
     mock_request = create_mock_request(user=self.anonymous_user)
     templates = template_api.get_all(request=mock_request)
     self.assertEquals(templates.count(), 0)