コード例 #1
0
ファイル: ajax.py プロジェクト: cdcs-repos/core_exporters_app
def _associated_templates_post(request):
    """ associated templates modal POST

    Args:
        request:

    Returns:

    """
    try:
        form = AssociatedTemplatesForm(request.POST)
        if form.is_valid():
            templates = request.POST.getlist('templates_manager', [])
            exporter_id = request.POST.get('id', None)
            if exporter_id is not None:
                exporter = exporter_api.get_by_id(exporter_id)
                template_id_list = [
                    template_api.get(template_id) for template_id in templates
                ]
                exporter.templates = template_id_list
                exporter_api.upsert(exporter)
                return HttpResponse(json.dumps({}),
                                    content_type='application/javascript')
        else:
            return HttpResponseBadRequest(
                'Bad entries. Please check your entries')
    except Exception, e:
        return HttpResponseBadRequest(e.message,
                                      content_type='application/javascript')
コード例 #2
0
def _associated_templates_post(request):
    """associated templates modal POST

    Args:
        request:

    Returns:

    """
    form = AssociatedTemplatesForm(request.POST, request=request)
    if form.is_valid():
        templates = request.POST.getlist("templates_manager", [])
        exporter_id = request.POST.get("id", None)
        if exporter_id is not None:
            exporter = exporter_api.get_by_id(exporter_id)
            template_id_list = [
                template_api.get(template_id, request=request)
                for template_id in templates
            ]
            exporter.templates = template_id_list
            exporter_api.upsert(exporter)
            return HttpResponse(json.dumps({}),
                                content_type="application/javascript")
    else:
        return HttpResponseBadRequest("Bad entries. Please check your entries")
コード例 #3
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
コード例 #4
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, it is added
                    exporter_added = Exporter(
                        name=pattern["name"],
                        url=pattern["view"],
                        enable_by_default=pattern["enable_by_default"],
                    )
                    # If an exporter was added and is a default one, it is added in all templates
                    if exporter_added.enable_by_default is True:
                        exporter_added.templates = system_api.get_all_templates()
                    exporters_api.upsert(exporter_added)
            except Exception as e:
                logger.error(
                    "Impossible to load the following exporter, class %s not found, exception: %s"
                    % (pattern["view"], str(e))
                )
    except ValidationError as e:
        raise Exception(
            "A validation error occurred during the exporter discovery: %s" % str(e)
        )
    except Exception as e:
        raise e
コード例 #5
0
def post_delete_template(sender, document, **kwargs):
    """ Method executed after a template deletion.
        We are removing in all exporter, the reference to the deleted template
    Args:
        sender:
        document:
        **kwargs:
    """
    exporter_list = exporter_api.get_all()
    for exporter in exporter_list:
        if document in exporter.templates:
            exporter.templates.remove(document)
            exporter_api.upsert(exporter)
コード例 #6
0
def post_save_template(sender, document, **kwargs):
    """ Method executed after saving of a Template object.
    Args:
        sender:
        document: template object.
        **kwargs:
    """
    default_exporter_list = exporter_api.get_all_default_exporter()

    for exporter in default_exporter_list:
        # When an template is added, save is called 2 times
        # so we have to avoid to had the same document several time
        if document not in exporter.templates:
            exporter.templates.append(document)
            exporter_api.upsert(exporter)
コード例 #7
0
 def update(self, instance, validated_data):
     # The only field we can actually update is the name of the instance
     instance.name = validated_data.get("name", instance.name)
     return exporter_api.upsert(instance)
コード例 #8
0
 def create(self, validated_data):
     return exporter_api.upsert(Exporter(**validated_data))
コード例 #9
0
ファイル: ajax.py プロジェクト: cdcs-repos/core_exporters_app
 def _save(self, form):
     # Save treatment.
     try:
         exporter_api.upsert(self.object)
     except Exception, e:
         form.add_error(None, e.message)
コード例 #10
0
 def _save(self, form):
     # Save treatment.
     try:
         exporter_api.upsert(self.object)
     except Exception as e:
         form.add_error(None, str(e))